diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-03-30 14:20:41 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-03-30 14:20:41 -0700 |
commit | 4c6ef3b156c67e8867e04668cb2af902d44e4086 (patch) | |
tree | 70f344855985980dd66776bcc5506738d2914441 /drivers/staging | |
parent | 59838093be51ee9447f6ad05483d697b6fa0368d (diff) | |
parent | e681bb287f40e7a9dbcb04cef80fd87a2511ab86 (diff) |
Merge tag 'staging-5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging and IIO driver updates from Greg KH:
"Here is the big staging and IIO driver pull request for 5.7-rc1.
We again end up deleting more code than we added here, thanks to
finally getting rid of the old and obsolete wireless USB stuff, and
the exfat code (which is coming in again through the vfs tree in a
much cleaner version).
But some code does come back, with the octeon drivers being found to
actually be used in the wild, so those deletions are now reverted.
Other than those major things, just loads and loads of tiny checkpatch
cleanups all over the place, along with new IIO drivers and fixes.
All have been in linux-next with no reported issues"
[ Stephen Rothwell points out some reported issues due to merge conflicts ]
* tag 'staging-5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (415 commits)
staging: vt6656: Use DIV_ROUND_UP macro instead of specific code
staging: remove hp100 driver
staging: wilc1000: Use crc7 in lib/ rather than a private copy
Staging: rtl8192u: ieee80211: Use netdev_alert().
Staging: rtl8192u: ieee80211: Use netdev_info() with network devices.
Staging: rtl8192u: ieee80211: Use netdev_warn() for network devices.
Staging: rtl8192u: ieee80211: Use netdev_dbg() for debug messages.
staging: wlan-ng: fix use-after-free Read in hfa384x_usbin_callback
staging: rtl8723bs: hal: Remove NULL check before kfree
staging: rtl8723bs: hal: Correct typos in comments
staging: rtl8723bs: os_dep: Correct typos in comments
staging: rtl8723bs: core: Correct typos in comments
staging: rtl8723bs: hal: Remove unnecessary cast on void pointer
staging: rtl8188eu: cleanup long line in odm.c
staging: rtl8723bs: hal: Compress return logic
staging: rtl8723bs: rtw_cmd: Compress lines for immediate return
staging: rtl8723bs: rtw_efuse: Compress lines for immediate return
staging: wilc1000: remove label from examples in DT binding documentation
staging: rtl8723bs: Remove blank line before '}' brace
Staging: rtl8188eu: hal: Add space around operators
...
Diffstat (limited to 'drivers/staging')
394 files changed, 14065 insertions, 50668 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index baccd7c883cc..a9939ff9490e 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -42,6 +42,10 @@ source "drivers/staging/rtl8188eu/Kconfig" source "drivers/staging/rts5208/Kconfig" +source "drivers/staging/octeon/Kconfig" + +source "drivers/staging/octeon-usb/Kconfig" + source "drivers/staging/vt6655/Kconfig" source "drivers/staging/vt6656/Kconfig" @@ -112,15 +116,8 @@ source "drivers/staging/fieldbus/Kconfig" source "drivers/staging/kpc2000/Kconfig" -source "drivers/staging/wusbcore/Kconfig" -source "drivers/staging/uwb/Kconfig" - -source "drivers/staging/exfat/Kconfig" - source "drivers/staging/qlge/Kconfig" -source "drivers/staging/hp/Kconfig" - source "drivers/staging/wfx/Kconfig" endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index fdd03fd6e704..4d34198151b3 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -12,6 +12,8 @@ obj-$(CONFIG_R8712U) += rtl8712/ obj-$(CONFIG_R8188EU) += rtl8188eu/ obj-$(CONFIG_RTS5208) += rts5208/ obj-$(CONFIG_NETLOGIC_XLR_NET) += netlogic/ +obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ +obj-$(CONFIG_OCTEON_USB) += octeon-usb/ obj-$(CONFIG_VT6655) += vt6655/ obj-$(CONFIG_VT6656) += vt6656/ obj-$(CONFIG_VME_BUS) += vme/ @@ -46,9 +48,5 @@ obj-$(CONFIG_STAGING_GASKET_FRAMEWORK) += gasket/ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/ obj-$(CONFIG_KPC2000) += kpc2000/ -obj-$(CONFIG_UWB) += uwb/ -obj-$(CONFIG_USB_WUSB) += wusbcore/ -obj-$(CONFIG_STAGING_EXFAT_FS) += exfat/ obj-$(CONFIG_QLGE) += qlge/ -obj-$(CONFIG_NET_VENDOR_HP) += hp/ obj-$(CONFIG_WFX) += wfx/ diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c index e15e33ed94ae..89dc84d3c803 100644 --- a/drivers/staging/comedi/drivers/dt282x.c +++ b/drivers/staging/comedi/drivers/dt282x.c @@ -484,14 +484,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device *dev, s->async->events |= COMEDI_CB_EOA; return; } -#if 0 - /* clear the dual dma flag, making this the last dma segment */ - /* XXX probably wrong */ - if (!devpriv->ntrig) { - devpriv->supcsr &= ~DT2821_SUPCSR_DDMA; - outw(devpriv->supcsr, dev->iobase + DT2821_SUPCSR_REG); - } -#endif + /* restart the channel */ dt282x_prep_ai_dma(dev, dma->cur_dma, 0); @@ -534,28 +527,7 @@ static irqreturn_t dt282x_interrupt(int irq, void *d) s_ao->async->events |= COMEDI_CB_ERROR; handled = 1; } -#if 0 - if (adcsr & DT2821_ADCSR_ADDONE) { - unsigned short data; - - data = inw(dev->iobase + DT2821_ADDAT_REG); - data &= s->maxdata; - if (devpriv->ad_2scomp) - data = comedi_offset_munge(s, data); - comedi_buf_write_samples(s, &data, 1); - - devpriv->nread--; - if (!devpriv->nread) { - s->async->events |= COMEDI_CB_EOA; - } else { - if (supcsr & DT2821_SUPCSR_SCDN) - outw(devpriv->supcsr | DT2821_SUPCSR_STRIG, - dev->iobase + DT2821_SUPCSR_REG); - } - handled = 1; - } -#endif comedi_handle_events(dev, s); if (s_ao) comedi_handle_events(dev, s_ao); diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c index f7c365b70106..011e19161b78 100644 --- a/drivers/staging/comedi/drivers/dt3000.c +++ b/drivers/staging/comedi/drivers/dt3000.c @@ -439,9 +439,8 @@ static int dt3k_ai_cmdtest(struct comedi_device *dev, if (cmd->scan_begin_src == TRIG_TIMER) { arg = cmd->convert_arg * cmd->scan_end_arg; - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - arg); + err |= comedi_check_trigger_arg_min( + &cmd->scan_begin_arg, arg); } } diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c index 4ee9b260eab0..75d5c9c24596 100644 --- a/drivers/staging/comedi/drivers/ni_660x.c +++ b/drivers/staging/comedi/drivers/ni_660x.c @@ -1035,7 +1035,7 @@ static int ni_660x_auto_attach(struct comedi_device *dev, ni_660x_init_tio_chips(dev, board->n_chips); /* prepare the device for globally-named routes. */ - if (ni_assign_device_routes("ni_660x", board->name, + if (ni_assign_device_routes("ni_660x", board->name, NULL, &devpriv->routing_tables) < 0) { dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n", __func__, board->name); diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c index 68ad9676f962..0bca7d752015 100644 --- a/drivers/staging/comedi/drivers/ni_atmio16d.c +++ b/drivers/staging/comedi/drivers/ni_atmio16d.c @@ -266,19 +266,9 @@ static int atmio16d_ai_cmdtest(struct comedi_device *dev, if (cmd->scan_begin_src == TRIG_FOLLOW) { /* internal trigger */ err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); - } else { -#if 0 - /* external trigger */ - /* should be level/edge, hi/lo specification here */ - err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0); -#endif } err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 10000); -#if 0 - err |= comedi_check_trigger_arg_max(&cmd->convert_arg, SLOWEST_TIMER); -#endif - err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c b/drivers/staging/comedi/drivers/ni_labpc_common.c index 406952f5521d..ce0f85026277 100644 --- a/drivers/staging/comedi/drivers/ni_labpc_common.c +++ b/drivers/staging/comedi/drivers/ni_labpc_common.c @@ -560,14 +560,13 @@ static int labpc_ai_cmdtest(struct comedi_device *dev, /* make sure scan timing is not too fast */ if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->convert_src == TRIG_TIMER) { - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - cmd->convert_arg * - cmd->chanlist_len); + err |= comedi_check_trigger_arg_min( + &cmd->scan_begin_arg, + cmd->convert_arg * cmd->chanlist_len); } - err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg, - board->ai_speed * - cmd->chanlist_len); + err |= comedi_check_trigger_arg_min( + &cmd->scan_begin_arg, + board->ai_speed * cmd->chanlist_len); } switch (cmd->stop_src) { diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c index f98e3ae27bff..d99f4065b96d 100644 --- a/drivers/staging/comedi/drivers/ni_mio_common.c +++ b/drivers/staging/comedi/drivers/ni_mio_common.c @@ -2199,9 +2199,10 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) break; case TRIG_EXT: ai_trig |= NISTC_AI_TRIG_START1_SEL( - ni_get_reg_value_roffs(CR_CHAN(cmd->start_arg), - NI_AI_StartTrigger, - &devpriv->routing_tables, 1)); + ni_get_reg_value_roffs( + CR_CHAN(cmd->start_arg), + NI_AI_StartTrigger, + &devpriv->routing_tables, 1)); if (cmd->start_arg & CR_INVERT) ai_trig |= NISTC_AI_TRIG_START1_POLARITY; @@ -2311,10 +2312,12 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) (cmd->scan_begin_arg & ~CR_EDGE) != (cmd->convert_arg & ~CR_EDGE)) start_stop_select |= NISTC_AI_START_SYNC; + start_stop_select |= NISTC_AI_START_SEL( - ni_get_reg_value_roffs(CR_CHAN(cmd->scan_begin_arg), - NI_AI_SampleClock, - &devpriv->routing_tables, 1)); + ni_get_reg_value_roffs( + CR_CHAN(cmd->scan_begin_arg), + NI_AI_SampleClock, + &devpriv->routing_tables, 1)); ni_stc_writew(dev, start_stop_select, NISTC_AI_START_STOP_REG); break; } @@ -2343,9 +2346,10 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) break; case TRIG_EXT: mode1 |= NISTC_AI_MODE1_CONVERT_SRC( - ni_get_reg_value_roffs(CR_CHAN(cmd->convert_arg), - NI_AI_ConvertClock, - &devpriv->routing_tables, 1)); + ni_get_reg_value_roffs( + CR_CHAN(cmd->convert_arg), + NI_AI_ConvertClock, + &devpriv->routing_tables, 1)); if ((cmd->convert_arg & CR_INVERT) == 0) mode1 |= NISTC_AI_MODE1_CONVERT_POLARITY; ni_stc_writew(dev, mode1, NISTC_AI_MODE1_REG); @@ -2970,9 +2974,11 @@ static void ni_ao_cmd_set_trigger(struct comedi_device *dev, NISTC_AO_TRIG_START1_SYNC; } else { /* TRIG_EXT */ trigsel = NISTC_AO_TRIG_START1_SEL( - ni_get_reg_value_roffs(CR_CHAN(cmd->start_arg), - NI_AO_StartTrigger, - &devpriv->routing_tables, 1)); + ni_get_reg_value_roffs( + CR_CHAN(cmd->start_arg), + NI_AO_StartTrigger, + &devpriv->routing_tables, 1)); + /* 0=active high, 1=active low. see daq-stc 3-24 (p186) */ if (cmd->start_arg & CR_INVERT) trigsel |= NISTC_AO_TRIG_START1_POLARITY; @@ -3079,12 +3085,10 @@ static void ni_ao_cmd_set_update(struct comedi_device *dev, * zero out these bit fields to be set below. Does an ao-reset do this * automatically? */ - devpriv->ao_mode1 &= ~( - NISTC_AO_MODE1_UI_SRC_MASK | - NISTC_AO_MODE1_UI_SRC_POLARITY | - NISTC_AO_MODE1_UPDATE_SRC_MASK | - NISTC_AO_MODE1_UPDATE_SRC_POLARITY - ); + devpriv->ao_mode1 &= ~(NISTC_AO_MODE1_UI_SRC_MASK | + NISTC_AO_MODE1_UI_SRC_POLARITY | + NISTC_AO_MODE1_UPDATE_SRC_MASK | + NISTC_AO_MODE1_UPDATE_SRC_POLARITY); if (cmd->scan_begin_src == TRIG_TIMER) { unsigned int trigvar; @@ -3134,9 +3138,10 @@ static void ni_ao_cmd_set_update(struct comedi_device *dev, /* FIXME: assert scan_begin_arg != 0, ret failure otherwise */ devpriv->ao_cmd2 |= NISTC_AO_CMD2_BC_GATE_ENA; devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC( - ni_get_reg_value(CR_CHAN(cmd->scan_begin_arg), - NI_AO_SampleClock, - &devpriv->routing_tables)); + ni_get_reg_value( + CR_CHAN(cmd->scan_begin_arg), + NI_AO_SampleClock, + &devpriv->routing_tables)); if (cmd->scan_begin_arg & CR_INVERT) devpriv->ao_mode1 |= NISTC_AO_MODE1_UPDATE_SRC_POLARITY; } @@ -3673,9 +3678,10 @@ static int ni_cdio_cmd(struct comedi_device *dev, struct comedi_subdevice *s) cdo_mode_bits = NI_M_CDO_MODE_FIFO_MODE | NI_M_CDO_MODE_HALT_ON_ERROR | NI_M_CDO_MODE_SAMPLE_SRC( - ni_get_reg_value(CR_CHAN(cmd->scan_begin_arg), - NI_DO_SampleClock, - &devpriv->routing_tables)); + ni_get_reg_value( + CR_CHAN(cmd->scan_begin_arg), + NI_DO_SampleClock, + &devpriv->routing_tables)); if (cmd->scan_begin_arg & CR_INVERT) cdo_mode_bits |= NI_M_CDO_MODE_POLARITY; ni_writel(dev, cdo_mode_bits, NI_M_CDO_MODE_REG); @@ -5975,6 +5981,7 @@ static int ni_E_init(struct comedi_device *dev, /* prepare the device for globally-named routes. */ if (ni_assign_device_routes(dev_family, board->name, + board->alt_route_name, &devpriv->routing_tables) < 0) { dev_warn(dev->class_dev, "%s: %s device has no signal routing table.\n", __func__, board->name); diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c index 14b26fffe049..7c82d5f9778f 100644 --- a/drivers/staging/comedi/drivers/ni_pcimio.c +++ b/drivers/staging/comedi/drivers/ni_pcimio.c @@ -888,6 +888,7 @@ static const struct ni_board_struct ni_boards[] = { }, [BOARD_PCIE6251] = { .name = "pcie-6251", + .alt_route_name = "pci-6251", .n_adchan = 16, .ai_maxdata = 0xffff, .ai_fifo_depth = 4095, @@ -976,6 +977,7 @@ static const struct ni_board_struct ni_boards[] = { }, [BOARD_PCIE6259] = { .name = "pcie-6259", + .alt_route_name = "pci-6259", .n_adchan = 32, .ai_maxdata = 0xffff, .ai_fifo_depth = 4095, diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c index 8f398b30f5bf..07cb970340db 100644 --- a/drivers/staging/comedi/drivers/ni_routes.c +++ b/drivers/staging/comedi/drivers/ni_routes.c @@ -50,20 +50,13 @@ #define RVi(table, src, dest) ((table)[(dest) * NI_NUM_NAMES + (src)]) /* - * Find the proper route_values and ni_device_routes tables for this particular - * device. - * - * Return: -ENODATA if either was not found; 0 if both were found. + * Find the route values for a device family. */ -static int ni_find_device_routes(const char *device_family, - const char *board_name, - struct ni_route_tables *tables) +static const u8 *ni_find_route_values(const char *device_family) { - const struct ni_device_routes *dr = NULL; const u8 *rv = NULL; int i; - /* First, find the register_values table for this device family */ for (i = 0; ni_all_route_values[i]; ++i) { if (memcmp(ni_all_route_values[i]->family, device_family, strnlen(device_family, 30)) == 0) { @@ -71,8 +64,18 @@ static int ni_find_device_routes(const char *device_family, break; } } + return rv; +} + +/* + * Find the valid routes for a board. + */ +static const struct ni_device_routes * +ni_find_valid_routes(const char *board_name) +{ + const struct ni_device_routes *dr = NULL; + int i; - /* Second, find the set of routes valid for this device. */ for (i = 0; ni_device_routes_list[i]; ++i) { if (memcmp(ni_device_routes_list[i]->device, board_name, strnlen(board_name, 30)) == 0) { @@ -80,6 +83,31 @@ static int ni_find_device_routes(const char *device_family, break; } } + return dr; +} + +/* + * Find the proper route_values and ni_device_routes tables for this particular + * device. Possibly try an alternate board name if device routes not found + * for the actual board name. + * + * Return: -ENODATA if either was not found; 0 if both were found. + */ +static int ni_find_device_routes(const char *device_family, + const char *board_name, + const char *alt_board_name, + struct ni_route_tables *tables) +{ + const struct ni_device_routes *dr; + const u8 *rv; + + /* First, find the register_values table for this device family */ + rv = ni_find_route_values(device_family); + + /* Second, find the set of routes valid for this device. */ + dr = ni_find_valid_routes(board_name); + if (!dr && alt_board_name) + dr = ni_find_valid_routes(alt_board_name); tables->route_values = rv; tables->valid_routes = dr; @@ -93,15 +121,28 @@ static int ni_find_device_routes(const char *device_family, /** * ni_assign_device_routes() - Assign the proper lookup table for NI signal * routing to the specified NI device. + * @device_family: Device family name (determines route values). + * @board_name: Board name (determines set of routes). + * @alt_board_name: Optional alternate board name to try on failure. + * @tables: Pointer to assigned routing information. + * + * Finds the route values for the device family and the set of valid routes + * for the board. If valid routes could not be found for the actual board + * name and an alternate board name has been specified, try that one. + * + * On failure, the assigned routing information may be partially filled + * (for example, with the route values but not the set of valid routes). * * Return: -ENODATA if assignment was not successful; 0 if successful. */ int ni_assign_device_routes(const char *device_family, const char *board_name, + const char *alt_board_name, struct ni_route_tables *tables) { memset(tables, 0, sizeof(struct ni_route_tables)); - return ni_find_device_routes(device_family, board_name, tables); + return ni_find_device_routes(device_family, board_name, alt_board_name, + tables); } EXPORT_SYMBOL_GPL(ni_assign_device_routes); diff --git a/drivers/staging/comedi/drivers/ni_routes.h b/drivers/staging/comedi/drivers/ni_routes.h index 3211a16adc6f..b7680fd2afe1 100644 --- a/drivers/staging/comedi/drivers/ni_routes.h +++ b/drivers/staging/comedi/drivers/ni_routes.h @@ -76,6 +76,7 @@ struct ni_route_tables { */ int ni_assign_device_routes(const char *device_family, const char *board_name, + const char *alt_board_name, struct ni_route_tables *tables); /* diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h index 35427f8bf8f7..fbc0b753a0f5 100644 --- a/drivers/staging/comedi/drivers/ni_stc.h +++ b/drivers/staging/comedi/drivers/ni_stc.h @@ -941,6 +941,7 @@ enum ni_reg_type { struct ni_board_struct { const char *name; + const char *alt_route_name; int device_id; int isapnp_id; diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c index b264db32a411..f6154addaa95 100644 --- a/drivers/staging/comedi/drivers/ni_tio.c +++ b/drivers/staging/comedi/drivers/ni_tio.c @@ -1342,8 +1342,8 @@ static int ni_m_gate2_to_generic_gate(unsigned int gate, unsigned int *src) static inline unsigned int ni_tio_get_gate_mode(struct ni_gpct *counter) { - unsigned int mode = ni_tio_get_soft_copy( - counter, NITIO_MODE_REG(counter->counter_index)); + unsigned int mode = ni_tio_get_soft_copy(counter, + NITIO_MODE_REG(counter->counter_index)); unsigned int ret = 0; if ((mode & GI_GATING_MODE_MASK) == GI_GATING_DISABLED) @@ -1358,8 +1358,8 @@ static inline unsigned int ni_tio_get_gate_mode(struct ni_gpct *counter) static inline unsigned int ni_tio_get_gate2_mode(struct ni_gpct *counter) { - unsigned int mode = ni_tio_get_soft_copy( - counter, NITIO_GATE2_REG(counter->counter_index)); + unsigned int mode = ni_tio_get_soft_copy(counter, + NITIO_GATE2_REG(counter->counter_index)); unsigned int ret = 0; if (!(mode & GI_GATE2_MODE)) diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c index bb400e08f0bc..8c04af09be2c 100644 --- a/drivers/staging/comedi/drivers/rtd520.c +++ b/drivers/staging/comedi/drivers/rtd520.c @@ -815,9 +815,8 @@ static int rtd_ai_cmdtest(struct comedi_device *dev, if (cmd->scan_begin_src == TRIG_TIMER) { arg = cmd->convert_arg * cmd->scan_end_arg; - err |= comedi_check_trigger_arg_min(&cmd-> - scan_begin_arg, - arg); + err |= comedi_check_trigger_arg_min( + &cmd->scan_begin_arg, arg); } } diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c index 39049d3c56d7..084a8e7b9fc2 100644 --- a/drivers/staging/comedi/drivers/s626.c +++ b/drivers/staging/comedi/drivers/s626.c @@ -1892,8 +1892,7 @@ static int s626_ai_cmdtest(struct comedi_device *dev, if (cmd->scan_begin_src == TRIG_TIMER) { arg = cmd->convert_arg * cmd->scan_end_arg; err |= comedi_check_trigger_arg_min( - &cmd->scan_begin_arg, - arg); + &cmd->scan_begin_arg, arg); } } diff --git a/drivers/staging/exfat/Kconfig b/drivers/staging/exfat/Kconfig deleted file mode 100644 index 292a19dfcaf5..000000000000 --- a/drivers/staging/exfat/Kconfig +++ /dev/null @@ -1,41 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -config STAGING_EXFAT_FS - tristate "exFAT fs support" - depends on BLOCK - select NLS - help - This adds support for the exFAT file system. - -config STAGING_EXFAT_DISCARD - bool "enable discard support" - depends on STAGING_EXFAT_FS - default y - -config STAGING_EXFAT_DELAYED_SYNC - bool "enable delayed sync" - depends on STAGING_EXFAT_FS - default n - -config STAGING_EXFAT_KERNEL_DEBUG - bool "enable kernel debug features via ioctl" - depends on STAGING_EXFAT_FS - default n - -config STAGING_EXFAT_DEBUG_MSG - bool "print debug messages" - depends on STAGING_EXFAT_FS - default n - -config STAGING_EXFAT_DEFAULT_CODEPAGE - int "Default codepage for exFAT" - default 437 - depends on STAGING_EXFAT_FS - help - This option should be set to the codepage of your exFAT filesystems. - -config STAGING_EXFAT_DEFAULT_IOCHARSET - string "Default iocharset for exFAT" - default "utf8" - depends on STAGING_EXFAT_FS - help - Set this to the default input/output character set you'd like exFAT to use. diff --git a/drivers/staging/exfat/Makefile b/drivers/staging/exfat/Makefile deleted file mode 100644 index 057556eeca0c..000000000000 --- a/drivers/staging/exfat/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later - -obj-$(CONFIG_STAGING_EXFAT_FS) += exfat.o - -exfat-y := exfat_core.o \ - exfat_super.o \ - exfat_blkdev.o \ - exfat_cache.o \ - exfat_nls.o \ - exfat_upcase.o diff --git a/drivers/staging/exfat/TODO b/drivers/staging/exfat/TODO deleted file mode 100644 index a283ce534cf4..000000000000 --- a/drivers/staging/exfat/TODO +++ /dev/null @@ -1,69 +0,0 @@ -A laundry list of things that need looking at, most of which will -require more work than the average checkpatch cleanup... - -Note that some of these entries may not be bugs - they're things -that need to be looked at, and *possibly* fixed. - -Clean up the ffsCamelCase function names. - -Fix (thing)->flags to not use magic numbers - multiple offenders - -Sort out all the s32/u32/u8 nonsense - most of these should be plain int. - -exfat_core.c - ffsReadFile - the goto err_out seem to leak a brelse(). -same for ffsWriteFile. - -All the calls to fs_sync() need to be looked at, particularly in the -context of EXFAT_DELAYED_SYNC. Currently, if that's defined, we only -flush to disk when sync() gets called. We should be doing at least -metadata flushes at appropriate times. - -ffsTruncateFile - if (old_size <= new_size) { -That doesn't look right. How did it ever work? Are they relying on lazy -block allocation when actual writes happen? If nothing else, it never -does the 'fid->size = new_size' and do the inode update.... - -ffsSetAttr() is just dangling in the breeze, not wired up at all... - -Convert global mutexes to a per-superblock mutex. - -Right now, we load exactly one UTF-8 table. Check to see -if that plays nice with different codepage and iocharset values -for simultanous mounts of different devices - -exfat_rmdir() checks for -EBUSY but ffsRemoveDir() doesn't return it. -In fact, there's a complete lack of -EBUSY testing anywhere. - -There's probably a few missing checks for -EEXIST - -check return codes of sync_dirty_buffer() - -Why is remove_file doing a num_entries++?? - -Double check a lot of can't-happen parameter checks (for null pointers for -things that have only one call site and can't pass a null, etc). - -All the DEBUG stuff can probably be tossed, including the ioctl(). Either -that, or convert to a proper fault-injection system. - -exfat_remount does exactly one thing. Fix to actually deal with remount -options, particularly handling R/O correctly. For that matter, allow -R/O mounts in the first place. - -Figure out why the VFAT code used multi_sector_(read|write) but the -exfat code doesn't use it. The difference matters on SSDs with wear leveling. - -exfat_fat_sync(), exfat_buf_sync(), and sync_alloc_bitmap() -aren't called anyplace.... - -Create helper function for exfat_set_entry_time() and exfat_set_entry_type() -because it's sort of ugly to be calling the same functionn directly and -other code calling through the fs_func struc ponters... - -clean up the remaining vol_type checks, which are of two types: -some are ?: operators with magic numbers, and the rest are places -where we're doing stuff with '.' and '..'. - -Patches to: - Greg Kroah-Hartman <gregkh@linuxfoundation.org> - Valdis Kletnieks <valdis.kletnieks@vt.edu> diff --git a/drivers/staging/exfat/exfat.h b/drivers/staging/exfat/exfat.h deleted file mode 100644 index 4d87360fab35..000000000000 --- a/drivers/staging/exfat/exfat.h +++ /dev/null @@ -1,824 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#ifndef _EXFAT_H -#define _EXFAT_H - -#include <linux/types.h> -#include <linux/buffer_head.h> - -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - /* For Debugging Purpose */ - /* IOCTL code 'f' used by - * - file systems typically #0~0x1F - * - embedded terminal devices #128~ - * - exts for debugging purpose #99 - * number 100 and 101 is available now but has possible conflicts - */ -#define EXFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long) -#define EXFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long) - -#define EXFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01 -#define EXFAT_DEBUGFLAGS_ERROR_RW 0x02 -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - -#ifdef CONFIG_STAGING_EXFAT_DEBUG_MSG -#define DEBUG 1 -#else -#undef DEBUG -#endif - -#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ - -#define DENTRY_SIZE 32 /* dir entry size */ -#define DENTRY_SIZE_BITS 5 - -/* PBR entries */ -#define PBR_SIGNATURE 0xAA55 -#define EXT_SIGNATURE 0xAA550000 -#define VOL_LABEL "NO NAME " /* size should be 11 */ -#define OEM_NAME "MSWIN4.1" /* size should be 8 */ -#define STR_FAT12 "FAT12 " /* size should be 8 */ -#define STR_FAT16 "FAT16 " /* size should be 8 */ -#define STR_FAT32 "FAT32 " /* size should be 8 */ -#define STR_EXFAT "EXFAT " /* size should be 8 */ -#define VOL_CLEAN 0x0000 -#define VOL_DIRTY 0x0002 - -/* max number of clusters */ -#define FAT12_THRESHOLD 4087 /* 2^12 - 1 + 2 (clu 0 & 1) */ -#define FAT16_THRESHOLD 65527 /* 2^16 - 1 + 2 */ -#define FAT32_THRESHOLD 268435457 /* 2^28 - 1 + 2 */ -#define EXFAT_THRESHOLD 268435457 /* 2^28 - 1 + 2 */ - -/* file types */ -#define TYPE_UNUSED 0x0000 -#define TYPE_DELETED 0x0001 -#define TYPE_INVALID 0x0002 -#define TYPE_CRITICAL_PRI 0x0100 -#define TYPE_BITMAP 0x0101 -#define TYPE_UPCASE 0x0102 -#define TYPE_VOLUME 0x0103 -#define TYPE_DIR 0x0104 -#define TYPE_FILE 0x011F -#define TYPE_SYMLINK 0x015F -#define TYPE_CRITICAL_SEC 0x0200 -#define TYPE_STREAM 0x0201 -#define TYPE_EXTEND 0x0202 -#define TYPE_ACL 0x0203 -#define TYPE_BENIGN_PRI 0x0400 -#define TYPE_GUID 0x0401 -#define TYPE_PADDING 0x0402 -#define TYPE_ACLTAB 0x0403 -#define TYPE_BENIGN_SEC 0x0800 -#define TYPE_ALL 0x0FFF - -/* time modes */ -#define TM_CREATE 0 -#define TM_MODIFY 1 -#define TM_ACCESS 2 - -/* checksum types */ -#define CS_DIR_ENTRY 0 -#define CS_PBR_SECTOR 1 -#define CS_DEFAULT 2 - -#define CLUSTER_16(x) ((u16)(x)) -#define CLUSTER_32(x) ((u32)(x)) - -#define START_SECTOR(x) \ - ((((sector_t)((x) - 2)) << p_fs->sectors_per_clu_bits) + \ - p_fs->data_start_sector) - -#define IS_LAST_SECTOR_IN_CLUSTER(sec) \ - ((((sec) - p_fs->data_start_sector + 1) & \ - ((1 << p_fs->sectors_per_clu_bits) - 1)) == 0) - -#define GET_CLUSTER_FROM_SECTOR(sec) \ - ((u32)((((sec) - p_fs->data_start_sector) >> \ - p_fs->sectors_per_clu_bits) + 2)) - -#define GET16(p_src) \ - (((u16)(p_src)[0]) | (((u16)(p_src)[1]) << 8)) -#define GET32(p_src) \ - (((u32)(p_src)[0]) | (((u32)(p_src)[1]) << 8) | \ - (((u32)(p_src)[2]) << 16) | (((u32)(p_src)[3]) << 24)) -#define GET64(p_src) \ - (((u64)(p_src)[0]) | (((u64)(p_src)[1]) << 8) | \ - (((u64)(p_src)[2]) << 16) | (((u64)(p_src)[3]) << 24) | \ - (((u64)(p_src)[4]) << 32) | (((u64)(p_src)[5]) << 40) | \ - (((u64)(p_src)[6]) << 48) | (((u64)(p_src)[7]) << 56)) - -#define SET16(p_dst, src) \ - do { \ - (p_dst)[0] = (u8)(src); \ - (p_dst)[1] = (u8)(((u16)(src)) >> 8); \ - } while (0) -#define SET32(p_dst, src) \ - do { \ - (p_dst)[0] = (u8)(src); \ - (p_dst)[1] = (u8)(((u32)(src)) >> 8); \ - (p_dst)[2] = (u8)(((u32)(src)) >> 16); \ - (p_dst)[3] = (u8)(((u32)(src)) >> 24); \ - } while (0) -#define SET64(p_dst, src) \ - do { \ - (p_dst)[0] = (u8)(src); \ - (p_dst)[1] = (u8)(((u64)(src)) >> 8); \ - (p_dst)[2] = (u8)(((u64)(src)) >> 16); \ - (p_dst)[3] = (u8)(((u64)(src)) >> 24); \ - (p_dst)[4] = (u8)(((u64)(src)) >> 32); \ - (p_dst)[5] = (u8)(((u64)(src)) >> 40); \ - (p_dst)[6] = (u8)(((u64)(src)) >> 48); \ - (p_dst)[7] = (u8)(((u64)(src)) >> 56); \ - } while (0) - -#ifdef __LITTLE_ENDIAN -#define GET16_A(p_src) (*((u16 *)(p_src))) -#define GET32_A(p_src) (*((u32 *)(p_src))) -#define GET64_A(p_src) (*((u64 *)(p_src))) -#define SET16_A(p_dst, src) (*((u16 *)(p_dst)) = (u16)(src)) -#define SET32_A(p_dst, src) (*((u32 *)(p_dst)) = (u32)(src)) -#define SET64_A(p_dst, src) (*((u64 *)(p_dst)) = (u64)(src)) -#else /* BIG_ENDIAN */ -#define GET16_A(p_src) GET16(p_src) -#define GET32_A(p_src) GET32(p_src) -#define GET64_A(p_src) GET64(p_src) -#define SET16_A(p_dst, src) SET16(p_dst, src) -#define SET32_A(p_dst, src) SET32(p_dst, src) -#define SET64_A(p_dst, src) SET64(p_dst, src) -#endif - -/* cache size (in number of sectors) */ -/* (should be an exponential value of 2) */ -#define FAT_CACHE_SIZE 128 -#define FAT_CACHE_HASH_SIZE 64 -#define BUF_CACHE_SIZE 256 -#define BUF_CACHE_HASH_SIZE 64 - -/* Upcase table macro */ -#define HIGH_INDEX_BIT (8) -#define HIGH_INDEX_MASK (0xFF00) -#define LOW_INDEX_BIT (16 - HIGH_INDEX_BIT) -#define UTBL_ROW_COUNT BIT(LOW_INDEX_BIT) -#define UTBL_COL_COUNT BIT(HIGH_INDEX_BIT) - -static inline u16 get_col_index(u16 i) -{ - return i >> LOW_INDEX_BIT; -} - -static inline u16 get_row_index(u16 i) -{ - return i & ~HIGH_INDEX_MASK; -} - -#define EXFAT_SUPER_MAGIC (0x2011BAB0L) -#define EXFAT_ROOT_INO 1 - -/* FAT types */ -#define FAT12 0x01 /* FAT12 */ -#define FAT16 0x0E /* Win95 FAT16 (LBA) */ -#define FAT32 0x0C /* Win95 FAT32 (LBA) */ -#define EXFAT 0x07 /* exFAT */ - -/* file name lengths */ -#define MAX_CHARSET_SIZE 3 /* max size of multi-byte character */ -#define MAX_PATH_DEPTH 15 /* max depth of path name */ -#define MAX_NAME_LENGTH 256 /* max len of filename including NULL */ -#define MAX_PATH_LENGTH 260 /* max len of pathname including NULL */ -#define DOS_NAME_LENGTH 11 /* DOS filename length excluding NULL */ -#define DOS_PATH_LENGTH 80 /* DOS pathname length excluding NULL */ - -/* file attributes */ -#define ATTR_NORMAL 0x0000 -#define ATTR_READONLY 0x0001 -#define ATTR_HIDDEN 0x0002 -#define ATTR_SYSTEM 0x0004 -#define ATTR_VOLUME 0x0008 -#define ATTR_SUBDIR 0x0010 -#define ATTR_ARCHIVE 0x0020 -#define ATTR_SYMLINK 0x0040 -#define ATTR_EXTEND 0x000F -#define ATTR_RWMASK 0x007E - -/* file creation modes */ -#define FM_REGULAR 0x00 -#define FM_SYMLINK 0x40 - -#define NUM_UPCASE 2918 - -#define DOS_CUR_DIR_NAME ". " -#define DOS_PAR_DIR_NAME ".. " - -#ifdef __LITTLE_ENDIAN -#define UNI_CUR_DIR_NAME ".\0" -#define UNI_PAR_DIR_NAME ".\0.\0" -#else -#define UNI_CUR_DIR_NAME "\0." -#define UNI_PAR_DIR_NAME "\0.\0." -#endif - -struct date_time_t { - u16 Year; - u16 Month; - u16 Day; - u16 Hour; - u16 Minute; - u16 Second; - u16 MilliSecond; -}; - -struct part_info_t { - u32 Offset; /* start sector number of the partition */ - u32 Size; /* in sectors */ -}; - -struct dev_info_t { - u32 SecSize; /* sector size in bytes */ - u32 DevSize; /* block device size in sectors */ -}; - -struct vol_info_t { - u32 FatType; - u32 ClusterSize; - u32 NumClusters; - u32 FreeClusters; - u32 UsedClusters; -}; - -/* directory structure */ -struct chain_t { - u32 dir; - s32 size; - u8 flags; -}; - -struct file_id_t { - struct chain_t dir; - s32 entry; - u32 type; - u32 attr; - u32 start_clu; - u64 size; - u8 flags; - s64 rwoffset; - s32 hint_last_off; - u32 hint_last_clu; -}; - -struct dir_entry_t { - char Name[MAX_NAME_LENGTH * MAX_CHARSET_SIZE]; - - /* used only for FAT12/16/32, not used for exFAT */ - char ShortName[DOS_NAME_LENGTH + 2]; - - u32 Attr; - u64 Size; - u32 NumSubdirs; - struct date_time_t CreateTimestamp; - struct date_time_t ModifyTimestamp; - struct date_time_t AccessTimestamp; -}; - -struct timestamp_t { - u16 sec; /* 0 ~ 59 */ - u16 min; /* 0 ~ 59 */ - u16 hour; /* 0 ~ 23 */ - u16 day; /* 1 ~ 31 */ - u16 mon; /* 1 ~ 12 */ - u16 year; /* 0 ~ 127 (since 1980) */ -}; - -/* MS_DOS FAT partition boot record (512 bytes) */ -struct pbr_sector_t { - u8 jmp_boot[3]; - u8 oem_name[8]; - u8 bpb[109]; - u8 boot_code[390]; - u8 signature[2]; -}; - -/* MS-DOS FAT12/16 BIOS parameter block (51 bytes) */ -struct bpb16_t { - u8 sector_size[2]; - u8 sectors_per_clu; - u8 num_reserved[2]; - u8 num_fats; - u8 num_root_entries[2]; - u8 num_sectors[2]; - u8 media_type; - u8 num_fat_sectors[2]; - u8 sectors_in_track[2]; - u8 num_heads[2]; - u8 num_hid_sectors[4]; - u8 num_huge_sectors[4]; - - u8 phy_drv_no; - u8 reserved; - u8 ext_signature; - u8 vol_serial[4]; - u8 vol_label[11]; - u8 vol_type[8]; -}; - -/* MS-DOS FAT32 BIOS parameter block (79 bytes) */ -struct bpb32_t { - u8 sector_size[2]; - u8 sectors_per_clu; - u8 num_reserved[2]; - u8 num_fats; - u8 num_root_entries[2]; - u8 num_sectors[2]; - u8 media_type; - u8 num_fat_sectors[2]; - u8 sectors_in_track[2]; - u8 num_heads[2]; - u8 num_hid_sectors[4]; - u8 num_huge_sectors[4]; - u8 num_fat32_sectors[4]; - u8 ext_flags[2]; - u8 fs_version[2]; - u8 root_cluster[4]; - u8 fsinfo_sector[2]; - u8 backup_sector[2]; - u8 reserved[12]; - - u8 phy_drv_no; - u8 ext_reserved; - u8 ext_signature; - u8 vol_serial[4]; - u8 vol_label[11]; - u8 vol_type[8]; -}; - -/* MS-DOS EXFAT BIOS parameter block (109 bytes) */ -struct bpbex_t { - u8 reserved1[53]; - u8 vol_offset[8]; - u8 vol_length[8]; - u8 fat_offset[4]; - u8 fat_length[4]; - u8 clu_offset[4]; - u8 clu_count[4]; - u8 root_cluster[4]; - u8 vol_serial[4]; - u8 fs_version[2]; - u8 vol_flags[2]; - u8 sector_size_bits; - u8 sectors_per_clu_bits; - u8 num_fats; - u8 phy_drv_no; - u8 perc_in_use; - u8 reserved2[7]; -}; - -/* MS-DOS FAT file system information sector (512 bytes) */ -struct fsi_sector_t { - u8 signature1[4]; - u8 reserved1[480]; - u8 signature2[4]; - u8 free_cluster[4]; - u8 next_cluster[4]; - u8 reserved2[14]; - u8 signature3[2]; -}; - -/* MS-DOS FAT directory entry (32 bytes) */ -struct dentry_t { - u8 dummy[32]; -}; - -struct dos_dentry_t { - u8 name[DOS_NAME_LENGTH]; - u8 attr; - u8 lcase; - u8 create_time_ms; - u8 create_time[2]; - u8 create_date[2]; - u8 access_date[2]; - u8 start_clu_hi[2]; - u8 modify_time[2]; - u8 modify_date[2]; - u8 start_clu_lo[2]; - u8 size[4]; -}; - -/* MS-DOS FAT extended directory entry (32 bytes) */ -struct ext_dentry_t { - u8 order; - u8 unicode_0_4[10]; - u8 attr; - u8 sysid; - u8 checksum; - u8 unicode_5_10[12]; - u8 start_clu[2]; - u8 unicode_11_12[4]; -}; - -/* MS-DOS EXFAT file directory entry (32 bytes) */ -struct file_dentry_t { - u8 type; - u8 num_ext; - u8 checksum[2]; - u8 attr[2]; - u8 reserved1[2]; - u8 create_time[2]; - u8 create_date[2]; - u8 modify_time[2]; - u8 modify_date[2]; - u8 access_time[2]; - u8 access_date[2]; - u8 create_time_ms; - u8 modify_time_ms; - u8 access_time_ms; - u8 reserved2[9]; -}; - -/* MS-DOS EXFAT stream extension directory entry (32 bytes) */ -struct strm_dentry_t { - u8 type; - u8 flags; - u8 reserved1; - u8 name_len; - u8 name_hash[2]; - u8 reserved2[2]; - u8 valid_size[8]; - u8 reserved3[4]; - u8 start_clu[4]; - u8 size[8]; -}; - -/* MS-DOS EXFAT file name directory entry (32 bytes) */ -struct name_dentry_t { - u8 type; - u8 flags; - u8 unicode_0_14[30]; -}; - -/* MS-DOS EXFAT allocation bitmap directory entry (32 bytes) */ -struct bmap_dentry_t { - u8 type; - u8 flags; - u8 reserved[18]; - u8 start_clu[4]; - u8 size[8]; -}; - -/* MS-DOS EXFAT up-case table directory entry (32 bytes) */ -struct case_dentry_t { - u8 type; - u8 reserved1[3]; - u8 checksum[4]; - u8 reserved2[12]; - u8 start_clu[4]; - u8 size[8]; -}; - -/* MS-DOS EXFAT volume label directory entry (32 bytes) */ -struct volm_dentry_t { - u8 type; - u8 label_len; - u8 unicode_0_10[22]; - u8 reserved[8]; -}; - -/* unused entry hint information */ -struct uentry_t { - u32 dir; - s32 entry; - struct chain_t clu; -}; - -/* DOS name structure */ -struct dos_name_t { - u8 name[DOS_NAME_LENGTH]; - u8 name_case; -}; - -/* unicode name structure */ -struct uni_name_t { - u16 name[MAX_NAME_LENGTH]; - u16 name_hash; - u8 name_len; -}; - -struct buf_cache_t { - struct buf_cache_t *next; - struct buf_cache_t *prev; - struct buf_cache_t *hash_next; - struct buf_cache_t *hash_prev; - s32 drv; - sector_t sec; - u32 flag; - struct buffer_head *buf_bh; -}; - -struct fs_info_t { - u32 drv; /* drive ID */ - u32 vol_type; /* volume FAT type */ - u32 vol_id; /* volume serial number */ - - u64 num_sectors; /* num of sectors in volume */ - u32 num_clusters; /* num of clusters in volume */ - u32 cluster_size; /* cluster size in bytes */ - u32 cluster_size_bits; - u32 sectors_per_clu; /* cluster size in sectors */ - u32 sectors_per_clu_bits; - - u32 PBR_sector; /* PBR sector */ - u32 FAT1_start_sector; /* FAT1 start sector */ - u32 FAT2_start_sector; /* FAT2 start sector */ - u32 root_start_sector; /* root dir start sector */ - u32 data_start_sector; /* data area start sector */ - u32 num_FAT_sectors; /* num of FAT sectors */ - - u32 root_dir; /* root dir cluster */ - u32 dentries_in_root; /* num of dentries in root dir */ - u32 dentries_per_clu; /* num of dentries per cluster */ - - u32 vol_flag; /* volume dirty flag */ - struct buffer_head *pbr_bh; /* PBR sector */ - - u32 map_clu; /* allocation bitmap start cluster */ - u32 map_sectors; /* num of allocation bitmap sectors */ - struct buffer_head **vol_amap; /* allocation bitmap */ - - u16 **vol_utbl; /* upcase table */ - - u32 clu_srch_ptr; /* cluster search pointer */ - u32 used_clusters; /* number of used clusters */ - struct uentry_t hint_uentry; /* unused entry hint information */ - - u32 dev_ejected; /* block device operation error flag */ - - struct mutex v_mutex; - - /* FAT cache */ - struct buf_cache_t FAT_cache_array[FAT_CACHE_SIZE]; - struct buf_cache_t FAT_cache_lru_list; - struct buf_cache_t FAT_cache_hash_list[FAT_CACHE_HASH_SIZE]; - - /* buf cache */ - struct buf_cache_t buf_cache_array[BUF_CACHE_SIZE]; - struct buf_cache_t buf_cache_lru_list; - struct buf_cache_t buf_cache_hash_list[BUF_CACHE_HASH_SIZE]; -}; - -#define ES_2_ENTRIES 2 -#define ES_3_ENTRIES 3 -#define ES_ALL_ENTRIES 0 - -struct entry_set_cache_t { - /* sector number that contains file_entry */ - sector_t sector; - - /* byte offset in the sector */ - s32 offset; - - /* - * flag in stream entry. - * 01 for cluster chain, - * 03 for contig. clusteres. - */ - s32 alloc_flag; - - u32 num_entries; - - /* __buf should be the last member */ - void *__buf; -}; - -#define EXFAT_ERRORS_CONT 1 /* ignore error and continue */ -#define EXFAT_ERRORS_PANIC 2 /* panic on error */ -#define EXFAT_ERRORS_RO 3 /* remount r/o on error */ - -/* ioctl command */ -#define EXFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32) - -struct exfat_mount_options { - kuid_t fs_uid; - kgid_t fs_gid; - unsigned short fs_fmask; - unsigned short fs_dmask; - - /* permission for setting the [am]time */ - unsigned short allow_utime; - - /* codepage for shortname conversions */ - unsigned short codepage; - - /* charset for filename input/display */ - char *iocharset; - - unsigned char casesensitive; - - /* on error: continue, panic, remount-ro */ - unsigned char errors; -#ifdef CONFIG_STAGING_EXFAT_DISCARD - /* flag on if -o dicard specified and device support discard() */ - unsigned char discard; -#endif /* CONFIG_STAGING_EXFAT_DISCARD */ -}; - -#define EXFAT_HASH_BITS 8 -#define EXFAT_HASH_SIZE BIT(EXFAT_HASH_BITS) - -/* - * EXFAT file system in-core superblock data - */ -struct bd_info_t { - s32 sector_size; /* in bytes */ - s32 sector_size_bits; - s32 sector_size_mask; - - /* total number of sectors in this block device */ - s32 num_sectors; - - /* opened or not */ - bool opened; -}; - -struct exfat_sb_info { - struct fs_info_t fs_info; - struct bd_info_t bd_info; - - struct exfat_mount_options options; - - int s_dirt; - struct mutex s_lock; - struct nls_table *nls_disk; /* Codepage used on disk */ - struct nls_table *nls_io; /* Charset used for input and display */ - - struct inode *fat_inode; - - spinlock_t inode_hash_lock; - struct hlist_head inode_hashtable[EXFAT_HASH_SIZE]; -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - long debug_flags; -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ -}; - -/* - * EXFAT file system inode data in memory - */ -struct exfat_inode_info { - struct file_id_t fid; - char *target; - /* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */ - loff_t mmu_private; /* physically allocated size */ - loff_t i_pos; /* on-disk position of directory entry or 0 */ - struct hlist_node i_hash_fat; /* hash by i_location */ - struct rw_semaphore truncate_lock; - struct inode vfs_inode; - struct rw_semaphore i_alloc_sem; /* protect bmap against truncate */ -}; - -#define EXFAT_SB(sb) ((struct exfat_sb_info *)((sb)->s_fs_info)) - -static inline struct exfat_inode_info *EXFAT_I(struct inode *inode) -{ - return container_of(inode, struct exfat_inode_info, vfs_inode); -} - -/* NLS management function */ -u16 nls_upper(struct super_block *sb, u16 a); -int nls_uniname_cmp(struct super_block *sb, u16 *a, u16 *b); -void nls_uniname_to_cstring(struct super_block *sb, u8 *p_cstring, - struct uni_name_t *p_uniname); -void nls_cstring_to_uniname(struct super_block *sb, - struct uni_name_t *p_uniname, u8 *p_cstring, - bool *p_lossy); - -/* buffer cache management */ -void exfat_buf_init(struct super_block *sb); -void exfat_buf_shutdown(struct super_block *sb); -int exfat_fat_read(struct super_block *sb, u32 loc, u32 *content); -s32 exfat_fat_write(struct super_block *sb, u32 loc, u32 content); -u8 *exfat_fat_getblk(struct super_block *sb, sector_t sec); -void exfat_fat_modify(struct super_block *sb, sector_t sec); -void exfat_fat_release_all(struct super_block *sb); -void exfat_fat_sync(struct super_block *sb); -u8 *exfat_buf_getblk(struct super_block *sb, sector_t sec); -void exfat_buf_modify(struct super_block *sb, sector_t sec); -void exfat_buf_lock(struct super_block *sb, sector_t sec); -void exfat_buf_unlock(struct super_block *sb, sector_t sec); -void exfat_buf_release(struct super_block *sb, sector_t sec); -void exfat_buf_release_all(struct super_block *sb); -void exfat_buf_sync(struct super_block *sb); - -/* fs management functions */ -void fs_set_vol_flags(struct super_block *sb, u32 new_flag); -void fs_error(struct super_block *sb); - -/* cluster management functions */ -s32 count_num_clusters(struct super_block *sb, struct chain_t *dir); -void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len); - -/* allocation bitmap management functions */ -s32 load_alloc_bitmap(struct super_block *sb); -void free_alloc_bitmap(struct super_block *sb); -void sync_alloc_bitmap(struct super_block *sb); - -/* upcase table management functions */ -s32 load_upcase_table(struct super_block *sb); -void free_upcase_table(struct super_block *sb); - -/* dir entry management functions */ -struct timestamp_t *tm_current(struct timestamp_t *tm); - -struct dentry_t *get_entry_in_dir(struct super_block *sb, struct chain_t *p_dir, - s32 entry, sector_t *sector); -struct entry_set_cache_t *get_entry_set_in_dir(struct super_block *sb, - struct chain_t *p_dir, s32 entry, - u32 type, - struct dentry_t **file_ep); -void release_entry_set(struct entry_set_cache_t *es); -s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir, - u32 type); -void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir, - s32 entry); -void update_dir_checksum_with_entry_set(struct super_block *sb, - struct entry_set_cache_t *es); -bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir); - -/* name conversion functions */ -s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir, - struct uni_name_t *p_uniname, s32 *entries, - struct dos_name_t *p_dosname); -u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type); - -/* name resolution functions */ -s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, - struct uni_name_t *p_uniname); - -/* file operation functions */ -s32 exfat_mount(struct super_block *sb, struct pbr_sector_t *p_pbr); -s32 create_dir(struct inode *inode, struct chain_t *p_dir, - struct uni_name_t *p_uniname, struct file_id_t *fid); -s32 create_file(struct inode *inode, struct chain_t *p_dir, - struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid); -void remove_file(struct inode *inode, struct chain_t *p_dir, s32 entry); -s32 exfat_rename_file(struct inode *inode, struct chain_t *p_dir, s32 old_entry, - struct uni_name_t *p_uniname, struct file_id_t *fid); -s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, - struct chain_t *p_newdir, struct uni_name_t *p_uniname, - struct file_id_t *fid); - -/* sector read/write functions */ -int sector_read(struct super_block *sb, sector_t sec, - struct buffer_head **bh, bool read); -int sector_write(struct super_block *sb, sector_t sec, - struct buffer_head *bh, bool sync); -int multi_sector_read(struct super_block *sb, sector_t sec, - struct buffer_head **bh, s32 num_secs, bool read); -int multi_sector_write(struct super_block *sb, sector_t sec, - struct buffer_head *bh, s32 num_secs, bool sync); - -void exfat_bdev_open(struct super_block *sb); -void exfat_bdev_close(struct super_block *sb); -int exfat_bdev_read(struct super_block *sb, sector_t secno, - struct buffer_head **bh, u32 num_secs, bool read); -int exfat_bdev_write(struct super_block *sb, sector_t secno, - struct buffer_head *bh, u32 num_secs, bool sync); -int exfat_bdev_sync(struct super_block *sb); - -/* cluster operation functions */ -s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc, - struct chain_t *p_chain); -void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain, - s32 do_relse); -s32 exfat_count_used_clusters(struct super_block *sb); - -/* dir operation functions */ -s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir, - struct uni_name_t *p_uniname, s32 num_entries, - struct dos_name_t *p_dosname, u32 type); -void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir, - s32 entry, s32 order, s32 num_entries); -void exfat_get_uni_name_from_ext_entry(struct super_block *sb, - struct chain_t *p_dir, s32 entry, - u16 *uniname); -s32 exfat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir, - s32 entry, struct dentry_t *p_entry); -s32 exfat_calc_num_entries(struct uni_name_t *p_uniname); - -/* dir entry getter/setter */ -u32 exfat_get_entry_type(struct dentry_t *p_entry); -u32 exfat_get_entry_attr(struct dentry_t *p_entry); -void exfat_set_entry_attr(struct dentry_t *p_entry, u32 attr); -u8 exfat_get_entry_flag(struct dentry_t *p_entry); -void exfat_set_entry_flag(struct dentry_t *p_entry, u8 flags); -u32 exfat_get_entry_clu0(struct dentry_t *p_entry); -void exfat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu); -u64 exfat_get_entry_size(struct dentry_t *p_entry); -void exfat_set_entry_size(struct dentry_t *p_entry, u64 size); -void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp, - u8 mode); -void exfat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp, - u8 mode); - -extern const u8 uni_upcase[]; -#endif /* _EXFAT_H */ diff --git a/drivers/staging/exfat/exfat_blkdev.c b/drivers/staging/exfat/exfat_blkdev.c deleted file mode 100644 index 0a3dc3568293..000000000000 --- a/drivers/staging/exfat/exfat_blkdev.c +++ /dev/null @@ -1,136 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/blkdev.h> -#include <linux/buffer_head.h> -#include <linux/fs.h> -#include "exfat.h" - -void exfat_bdev_open(struct super_block *sb) -{ - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - if (p_bd->opened) - return; - - p_bd->sector_size = bdev_logical_block_size(sb->s_bdev); - p_bd->sector_size_bits = ilog2(p_bd->sector_size); - p_bd->sector_size_mask = p_bd->sector_size - 1; - p_bd->num_sectors = i_size_read(sb->s_bdev->bd_inode) >> - p_bd->sector_size_bits; - p_bd->opened = true; -} - -void exfat_bdev_close(struct super_block *sb) -{ - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - p_bd->opened = false; -} - -int exfat_bdev_read(struct super_block *sb, sector_t secno, struct buffer_head **bh, - u32 num_secs, bool read) -{ - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - struct exfat_sb_info *sbi = EXFAT_SB(sb); - long flags = sbi->debug_flags; - - if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) - return -EIO; -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - - if (!p_bd->opened) - return -ENODEV; - - if (*bh) - __brelse(*bh); - - if (read) - *bh = __bread(sb->s_bdev, secno, - num_secs << p_bd->sector_size_bits); - else - *bh = __getblk(sb->s_bdev, secno, - num_secs << p_bd->sector_size_bits); - - if (*bh) - return 0; - - WARN(!p_fs->dev_ejected, - "[EXFAT] No bh, device seems wrong or to be ejected.\n"); - - return -EIO; -} - -int exfat_bdev_write(struct super_block *sb, sector_t secno, struct buffer_head *bh, - u32 num_secs, bool sync) -{ - s32 count; - struct buffer_head *bh2; - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - struct exfat_sb_info *sbi = EXFAT_SB(sb); - long flags = sbi->debug_flags; - - if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) - return -EIO; -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - - if (!p_bd->opened) - return -ENODEV; - - if (secno == bh->b_blocknr) { - lock_buffer(bh); - set_buffer_uptodate(bh); - mark_buffer_dirty(bh); - unlock_buffer(bh); - if (sync && (sync_dirty_buffer(bh) != 0)) - return -EIO; - } else { - count = num_secs << p_bd->sector_size_bits; - - bh2 = __getblk(sb->s_bdev, secno, count); - if (!bh2) - goto no_bh; - - lock_buffer(bh2); - memcpy(bh2->b_data, bh->b_data, count); - set_buffer_uptodate(bh2); - mark_buffer_dirty(bh2); - unlock_buffer(bh2); - if (sync && (sync_dirty_buffer(bh2) != 0)) { - __brelse(bh2); - goto no_bh; - } - __brelse(bh2); - } - - return 0; - -no_bh: - WARN(!p_fs->dev_ejected, - "[EXFAT] No bh, device seems wrong or to be ejected.\n"); - - return -EIO; -} - -int exfat_bdev_sync(struct super_block *sb) -{ - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - struct exfat_sb_info *sbi = EXFAT_SB(sb); - long flags = sbi->debug_flags; - - if (flags & EXFAT_DEBUGFLAGS_ERROR_RW) - return -EIO; -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - - if (!p_bd->opened) - return -ENODEV; - - return sync_blockdev(sb->s_bdev); -} diff --git a/drivers/staging/exfat/exfat_cache.c b/drivers/staging/exfat/exfat_cache.c deleted file mode 100644 index 3fd5604058a9..000000000000 --- a/drivers/staging/exfat/exfat_cache.c +++ /dev/null @@ -1,555 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/buffer_head.h> -#include <linux/fs.h> -#include <linux/mutex.h> -#include "exfat.h" - -#define LOCKBIT 0x01 -#define DIRTYBIT 0x02 - -/* Local variables */ -static DEFINE_MUTEX(f_mutex); -static DEFINE_MUTEX(b_mutex); - -static struct buf_cache_t *FAT_cache_find(struct super_block *sb, sector_t sec) -{ - s32 off; - struct buf_cache_t *bp, *hp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - off = (sec + - (sec >> p_fs->sectors_per_clu_bits)) & (FAT_CACHE_HASH_SIZE - 1); - - hp = &p_fs->FAT_cache_hash_list[off]; - for (bp = hp->hash_next; bp != hp; bp = bp->hash_next) { - if ((bp->drv == p_fs->drv) && (bp->sec == sec)) { - WARN(!bp->buf_bh, - "[EXFAT] FAT_cache has no bh. It will make system panic.\n"); - - touch_buffer(bp->buf_bh); - return bp; - } - } - return NULL; -} - -static void push_to_mru(struct buf_cache_t *bp, struct buf_cache_t *list) -{ - bp->next = list->next; - bp->prev = list; - list->next->prev = bp; - list->next = bp; -} - -static void push_to_lru(struct buf_cache_t *bp, struct buf_cache_t *list) -{ - bp->prev = list->prev; - bp->next = list; - list->prev->next = bp; - list->prev = bp; -} - -static void move_to_mru(struct buf_cache_t *bp, struct buf_cache_t *list) -{ - bp->prev->next = bp->next; - bp->next->prev = bp->prev; - push_to_mru(bp, list); -} - -static void move_to_lru(struct buf_cache_t *bp, struct buf_cache_t *list) -{ - bp->prev->next = bp->next; - bp->next->prev = bp->prev; - push_to_lru(bp, list); -} - -static struct buf_cache_t *FAT_cache_get(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - bp = p_fs->FAT_cache_lru_list.prev; - - move_to_mru(bp, &p_fs->FAT_cache_lru_list); - return bp; -} - -static void FAT_cache_insert_hash(struct super_block *sb, - struct buf_cache_t *bp) -{ - s32 off; - struct buf_cache_t *hp; - struct fs_info_t *p_fs; - - p_fs = &(EXFAT_SB(sb)->fs_info); - off = (bp->sec + - (bp->sec >> p_fs->sectors_per_clu_bits)) & - (FAT_CACHE_HASH_SIZE - 1); - - hp = &p_fs->FAT_cache_hash_list[off]; - bp->hash_next = hp->hash_next; - bp->hash_prev = hp; - hp->hash_next->hash_prev = bp; - hp->hash_next = bp; -} - -static void FAT_cache_remove_hash(struct buf_cache_t *bp) -{ - (bp->hash_prev)->hash_next = bp->hash_next; - (bp->hash_next)->hash_prev = bp->hash_prev; -} - -static void buf_cache_insert_hash(struct super_block *sb, - struct buf_cache_t *bp) -{ - s32 off; - struct buf_cache_t *hp; - struct fs_info_t *p_fs; - - p_fs = &(EXFAT_SB(sb)->fs_info); - off = (bp->sec + - (bp->sec >> p_fs->sectors_per_clu_bits)) & - (BUF_CACHE_HASH_SIZE - 1); - - hp = &p_fs->buf_cache_hash_list[off]; - bp->hash_next = hp->hash_next; - bp->hash_prev = hp; - hp->hash_next->hash_prev = bp; - hp->hash_next = bp; -} - -static void buf_cache_remove_hash(struct buf_cache_t *bp) -{ - (bp->hash_prev)->hash_next = bp->hash_next; - (bp->hash_next)->hash_prev = bp->hash_prev; -} - -void exfat_buf_init(struct super_block *sb) -{ - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - int i; - - /* LRU list */ - p_fs->FAT_cache_lru_list.next = &p_fs->FAT_cache_lru_list; - p_fs->FAT_cache_lru_list.prev = &p_fs->FAT_cache_lru_list; - - for (i = 0; i < FAT_CACHE_SIZE; i++) { - p_fs->FAT_cache_array[i].drv = -1; - p_fs->FAT_cache_array[i].sec = ~0; - p_fs->FAT_cache_array[i].flag = 0; - p_fs->FAT_cache_array[i].buf_bh = NULL; - p_fs->FAT_cache_array[i].prev = NULL; - p_fs->FAT_cache_array[i].next = NULL; - push_to_mru(&p_fs->FAT_cache_array[i], - &p_fs->FAT_cache_lru_list); - } - - p_fs->buf_cache_lru_list.next = &p_fs->buf_cache_lru_list; - p_fs->buf_cache_lru_list.prev = &p_fs->buf_cache_lru_list; - - for (i = 0; i < BUF_CACHE_SIZE; i++) { - p_fs->buf_cache_array[i].drv = -1; - p_fs->buf_cache_array[i].sec = ~0; - p_fs->buf_cache_array[i].flag = 0; - p_fs->buf_cache_array[i].buf_bh = NULL; - p_fs->buf_cache_array[i].prev = NULL; - p_fs->buf_cache_array[i].next = NULL; - push_to_mru(&p_fs->buf_cache_array[i], - &p_fs->buf_cache_lru_list); - } - - /* HASH list */ - for (i = 0; i < FAT_CACHE_HASH_SIZE; i++) { - p_fs->FAT_cache_hash_list[i].drv = -1; - p_fs->FAT_cache_hash_list[i].sec = ~0; - p_fs->FAT_cache_hash_list[i].hash_next = - &p_fs->FAT_cache_hash_list[i]; - p_fs->FAT_cache_hash_list[i].hash_prev = - &p_fs->FAT_cache_hash_list[i]; - } - - for (i = 0; i < FAT_CACHE_SIZE; i++) - FAT_cache_insert_hash(sb, &p_fs->FAT_cache_array[i]); - - for (i = 0; i < BUF_CACHE_HASH_SIZE; i++) { - p_fs->buf_cache_hash_list[i].drv = -1; - p_fs->buf_cache_hash_list[i].sec = ~0; - p_fs->buf_cache_hash_list[i].hash_next = - &p_fs->buf_cache_hash_list[i]; - p_fs->buf_cache_hash_list[i].hash_prev = - &p_fs->buf_cache_hash_list[i]; - } - - for (i = 0; i < BUF_CACHE_SIZE; i++) - buf_cache_insert_hash(sb, &p_fs->buf_cache_array[i]); -} - -void exfat_buf_shutdown(struct super_block *sb) -{ -} - -static int __exfat_fat_read(struct super_block *sb, u32 loc, u32 *content) -{ - s32 off; - u32 _content; - sector_t sec; - u8 *fat_sector, *fat_entry; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - sec = p_fs->FAT1_start_sector + - (loc >> (p_bd->sector_size_bits - 2)); - off = (loc << 2) & p_bd->sector_size_mask; - - fat_sector = exfat_fat_getblk(sb, sec); - if (!fat_sector) - return -1; - - fat_entry = &fat_sector[off]; - _content = GET32_A(fat_entry); - - if (_content >= CLUSTER_32(0xFFFFFFF8)) { - *content = CLUSTER_32(~0); - return 0; - } - *content = CLUSTER_32(_content); - return 0; -} - -/* in : sb, loc - * out: content - * returns 0 on success - * -1 on error - */ -int exfat_fat_read(struct super_block *sb, u32 loc, u32 *content) -{ - s32 ret; - - mutex_lock(&f_mutex); - ret = __exfat_fat_read(sb, loc, content); - mutex_unlock(&f_mutex); - - return ret; -} - -static s32 __exfat_fat_write(struct super_block *sb, u32 loc, u32 content) -{ - s32 off; - sector_t sec; - u8 *fat_sector, *fat_entry; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - sec = p_fs->FAT1_start_sector + (loc >> - (p_bd->sector_size_bits - 2)); - off = (loc << 2) & p_bd->sector_size_mask; - - fat_sector = exfat_fat_getblk(sb, sec); - if (!fat_sector) - return -1; - - fat_entry = &fat_sector[off]; - - SET32_A(fat_entry, content); - - exfat_fat_modify(sb, sec); - return 0; -} - -int exfat_fat_write(struct super_block *sb, u32 loc, u32 content) -{ - s32 ret; - - mutex_lock(&f_mutex); - ret = __exfat_fat_write(sb, loc, content); - mutex_unlock(&f_mutex); - - return ret; -} - -u8 *exfat_fat_getblk(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - bp = FAT_cache_find(sb, sec); - if (bp) { - move_to_mru(bp, &p_fs->FAT_cache_lru_list); - return bp->buf_bh->b_data; - } - - bp = FAT_cache_get(sb, sec); - - FAT_cache_remove_hash(bp); - - bp->drv = p_fs->drv; - bp->sec = sec; - bp->flag = 0; - - FAT_cache_insert_hash(sb, bp); - - if (sector_read(sb, sec, &bp->buf_bh, 1) != 0) { - FAT_cache_remove_hash(bp); - bp->drv = -1; - bp->sec = ~0; - bp->flag = 0; - bp->buf_bh = NULL; - - move_to_lru(bp, &p_fs->FAT_cache_lru_list); - return NULL; - } - - return bp->buf_bh->b_data; -} - -void exfat_fat_modify(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - - bp = FAT_cache_find(sb, sec); - if (bp) - sector_write(sb, sec, bp->buf_bh, 0); -} - -void exfat_fat_release_all(struct super_block *sb) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - mutex_lock(&f_mutex); - - bp = p_fs->FAT_cache_lru_list.next; - while (bp != &p_fs->FAT_cache_lru_list) { - if (bp->drv == p_fs->drv) { - bp->drv = -1; - bp->sec = ~0; - bp->flag = 0; - - if (bp->buf_bh) { - __brelse(bp->buf_bh); - bp->buf_bh = NULL; - } - } - bp = bp->next; - } - - mutex_unlock(&f_mutex); -} - -void exfat_fat_sync(struct super_block *sb) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - mutex_lock(&f_mutex); - - bp = p_fs->FAT_cache_lru_list.next; - while (bp != &p_fs->FAT_cache_lru_list) { - if ((bp->drv == p_fs->drv) && (bp->flag & DIRTYBIT)) { - sync_dirty_buffer(bp->buf_bh); - bp->flag &= ~(DIRTYBIT); - } - bp = bp->next; - } - - mutex_unlock(&f_mutex); -} - -static struct buf_cache_t *buf_cache_find(struct super_block *sb, sector_t sec) -{ - s32 off; - struct buf_cache_t *bp, *hp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - off = (sec + (sec >> p_fs->sectors_per_clu_bits)) & - (BUF_CACHE_HASH_SIZE - 1); - - hp = &p_fs->buf_cache_hash_list[off]; - for (bp = hp->hash_next; bp != hp; bp = bp->hash_next) { - if ((bp->drv == p_fs->drv) && (bp->sec == sec)) { - touch_buffer(bp->buf_bh); - return bp; - } - } - return NULL; -} - -static struct buf_cache_t *buf_cache_get(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - bp = p_fs->buf_cache_lru_list.prev; - while (bp->flag & LOCKBIT) - bp = bp->prev; - - move_to_mru(bp, &p_fs->buf_cache_lru_list); - return bp; -} - -static u8 *__exfat_buf_getblk(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - bp = buf_cache_find(sb, sec); - if (bp) { - move_to_mru(bp, &p_fs->buf_cache_lru_list); - return bp->buf_bh->b_data; - } - - bp = buf_cache_get(sb, sec); - - buf_cache_remove_hash(bp); - - bp->drv = p_fs->drv; - bp->sec = sec; - bp->flag = 0; - - buf_cache_insert_hash(sb, bp); - - if (sector_read(sb, sec, &bp->buf_bh, 1) != 0) { - buf_cache_remove_hash(bp); - bp->drv = -1; - bp->sec = ~0; - bp->flag = 0; - bp->buf_bh = NULL; - - move_to_lru(bp, &p_fs->buf_cache_lru_list); - return NULL; - } - - return bp->buf_bh->b_data; -} - -u8 *exfat_buf_getblk(struct super_block *sb, sector_t sec) -{ - u8 *buf; - - mutex_lock(&b_mutex); - buf = __exfat_buf_getblk(sb, sec); - mutex_unlock(&b_mutex); - - return buf; -} - -void exfat_buf_modify(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - - mutex_lock(&b_mutex); - - bp = buf_cache_find(sb, sec); - if (likely(bp)) - sector_write(sb, sec, bp->buf_bh, 0); - - WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n", - (unsigned long long)sec); - - mutex_unlock(&b_mutex); -} - -void exfat_buf_lock(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - - mutex_lock(&b_mutex); - - bp = buf_cache_find(sb, sec); - if (likely(bp)) - bp->flag |= LOCKBIT; - - WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n", - (unsigned long long)sec); - - mutex_unlock(&b_mutex); -} - -void exfat_buf_unlock(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - - mutex_lock(&b_mutex); - - bp = buf_cache_find(sb, sec); - if (likely(bp)) - bp->flag &= ~(LOCKBIT); - - WARN(!bp, "[EXFAT] failed to find buffer_cache(sector:%llu).\n", - (unsigned long long)sec); - - mutex_unlock(&b_mutex); -} - -void exfat_buf_release(struct super_block *sb, sector_t sec) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - mutex_lock(&b_mutex); - - bp = buf_cache_find(sb, sec); - if (likely(bp)) { - bp->drv = -1; - bp->sec = ~0; - bp->flag = 0; - - if (bp->buf_bh) { - __brelse(bp->buf_bh); - bp->buf_bh = NULL; - } - - move_to_lru(bp, &p_fs->buf_cache_lru_list); - } - - mutex_unlock(&b_mutex); -} - -void exfat_buf_release_all(struct super_block *sb) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - mutex_lock(&b_mutex); - - bp = p_fs->buf_cache_lru_list.next; - while (bp != &p_fs->buf_cache_lru_list) { - if (bp->drv == p_fs->drv) { - bp->drv = -1; - bp->sec = ~0; - bp->flag = 0; - - if (bp->buf_bh) { - __brelse(bp->buf_bh); - bp->buf_bh = NULL; - } - } - bp = bp->next; - } - - mutex_unlock(&b_mutex); -} - -void exfat_buf_sync(struct super_block *sb) -{ - struct buf_cache_t *bp; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - mutex_lock(&b_mutex); - - bp = p_fs->buf_cache_lru_list.next; - while (bp != &p_fs->buf_cache_lru_list) { - if ((bp->drv == p_fs->drv) && (bp->flag & DIRTYBIT)) { - sync_dirty_buffer(bp->buf_bh); - bp->flag &= ~(DIRTYBIT); - } - bp = bp->next; - } - - mutex_unlock(&b_mutex); -} diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c deleted file mode 100644 index 07b460d01334..000000000000 --- a/drivers/staging/exfat/exfat_core.c +++ /dev/null @@ -1,2582 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/types.h> -#include <linux/buffer_head.h> -#include <linux/fs.h> -#include <linux/mutex.h> -#include <linux/blkdev.h> -#include <linux/slab.h> -#include "exfat.h" - -static void __set_sb_dirty(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - sbi->s_dirt = 1; -} - -static u8 name_buf[MAX_PATH_LENGTH * MAX_CHARSET_SIZE]; - -static u8 free_bit[] = { - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 0 ~ 19 */ - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, /* 20 ~ 39 */ - 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 40 ~ 59 */ - 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, /* 60 ~ 79 */ - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, 0, 1, 0, 2, /* 80 ~ 99 */ - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, /* 100 ~ 119 */ - 0, 1, 0, 2, 0, 1, 0, 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 120 ~ 139 */ - 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 5, /* 140 ~ 159 */ - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, /* 160 ~ 179 */ - 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 6, 0, 1, 0, 2, 0, 1, 0, 3, /* 180 ~ 199 */ - 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, /* 200 ~ 219 */ - 0, 1, 0, 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, /* 220 ~ 239 */ - 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 /* 240 ~ 254 */ -}; - -static u8 used_bit[] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, /* 0 ~ 19 */ - 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, /* 20 ~ 39 */ - 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, /* 40 ~ 59 */ - 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, /* 60 ~ 79 */ - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, /* 80 ~ 99 */ - 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, /* 100 ~ 119 */ - 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, /* 120 ~ 139 */ - 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, /* 140 ~ 159 */ - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, /* 160 ~ 179 */ - 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, /* 180 ~ 199 */ - 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, /* 200 ~ 219 */ - 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, /* 220 ~ 239 */ - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 /* 240 ~ 255 */ -}; - -#define BITMAP_LOC(v) ((v) >> 3) -#define BITMAP_SHIFT(v) ((v) & 0x07) - -static inline s32 exfat_bitmap_test(u8 *bitmap, int i) -{ - u8 data; - - data = bitmap[BITMAP_LOC(i)]; - if ((data >> BITMAP_SHIFT(i)) & 0x01) - return 1; - return 0; -} - -static inline void exfat_bitmap_set(u8 *bitmap, int i) -{ - bitmap[BITMAP_LOC(i)] |= (0x01 << BITMAP_SHIFT(i)); -} - -static inline void exfat_bitmap_clear(u8 *bitmap, int i) -{ - bitmap[BITMAP_LOC(i)] &= ~(0x01 << BITMAP_SHIFT(i)); -} - -/* - * File System Management Functions - */ - -void fs_set_vol_flags(struct super_block *sb, u32 new_flag) -{ - struct pbr_sector_t *p_pbr; - struct bpbex_t *p_bpb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (p_fs->vol_flag == new_flag) - return; - - p_fs->vol_flag = new_flag; - - if (!p_fs->pbr_bh) { - if (sector_read(sb, p_fs->PBR_sector, - &p_fs->pbr_bh, 1) != 0) - return; - } - - p_pbr = (struct pbr_sector_t *)p_fs->pbr_bh->b_data; - p_bpb = (struct bpbex_t *)p_pbr->bpb; - SET16(p_bpb->vol_flags, (u16)new_flag); - - /* XXX duyoung - * what can we do here? (cuz fs_set_vol_flags() is void) - */ - if ((new_flag == VOL_DIRTY) && (!buffer_dirty(p_fs->pbr_bh))) - sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 1); - else - sector_write(sb, p_fs->PBR_sector, p_fs->pbr_bh, 0); -} - -void fs_error(struct super_block *sb) -{ - struct exfat_mount_options *opts = &EXFAT_SB(sb)->options; - - if (opts->errors == EXFAT_ERRORS_PANIC) { - panic("[EXFAT] Filesystem panic from previous error\n"); - } else if ((opts->errors == EXFAT_ERRORS_RO) && !sb_rdonly(sb)) { - sb->s_flags |= SB_RDONLY; - pr_err("[EXFAT] Filesystem has been set read-only\n"); - } -} - -/* - * Cluster Management Functions - */ - -static s32 clear_cluster(struct super_block *sb, u32 clu) -{ - sector_t s, n; - s32 ret = 0; - struct buffer_head *tmp_bh = NULL; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - if (clu == CLUSTER_32(0)) { /* FAT16 root_dir */ - s = p_fs->root_start_sector; - n = p_fs->data_start_sector; - } else { - s = START_SECTOR(clu); - n = s + p_fs->sectors_per_clu; - } - - for (; s < n; s++) { - ret = sector_read(sb, s, &tmp_bh, 0); - if (ret != 0) - return ret; - - memset((char *)tmp_bh->b_data, 0x0, p_bd->sector_size); - ret = sector_write(sb, s, tmp_bh, 0); - if (ret != 0) - break; - } - - brelse(tmp_bh); - return ret; -} - -static s32 set_alloc_bitmap(struct super_block *sb, u32 clu) -{ - int i, b; - sector_t sector; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - i = clu >> (p_bd->sector_size_bits + 3); - b = clu & ((p_bd->sector_size << 3) - 1); - - sector = START_SECTOR(p_fs->map_clu) + i; - - exfat_bitmap_set((u8 *)p_fs->vol_amap[i]->b_data, b); - - return sector_write(sb, sector, p_fs->vol_amap[i], 0); -} - -static s32 clr_alloc_bitmap(struct super_block *sb, u32 clu) -{ - int i, b; - sector_t sector; -#ifdef CONFIG_STAGING_EXFAT_DISCARD - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct exfat_mount_options *opts = &sbi->options; - int ret; -#endif /* CONFIG_STAGING_EXFAT_DISCARD */ - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - i = clu >> (p_bd->sector_size_bits + 3); - b = clu & ((p_bd->sector_size << 3) - 1); - - sector = START_SECTOR(p_fs->map_clu) + i; - - exfat_bitmap_clear((u8 *)p_fs->vol_amap[i]->b_data, b); - -#ifdef CONFIG_STAGING_EXFAT_DISCARD - if (opts->discard) { - ret = sb_issue_discard(sb, START_SECTOR(clu), - (1 << p_fs->sectors_per_clu_bits), - GFP_NOFS, 0); - if (ret == -EOPNOTSUPP) { - pr_warn("discard not supported by device, disabling"); - opts->discard = 0; - } else { - return ret; - } - } -#endif /* CONFIG_STAGING_EXFAT_DISCARD */ - - return sector_write(sb, sector, p_fs->vol_amap[i], 0); -} - -static u32 test_alloc_bitmap(struct super_block *sb, u32 clu) -{ - int i, map_i, map_b; - u32 clu_base, clu_free; - u8 k, clu_mask; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - clu_base = (clu & ~(0x7)) + 2; - clu_mask = (1 << (clu - clu_base + 2)) - 1; - - map_i = clu >> (p_bd->sector_size_bits + 3); - map_b = (clu >> 3) & p_bd->sector_size_mask; - - for (i = 2; i < p_fs->num_clusters; i += 8) { - k = *(((u8 *)p_fs->vol_amap[map_i]->b_data) + map_b); - if (clu_mask > 0) { - k |= clu_mask; - clu_mask = 0; - } - if (k < 0xFF) { - clu_free = clu_base + free_bit[k]; - if (clu_free < p_fs->num_clusters) - return clu_free; - } - clu_base += 8; - - if (((++map_b) >= p_bd->sector_size) || - (clu_base >= p_fs->num_clusters)) { - if ((++map_i) >= p_fs->map_sectors) { - clu_base = 2; - map_i = 0; - } - map_b = 0; - } - } - - return CLUSTER_32(~0); -} - -s32 exfat_alloc_cluster(struct super_block *sb, s32 num_alloc, - struct chain_t *p_chain) -{ - s32 num_clusters = 0; - u32 hint_clu, new_clu, last_clu = CLUSTER_32(~0); - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - hint_clu = p_chain->dir; - if (hint_clu == CLUSTER_32(~0)) { - hint_clu = test_alloc_bitmap(sb, p_fs->clu_srch_ptr - 2); - if (hint_clu == CLUSTER_32(~0)) - return 0; - } else if (hint_clu >= p_fs->num_clusters) { - hint_clu = 2; - p_chain->flags = 0x01; - } - - __set_sb_dirty(sb); - - p_chain->dir = CLUSTER_32(~0); - - while ((new_clu = test_alloc_bitmap(sb, hint_clu - 2)) != CLUSTER_32(~0)) { - if (new_clu != hint_clu) { - if (p_chain->flags == 0x03) { - exfat_chain_cont_cluster(sb, p_chain->dir, - num_clusters); - p_chain->flags = 0x01; - } - } - - if (set_alloc_bitmap(sb, new_clu - 2) != 0) - return -EIO; - - num_clusters++; - - if (p_chain->flags == 0x01) { - if (exfat_fat_write(sb, new_clu, CLUSTER_32(~0)) < 0) - return -EIO; - } - - if (p_chain->dir == CLUSTER_32(~0)) { - p_chain->dir = new_clu; - } else { - if (p_chain->flags == 0x01) { - if (exfat_fat_write(sb, last_clu, new_clu) < 0) - return -EIO; - } - } - last_clu = new_clu; - - if ((--num_alloc) == 0) { - p_fs->clu_srch_ptr = hint_clu; - if (p_fs->used_clusters != UINT_MAX) - p_fs->used_clusters += num_clusters; - - p_chain->size += num_clusters; - return num_clusters; - } - - hint_clu = new_clu + 1; - if (hint_clu >= p_fs->num_clusters) { - hint_clu = 2; - - if (p_chain->flags == 0x03) { - exfat_chain_cont_cluster(sb, p_chain->dir, - num_clusters); - p_chain->flags = 0x01; - } - } - } - - p_fs->clu_srch_ptr = hint_clu; - if (p_fs->used_clusters != UINT_MAX) - p_fs->used_clusters += num_clusters; - - p_chain->size += num_clusters; - return num_clusters; -} - -void exfat_free_cluster(struct super_block *sb, struct chain_t *p_chain, - s32 do_relse) -{ - s32 num_clusters = 0; - u32 clu; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - int i; - sector_t sector; - - if ((p_chain->dir == CLUSTER_32(0)) || (p_chain->dir == CLUSTER_32(~0))) - return; - - if (p_chain->size <= 0) { - pr_err("[EXFAT] free_cluster : skip free-req clu:%u, because of zero-size truncation\n", - p_chain->dir); - return; - } - - __set_sb_dirty(sb); - clu = p_chain->dir; - - if (p_chain->flags == 0x03) { - do { - if (do_relse) { - sector = START_SECTOR(clu); - for (i = 0; i < p_fs->sectors_per_clu; i++) - exfat_buf_release(sb, sector + i); - } - - if (clr_alloc_bitmap(sb, clu - 2) != 0) - break; - clu++; - - num_clusters++; - } while (num_clusters < p_chain->size); - } else { - do { - if (p_fs->dev_ejected) - break; - - if (do_relse) { - sector = START_SECTOR(clu); - for (i = 0; i < p_fs->sectors_per_clu; i++) - exfat_buf_release(sb, sector + i); - } - - if (clr_alloc_bitmap(sb, clu - 2) != 0) - break; - - if (exfat_fat_read(sb, clu, &clu) == -1) - break; - num_clusters++; - } while ((clu != CLUSTER_32(0)) && (clu != CLUSTER_32(~0))); - } - - if (p_fs->used_clusters != UINT_MAX) - p_fs->used_clusters -= num_clusters; -} - -static u32 find_last_cluster(struct super_block *sb, struct chain_t *p_chain) -{ - u32 clu, next; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - clu = p_chain->dir; - - if (p_chain->flags == 0x03) { - clu += p_chain->size - 1; - } else { - while ((exfat_fat_read(sb, clu, &next) == 0) && - (next != CLUSTER_32(~0))) { - if (p_fs->dev_ejected) - break; - clu = next; - } - } - - return clu; -} - -s32 count_num_clusters(struct super_block *sb, struct chain_t *p_chain) -{ - int i, count = 0; - u32 clu; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if ((p_chain->dir == CLUSTER_32(0)) || (p_chain->dir == CLUSTER_32(~0))) - return 0; - - clu = p_chain->dir; - - if (p_chain->flags == 0x03) { - count = p_chain->size; - } else { - for (i = 2; i < p_fs->num_clusters; i++) { - count++; - if (exfat_fat_read(sb, clu, &clu) != 0) - return 0; - if (clu == CLUSTER_32(~0)) - break; - } - } - - return count; -} - -s32 exfat_count_used_clusters(struct super_block *sb) -{ - int i, map_i, map_b, count = 0; - u8 k; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - map_i = 0; - map_b = 0; - - for (i = 2; i < p_fs->num_clusters; i += 8) { - k = *(((u8 *)p_fs->vol_amap[map_i]->b_data) + map_b); - count += used_bit[k]; - - if ((++map_b) >= p_bd->sector_size) { - map_i++; - map_b = 0; - } - } - - return count; -} - -void exfat_chain_cont_cluster(struct super_block *sb, u32 chain, s32 len) -{ - if (len == 0) - return; - - while (len > 1) { - if (exfat_fat_write(sb, chain, chain + 1) < 0) - break; - chain++; - len--; - } - exfat_fat_write(sb, chain, CLUSTER_32(~0)); -} - -/* - * Allocation Bitmap Management Functions - */ - -s32 load_alloc_bitmap(struct super_block *sb) -{ - int i, j, ret; - u32 map_size; - u32 type; - sector_t sector; - struct chain_t clu; - struct bmap_dentry_t *ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - clu.dir = p_fs->root_dir; - clu.flags = 0x01; - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - for (i = 0; i < p_fs->dentries_per_clu; i++) { - ep = (struct bmap_dentry_t *)get_entry_in_dir(sb, &clu, - i, NULL); - if (!ep) - return -ENOENT; - - type = exfat_get_entry_type((struct dentry_t *)ep); - - if (type == TYPE_UNUSED) - break; - if (type != TYPE_BITMAP) - continue; - - if (ep->flags == 0x0) { - p_fs->map_clu = GET32_A(ep->start_clu); - map_size = (u32)GET64_A(ep->size); - - p_fs->map_sectors = ((map_size - 1) >> p_bd->sector_size_bits) + 1; - - p_fs->vol_amap = kmalloc_array(p_fs->map_sectors, - sizeof(struct buffer_head *), - GFP_KERNEL); - if (!p_fs->vol_amap) - return -ENOMEM; - - sector = START_SECTOR(p_fs->map_clu); - - for (j = 0; j < p_fs->map_sectors; j++) { - p_fs->vol_amap[j] = NULL; - ret = sector_read(sb, sector + j, &p_fs->vol_amap[j], 1); - if (ret != 0) { - /* release all buffers and free vol_amap */ - i = 0; - while (i < j) - brelse(p_fs->vol_amap[i++]); - - kfree(p_fs->vol_amap); - p_fs->vol_amap = NULL; - return ret; - } - } - - p_fs->pbr_bh = NULL; - return 0; - } - } - - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - return -EIO; - } - - return -EFSCORRUPTED; -} - -void free_alloc_bitmap(struct super_block *sb) -{ - int i; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - brelse(p_fs->pbr_bh); - - for (i = 0; i < p_fs->map_sectors; i++) - __brelse(p_fs->vol_amap[i]); - - kfree(p_fs->vol_amap); - p_fs->vol_amap = NULL; -} - -void sync_alloc_bitmap(struct super_block *sb) -{ - int i; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (!p_fs->vol_amap) - return; - - for (i = 0; i < p_fs->map_sectors; i++) - sync_dirty_buffer(p_fs->vol_amap[i]); -} - -/* - * Upcase table Management Functions - */ -static s32 __load_upcase_table(struct super_block *sb, sector_t sector, - u32 num_sectors, u32 utbl_checksum) -{ - int i, ret = -EINVAL; - u32 j; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - struct buffer_head *tmp_bh = NULL; - sector_t end_sector = num_sectors + sector; - - bool skip = false; - u32 index = 0; - u16 uni = 0; - u16 **upcase_table; - - u32 checksum = 0; - - upcase_table = kmalloc_array(UTBL_COL_COUNT, sizeof(u16 *), GFP_KERNEL); - p_fs->vol_utbl = upcase_table; - if (!upcase_table) - return -ENOMEM; - memset(upcase_table, 0, UTBL_COL_COUNT * sizeof(u16 *)); - - while (sector < end_sector) { - ret = sector_read(sb, sector, &tmp_bh, 1); - if (ret != 0) { - pr_debug("sector read (0x%llX)fail\n", - (unsigned long long)sector); - goto error; - } - sector++; - - for (i = 0; i < p_bd->sector_size && index <= 0xFFFF; i += 2) { - uni = GET16(((u8 *)tmp_bh->b_data) + i); - - checksum = ((checksum & 1) ? 0x80000000 : 0) + - (checksum >> 1) + *(((u8 *)tmp_bh->b_data) + - i); - checksum = ((checksum & 1) ? 0x80000000 : 0) + - (checksum >> 1) + *(((u8 *)tmp_bh->b_data) + - (i + 1)); - - if (skip) { - pr_debug("skip from 0x%X ", index); - index += uni; - pr_debug("to 0x%X (amount of 0x%X)\n", - index, uni); - skip = false; - } else if (uni == index) { - index++; - } else if (uni == 0xFFFF) { - skip = true; - } else { /* uni != index , uni != 0xFFFF */ - u16 col_index = get_col_index(index); - - if (!upcase_table[col_index]) { - pr_debug("alloc = 0x%X\n", col_index); - upcase_table[col_index] = kmalloc_array(UTBL_ROW_COUNT, - sizeof(u16), GFP_KERNEL); - if (!upcase_table[col_index]) { - ret = -ENOMEM; - goto error; - } - - for (j = 0; j < UTBL_ROW_COUNT; j++) - upcase_table[col_index][j] = (col_index << LOW_INDEX_BIT) | j; - } - - upcase_table[col_index][get_row_index(index)] = uni; - index++; - } - } - } - if (index >= 0xFFFF && utbl_checksum == checksum) { - if (tmp_bh) - brelse(tmp_bh); - return 0; - } - ret = -EINVAL; -error: - if (tmp_bh) - brelse(tmp_bh); - free_upcase_table(sb); - return ret; -} - -static s32 __load_default_upcase_table(struct super_block *sb) -{ - int i, ret = -EINVAL; - u32 j; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - bool skip = false; - u32 index = 0; - u16 uni = 0; - u16 **upcase_table; - - upcase_table = kmalloc_array(UTBL_COL_COUNT, sizeof(u16 *), GFP_KERNEL); - p_fs->vol_utbl = upcase_table; - if (!upcase_table) - return -ENOMEM; - memset(upcase_table, 0, UTBL_COL_COUNT * sizeof(u16 *)); - - for (i = 0; index <= 0xFFFF && i < NUM_UPCASE * 2; i += 2) { - uni = GET16(uni_upcase + i); - if (skip) { - pr_debug("skip from 0x%X ", index); - index += uni; - pr_debug("to 0x%X (amount of 0x%X)\n", index, uni); - skip = false; - } else if (uni == index) { - index++; - } else if (uni == 0xFFFF) { - skip = true; - } else { /* uni != index , uni != 0xFFFF */ - u16 col_index = get_col_index(index); - - if (!upcase_table[col_index]) { - pr_debug("alloc = 0x%X\n", col_index); - upcase_table[col_index] = kmalloc_array(UTBL_ROW_COUNT, - sizeof(u16), - GFP_KERNEL); - if (!upcase_table[col_index]) { - ret = -ENOMEM; - goto error; - } - - for (j = 0; j < UTBL_ROW_COUNT; j++) - upcase_table[col_index][j] = (col_index << LOW_INDEX_BIT) | j; - } - - upcase_table[col_index][get_row_index(index)] = uni; - index++; - } - } - - if (index >= 0xFFFF) - return 0; - -error: - /* FATAL error: default upcase table has error */ - free_upcase_table(sb); - return ret; -} - -s32 load_upcase_table(struct super_block *sb) -{ - int i; - u32 tbl_clu, tbl_size; - sector_t sector; - u32 type, num_sectors; - struct chain_t clu; - struct case_dentry_t *ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - clu.dir = p_fs->root_dir; - clu.flags = 0x01; - - if (p_fs->dev_ejected) - return -EIO; - - while (clu.dir != CLUSTER_32(~0)) { - for (i = 0; i < p_fs->dentries_per_clu; i++) { - ep = (struct case_dentry_t *)get_entry_in_dir(sb, &clu, - i, NULL); - if (!ep) - return -ENOENT; - - type = exfat_get_entry_type((struct dentry_t *)ep); - - if (type == TYPE_UNUSED) - break; - if (type != TYPE_UPCASE) - continue; - - tbl_clu = GET32_A(ep->start_clu); - tbl_size = (u32)GET64_A(ep->size); - - sector = START_SECTOR(tbl_clu); - num_sectors = ((tbl_size - 1) >> p_bd->sector_size_bits) + 1; - if (__load_upcase_table(sb, sector, num_sectors, - GET32_A(ep->checksum)) != 0) - break; - return 0; - } - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - return -EIO; - } - /* load default upcase table */ - return __load_default_upcase_table(sb); -} - -void free_upcase_table(struct super_block *sb) -{ - u32 i; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - u16 **upcase_table; - - upcase_table = p_fs->vol_utbl; - for (i = 0; i < UTBL_COL_COUNT; i++) - kfree(upcase_table[i]); - - kfree(p_fs->vol_utbl); - p_fs->vol_utbl = NULL; -} - -/* - * Directory Entry Management Functions - */ - -u32 exfat_get_entry_type(struct dentry_t *p_entry) -{ - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - if (ep->type == 0x0) { - return TYPE_UNUSED; - } else if (ep->type < 0x80) { - return TYPE_DELETED; - } else if (ep->type == 0x80) { - return TYPE_INVALID; - } else if (ep->type < 0xA0) { - if (ep->type == 0x81) { - return TYPE_BITMAP; - } else if (ep->type == 0x82) { - return TYPE_UPCASE; - } else if (ep->type == 0x83) { - return TYPE_VOLUME; - } else if (ep->type == 0x85) { - if (GET16_A(ep->attr) & ATTR_SUBDIR) - return TYPE_DIR; - else - return TYPE_FILE; - } - return TYPE_CRITICAL_PRI; - } else if (ep->type < 0xC0) { - if (ep->type == 0xA0) - return TYPE_GUID; - else if (ep->type == 0xA1) - return TYPE_PADDING; - else if (ep->type == 0xA2) - return TYPE_ACLTAB; - return TYPE_BENIGN_PRI; - } else if (ep->type < 0xE0) { - if (ep->type == 0xC0) - return TYPE_STREAM; - else if (ep->type == 0xC1) - return TYPE_EXTEND; - else if (ep->type == 0xC2) - return TYPE_ACL; - return TYPE_CRITICAL_SEC; - } - - return TYPE_BENIGN_SEC; -} - -static void exfat_set_entry_type(struct dentry_t *p_entry, u32 type) -{ - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - if (type == TYPE_UNUSED) { - ep->type = 0x0; - } else if (type == TYPE_DELETED) { - ep->type &= ~0x80; - } else if (type == TYPE_STREAM) { - ep->type = 0xC0; - } else if (type == TYPE_EXTEND) { - ep->type = 0xC1; - } else if (type == TYPE_BITMAP) { - ep->type = 0x81; - } else if (type == TYPE_UPCASE) { - ep->type = 0x82; - } else if (type == TYPE_VOLUME) { - ep->type = 0x83; - } else if (type == TYPE_DIR) { - ep->type = 0x85; - SET16_A(ep->attr, ATTR_SUBDIR); - } else if (type == TYPE_FILE) { - ep->type = 0x85; - SET16_A(ep->attr, ATTR_ARCHIVE); - } else if (type == TYPE_SYMLINK) { - ep->type = 0x85; - SET16_A(ep->attr, ATTR_ARCHIVE | ATTR_SYMLINK); - } -} - -u32 exfat_get_entry_attr(struct dentry_t *p_entry) -{ - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - return (u32)GET16_A(ep->attr); -} - -void exfat_set_entry_attr(struct dentry_t *p_entry, u32 attr) -{ - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - SET16_A(ep->attr, (u16)attr); -} - -u8 exfat_get_entry_flag(struct dentry_t *p_entry) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - return ep->flags; -} - -void exfat_set_entry_flag(struct dentry_t *p_entry, u8 flags) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - ep->flags = flags; -} - -u32 exfat_get_entry_clu0(struct dentry_t *p_entry) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - return GET32_A(ep->start_clu); -} - -void exfat_set_entry_clu0(struct dentry_t *p_entry, u32 start_clu) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - SET32_A(ep->start_clu, start_clu); -} - -u64 exfat_get_entry_size(struct dentry_t *p_entry) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - return GET64_A(ep->valid_size); -} - -void exfat_set_entry_size(struct dentry_t *p_entry, u64 size) -{ - struct strm_dentry_t *ep = (struct strm_dentry_t *)p_entry; - - SET64_A(ep->valid_size, size); - SET64_A(ep->size, size); -} - -void exfat_get_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp, - u8 mode) -{ - u16 t = 0x00, d = 0x21; - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - switch (mode) { - case TM_CREATE: - t = GET16_A(ep->create_time); - d = GET16_A(ep->create_date); - break; - case TM_MODIFY: - t = GET16_A(ep->modify_time); - d = GET16_A(ep->modify_date); - break; - case TM_ACCESS: - t = GET16_A(ep->access_time); - d = GET16_A(ep->access_date); - break; - } - - tp->sec = (t & 0x001F) << 1; - tp->min = (t >> 5) & 0x003F; - tp->hour = (t >> 11); - tp->day = (d & 0x001F); - tp->mon = (d >> 5) & 0x000F; - tp->year = (d >> 9); -} - -void exfat_set_entry_time(struct dentry_t *p_entry, struct timestamp_t *tp, - u8 mode) -{ - u16 t, d; - struct file_dentry_t *ep = (struct file_dentry_t *)p_entry; - - t = (tp->hour << 11) | (tp->min << 5) | (tp->sec >> 1); - d = (tp->year << 9) | (tp->mon << 5) | tp->day; - - switch (mode) { - case TM_CREATE: - SET16_A(ep->create_time, t); - SET16_A(ep->create_date, d); - break; - case TM_MODIFY: - SET16_A(ep->modify_time, t); - SET16_A(ep->modify_date, d); - break; - case TM_ACCESS: - SET16_A(ep->access_time, t); - SET16_A(ep->access_date, d); - break; - } -} - -static void init_file_entry(struct file_dentry_t *ep, u32 type) -{ - struct timestamp_t tm, *tp; - - exfat_set_entry_type((struct dentry_t *)ep, type); - - tp = tm_current(&tm); - exfat_set_entry_time((struct dentry_t *)ep, tp, TM_CREATE); - exfat_set_entry_time((struct dentry_t *)ep, tp, TM_MODIFY); - exfat_set_entry_time((struct dentry_t *)ep, tp, TM_ACCESS); - ep->create_time_ms = 0; - ep->modify_time_ms = 0; - ep->access_time_ms = 0; -} - -static void init_strm_entry(struct strm_dentry_t *ep, u8 flags, u32 start_clu, u64 size) -{ - exfat_set_entry_type((struct dentry_t *)ep, TYPE_STREAM); - ep->flags = flags; - SET32_A(ep->start_clu, start_clu); - SET64_A(ep->valid_size, size); - SET64_A(ep->size, size); -} - -static void init_name_entry(struct name_dentry_t *ep, u16 *uniname) -{ - int i; - - exfat_set_entry_type((struct dentry_t *)ep, TYPE_EXTEND); - ep->flags = 0x0; - - for (i = 0; i < 30; i++, i++) { - SET16_A(ep->unicode_0_14 + i, *uniname); - if (*uniname == 0x0) - break; - uniname++; - } -} - -static s32 exfat_init_dir_entry(struct super_block *sb, struct chain_t *p_dir, - s32 entry, u32 type, u32 start_clu, u64 size) -{ - sector_t sector; - u8 flags; - struct file_dentry_t *file_ep; - struct strm_dentry_t *strm_ep; - - flags = (type == TYPE_FILE) ? 0x01 : 0x03; - - /* we cannot use get_entry_set_in_dir here because file ep is not initialized yet */ - file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry, - §or); - if (!file_ep) - return -ENOENT; - - strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1, - §or); - if (!strm_ep) - return -ENOENT; - - init_file_entry(file_ep, type); - exfat_buf_modify(sb, sector); - - init_strm_entry(strm_ep, flags, start_clu, size); - exfat_buf_modify(sb, sector); - - return 0; -} - -static s32 exfat_init_ext_entry(struct super_block *sb, struct chain_t *p_dir, - s32 entry, s32 num_entries, - struct uni_name_t *p_uniname, - struct dos_name_t *p_dosname) -{ - int i; - sector_t sector; - u16 *uniname = p_uniname->name; - struct file_dentry_t *file_ep; - struct strm_dentry_t *strm_ep; - struct name_dentry_t *name_ep; - - file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry, - §or); - if (!file_ep) - return -ENOENT; - - file_ep->num_ext = (u8)(num_entries - 1); - exfat_buf_modify(sb, sector); - - strm_ep = (struct strm_dentry_t *)get_entry_in_dir(sb, p_dir, entry + 1, - §or); - if (!strm_ep) - return -ENOENT; - - strm_ep->name_len = p_uniname->name_len; - SET16_A(strm_ep->name_hash, p_uniname->name_hash); - exfat_buf_modify(sb, sector); - - for (i = 2; i < num_entries; i++) { - name_ep = (struct name_dentry_t *)get_entry_in_dir(sb, p_dir, - entry + i, - §or); - if (!name_ep) - return -ENOENT; - - init_name_entry(name_ep, uniname); - exfat_buf_modify(sb, sector); - uniname += 15; - } - - update_dir_checksum(sb, p_dir, entry); - - return 0; -} - -void exfat_delete_dir_entry(struct super_block *sb, struct chain_t *p_dir, - s32 entry, s32 order, s32 num_entries) -{ - int i; - sector_t sector; - struct dentry_t *ep; - - for (i = order; i < num_entries; i++) { - ep = get_entry_in_dir(sb, p_dir, entry + i, §or); - if (!ep) - return; - - exfat_set_entry_type(ep, TYPE_DELETED); - exfat_buf_modify(sb, sector); - } -} - -void update_dir_checksum(struct super_block *sb, struct chain_t *p_dir, - s32 entry) -{ - int i, num_entries; - sector_t sector; - u16 chksum; - struct file_dentry_t *file_ep; - struct dentry_t *ep; - - file_ep = (struct file_dentry_t *)get_entry_in_dir(sb, p_dir, entry, - §or); - if (!file_ep) - return; - - exfat_buf_lock(sb, sector); - - num_entries = (s32)file_ep->num_ext + 1; - chksum = calc_checksum_2byte((void *)file_ep, DENTRY_SIZE, 0, - CS_DIR_ENTRY); - - for (i = 1; i < num_entries; i++) { - ep = get_entry_in_dir(sb, p_dir, entry + i, NULL); - if (!ep) { - exfat_buf_unlock(sb, sector); - return; - } - - chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum, - CS_DEFAULT); - } - - SET16_A(file_ep->checksum, chksum); - exfat_buf_modify(sb, sector); - exfat_buf_unlock(sb, sector); -} - -static s32 __write_partial_entries_in_entry_set(struct super_block *sb, - struct entry_set_cache_t *es, - sector_t sec, s32 off, u32 count) -{ - s32 num_entries, buf_off = (off - es->offset); - u32 remaining_byte_in_sector, copy_entries; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - u32 clu; - u8 *buf, *esbuf = (u8 *)&es->__buf; - - pr_debug("%s entered es %p sec %llu off %d count %d\n", - __func__, es, (unsigned long long)sec, off, count); - num_entries = count; - - while (num_entries) { - /* white per sector base */ - remaining_byte_in_sector = (1 << p_bd->sector_size_bits) - off; - copy_entries = min_t(s32, - remaining_byte_in_sector >> DENTRY_SIZE_BITS, - num_entries); - buf = exfat_buf_getblk(sb, sec); - if (!buf) - goto err_out; - pr_debug("es->buf %p buf_off %u\n", esbuf, buf_off); - pr_debug("copying %d entries from %p to sector %llu\n", - copy_entries, (esbuf + buf_off), - (unsigned long long)sec); - memcpy(buf + off, esbuf + buf_off, - copy_entries << DENTRY_SIZE_BITS); - exfat_buf_modify(sb, sec); - num_entries -= copy_entries; - - if (num_entries) { - /* get next sector */ - if (IS_LAST_SECTOR_IN_CLUSTER(sec)) { - clu = GET_CLUSTER_FROM_SECTOR(sec); - if (es->alloc_flag == 0x03) { - clu++; - } else { - if (exfat_fat_read(sb, clu, &clu) == -1) - goto err_out; - } - sec = START_SECTOR(clu); - } else { - sec++; - } - off = 0; - buf_off += copy_entries << DENTRY_SIZE_BITS; - } - } - - pr_debug("%s exited successfully\n", __func__); - return 0; -err_out: - pr_debug("%s failed\n", __func__); - return -EINVAL; -} - -/* write back all entries in entry set */ -static s32 write_whole_entry_set(struct super_block *sb, struct entry_set_cache_t *es) -{ - return __write_partial_entries_in_entry_set(sb, es, es->sector, - es->offset, - es->num_entries); -} - -void update_dir_checksum_with_entry_set(struct super_block *sb, - struct entry_set_cache_t *es) -{ - struct dentry_t *ep; - u16 chksum = 0; - s32 chksum_type = CS_DIR_ENTRY, i; - - ep = (struct dentry_t *)&es->__buf; - for (i = 0; i < es->num_entries; i++) { - pr_debug("%s ep %p\n", __func__, ep); - chksum = calc_checksum_2byte((void *)ep, DENTRY_SIZE, chksum, - chksum_type); - ep++; - chksum_type = CS_DEFAULT; - } - - ep = (struct dentry_t *)&es->__buf; - SET16_A(((struct file_dentry_t *)ep)->checksum, chksum); - write_whole_entry_set(sb, es); -} - -static s32 _walk_fat_chain(struct super_block *sb, struct chain_t *p_dir, - s32 byte_offset, u32 *clu) -{ - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - s32 clu_offset; - u32 cur_clu; - - clu_offset = byte_offset >> p_fs->cluster_size_bits; - cur_clu = p_dir->dir; - - if (p_dir->flags == 0x03) { - cur_clu += clu_offset; - } else { - while (clu_offset > 0) { - if (exfat_fat_read(sb, cur_clu, &cur_clu) == -1) - return -EIO; - clu_offset--; - } - } - - if (clu) - *clu = cur_clu; - return 0; -} - -static s32 find_location(struct super_block *sb, struct chain_t *p_dir, s32 entry, - sector_t *sector, s32 *offset) -{ - s32 off, ret; - u32 clu = 0; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - off = entry << DENTRY_SIZE_BITS; - - if (p_dir->dir == CLUSTER_32(0)) { /* FAT16 root_dir */ - *offset = off & p_bd->sector_size_mask; - *sector = off >> p_bd->sector_size_bits; - *sector += p_fs->root_start_sector; - } else { - ret = _walk_fat_chain(sb, p_dir, off, &clu); - if (ret != 0) - return ret; - - /* byte offset in cluster */ - off &= p_fs->cluster_size - 1; - - /* byte offset in sector */ - *offset = off & p_bd->sector_size_mask; - - /* sector offset in cluster */ - *sector = off >> p_bd->sector_size_bits; - *sector += START_SECTOR(clu); - } - return 0; -} - -struct dentry_t *get_entry_in_dir(struct super_block *sb, struct chain_t *p_dir, - s32 entry, sector_t *sector) -{ - s32 off; - sector_t sec; - u8 *buf; - - if (find_location(sb, p_dir, entry, &sec, &off) != 0) - return NULL; - - buf = exfat_buf_getblk(sb, sec); - - if (!buf) - return NULL; - - if (sector) - *sector = sec; - return (struct dentry_t *)(buf + off); -} - -/* returns a set of dentries for a file or dir. - * Note that this is a copy (dump) of dentries so that user should call write_entry_set() - * to apply changes made in this entry set to the real device. - * in: - * sb+p_dir+entry: indicates a file/dir - * type: specifies how many dentries should be included. - * out: - * file_ep: will point the first dentry(= file dentry) on success - * return: - * pointer of entry set on success, - * NULL on failure. - */ - -#define ES_MODE_STARTED 0 -#define ES_MODE_GET_FILE_ENTRY 1 -#define ES_MODE_GET_STRM_ENTRY 2 -#define ES_MODE_GET_NAME_ENTRY 3 -#define ES_MODE_GET_CRITICAL_SEC_ENTRY 4 -struct entry_set_cache_t *get_entry_set_in_dir(struct super_block *sb, - struct chain_t *p_dir, s32 entry, - u32 type, - struct dentry_t **file_ep) -{ - s32 off, ret, byte_offset; - u32 clu = 0; - sector_t sec; - u32 entry_type; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - struct entry_set_cache_t *es = NULL; - struct dentry_t *ep, *pos; - u8 *buf; - u8 num_entries; - s32 mode = ES_MODE_STARTED; - size_t bufsize; - - pr_debug("%s entered p_dir dir %u flags %x size %d\n", - __func__, p_dir->dir, p_dir->flags, p_dir->size); - - byte_offset = entry << DENTRY_SIZE_BITS; - ret = _walk_fat_chain(sb, p_dir, byte_offset, &clu); - if (ret != 0) - return NULL; - - /* byte offset in cluster */ - byte_offset &= p_fs->cluster_size - 1; - - /* byte offset in sector */ - off = byte_offset & p_bd->sector_size_mask; - - /* sector offset in cluster */ - sec = byte_offset >> p_bd->sector_size_bits; - sec += START_SECTOR(clu); - - buf = exfat_buf_getblk(sb, sec); - if (!buf) - goto err_out; - - ep = (struct dentry_t *)(buf + off); - entry_type = exfat_get_entry_type(ep); - - if ((entry_type != TYPE_FILE) && (entry_type != TYPE_DIR)) - goto err_out; - - if (type == ES_ALL_ENTRIES) - num_entries = ((struct file_dentry_t *)ep)->num_ext + 1; - else - num_entries = type; - - bufsize = offsetof(struct entry_set_cache_t, __buf) + (num_entries) * - sizeof(struct dentry_t); - pr_debug("%s: trying to kmalloc %zx bytes for %d entries\n", __func__, - bufsize, num_entries); - es = kmalloc(bufsize, GFP_KERNEL); - if (!es) - goto err_out; - - es->num_entries = num_entries; - es->sector = sec; - es->offset = off; - es->alloc_flag = p_dir->flags; - - pos = (struct dentry_t *)&es->__buf; - - while (num_entries) { - /* - * instead of copying whole sector, we will check every entry. - * this will provide minimum stablity and consistency. - */ - entry_type = exfat_get_entry_type(ep); - - if ((entry_type == TYPE_UNUSED) || (entry_type == TYPE_DELETED)) - goto err_out; - - switch (mode) { - case ES_MODE_STARTED: - if ((entry_type == TYPE_FILE) || (entry_type == TYPE_DIR)) - mode = ES_MODE_GET_FILE_ENTRY; - else - goto err_out; - break; - case ES_MODE_GET_FILE_ENTRY: - if (entry_type == TYPE_STREAM) - mode = ES_MODE_GET_STRM_ENTRY; - else - goto err_out; - break; - case ES_MODE_GET_STRM_ENTRY: - if (entry_type == TYPE_EXTEND) - mode = ES_MODE_GET_NAME_ENTRY; - else - goto err_out; - break; - case ES_MODE_GET_NAME_ENTRY: - if (entry_type == TYPE_EXTEND) - break; - else if (entry_type == TYPE_STREAM) - goto err_out; - else if (entry_type & TYPE_CRITICAL_SEC) - mode = ES_MODE_GET_CRITICAL_SEC_ENTRY; - else - goto err_out; - break; - case ES_MODE_GET_CRITICAL_SEC_ENTRY: - if ((entry_type == TYPE_EXTEND) || - (entry_type == TYPE_STREAM)) - goto err_out; - else if ((entry_type & TYPE_CRITICAL_SEC) != - TYPE_CRITICAL_SEC) - goto err_out; - break; - } - - memcpy(pos, ep, sizeof(struct dentry_t)); - - if (--num_entries == 0) - break; - - if (((off + DENTRY_SIZE) & p_bd->sector_size_mask) < - (off & p_bd->sector_size_mask)) { - /* get the next sector */ - if (IS_LAST_SECTOR_IN_CLUSTER(sec)) { - if (es->alloc_flag == 0x03) { - clu++; - } else { - if (exfat_fat_read(sb, clu, &clu) == -1) - goto err_out; - } - sec = START_SECTOR(clu); - } else { - sec++; - } - buf = exfat_buf_getblk(sb, sec); - if (!buf) - goto err_out; - off = 0; - ep = (struct dentry_t *)(buf); - } else { - ep++; - off += DENTRY_SIZE; - } - pos++; - } - - if (file_ep) - *file_ep = (struct dentry_t *)&es->__buf; - - pr_debug("%s exiting es %p sec %llu offset %d flags %d, num_entries %u buf ptr %p\n", - __func__, es, (unsigned long long)es->sector, es->offset, - es->alloc_flag, es->num_entries, &es->__buf); - return es; -err_out: - pr_debug("%s exited NULL (es %p)\n", __func__, es); - kfree(es); - return NULL; -} - -void release_entry_set(struct entry_set_cache_t *es) -{ - pr_debug("%s es=%p\n", __func__, es); - kfree(es); -} - -/* search EMPTY CONTINUOUS "num_entries" entries */ -static s32 search_deleted_or_unused_entry(struct super_block *sb, - struct chain_t *p_dir, - s32 num_entries) -{ - int i, dentry, num_empty = 0; - s32 dentries_per_clu; - u32 type; - struct chain_t clu; - struct dentry_t *ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - dentries_per_clu = p_fs->dentries_in_root; - else - dentries_per_clu = p_fs->dentries_per_clu; - - if (p_fs->hint_uentry.dir == p_dir->dir) { - if (p_fs->hint_uentry.entry == -1) - return -1; - - clu.dir = p_fs->hint_uentry.clu.dir; - clu.size = p_fs->hint_uentry.clu.size; - clu.flags = p_fs->hint_uentry.clu.flags; - - dentry = p_fs->hint_uentry.entry; - } else { - p_fs->hint_uentry.entry = -1; - - clu.dir = p_dir->dir; - clu.size = p_dir->size; - clu.flags = p_dir->flags; - - dentry = 0; - } - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - i = dentry % dentries_per_clu; - else - i = dentry & (dentries_per_clu - 1); - - for (; i < dentries_per_clu; i++, dentry++) { - ep = get_entry_in_dir(sb, &clu, i, NULL); - if (!ep) - return -1; - - type = exfat_get_entry_type(ep); - - if (type == TYPE_UNUSED) { - num_empty++; - if (p_fs->hint_uentry.entry == -1) { - p_fs->hint_uentry.dir = p_dir->dir; - p_fs->hint_uentry.entry = dentry; - - p_fs->hint_uentry.clu.dir = clu.dir; - p_fs->hint_uentry.clu.size = clu.size; - p_fs->hint_uentry.clu.flags = clu.flags; - } - } else if (type == TYPE_DELETED) { - num_empty++; - } else { - num_empty = 0; - } - - if (num_empty >= num_entries) { - p_fs->hint_uentry.dir = CLUSTER_32(~0); - p_fs->hint_uentry.entry = -1; - - if (p_fs->vol_type == EXFAT) - return dentry - (num_entries - 1); - else - return dentry; - } - } - - if (p_dir->dir == CLUSTER_32(0)) - break; /* FAT16 root_dir */ - - if (clu.flags == 0x03) { - if ((--clu.size) > 0) - clu.dir++; - else - clu.dir = CLUSTER_32(~0); - } else { - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - return -1; - } - } - - return -1; -} - -static s32 find_empty_entry(struct inode *inode, struct chain_t *p_dir, s32 num_entries) -{ - s32 ret, dentry; - u32 last_clu; - sector_t sector; - u64 size = 0; - struct chain_t clu; - struct dentry_t *ep = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - return search_deleted_or_unused_entry(sb, p_dir, num_entries); - - while ((dentry = search_deleted_or_unused_entry(sb, p_dir, num_entries)) < 0) { - if (p_fs->dev_ejected) - break; - - if (p_dir->dir != p_fs->root_dir) - size = i_size_read(inode); - - last_clu = find_last_cluster(sb, p_dir); - clu.dir = last_clu + 1; - clu.size = 0; - clu.flags = p_dir->flags; - - /* (1) allocate a cluster */ - ret = exfat_alloc_cluster(sb, 1, &clu); - if (ret < 1) - return -EIO; - - if (clear_cluster(sb, clu.dir) != 0) - return -EIO; - - /* (2) append to the FAT chain */ - if (clu.flags != p_dir->flags) { - exfat_chain_cont_cluster(sb, p_dir->dir, p_dir->size); - p_dir->flags = 0x01; - p_fs->hint_uentry.clu.flags = 0x01; - } - if (clu.flags == 0x01) - if (exfat_fat_write(sb, last_clu, clu.dir) < 0) - return -EIO; - - if (p_fs->hint_uentry.entry == -1) { - p_fs->hint_uentry.dir = p_dir->dir; - p_fs->hint_uentry.entry = p_dir->size << (p_fs->cluster_size_bits - DENTRY_SIZE_BITS); - - p_fs->hint_uentry.clu.dir = clu.dir; - p_fs->hint_uentry.clu.size = 0; - p_fs->hint_uentry.clu.flags = clu.flags; - } - p_fs->hint_uentry.clu.size++; - p_dir->size++; - - /* (3) update the directory entry */ - if (p_dir->dir != p_fs->root_dir) { - size += p_fs->cluster_size; - - ep = get_entry_in_dir(sb, &fid->dir, - fid->entry + 1, §or); - if (!ep) - return -ENOENT; - exfat_set_entry_size(ep, size); - exfat_set_entry_flag(ep, p_dir->flags); - exfat_buf_modify(sb, sector); - - update_dir_checksum(sb, &fid->dir, - fid->entry); - } - - i_size_write(inode, i_size_read(inode) + p_fs->cluster_size); - EXFAT_I(inode)->mmu_private += p_fs->cluster_size; - EXFAT_I(inode)->fid.size += p_fs->cluster_size; - EXFAT_I(inode)->fid.flags = p_dir->flags; - inode->i_blocks += 1 << (p_fs->cluster_size_bits - 9); - } - - return dentry; -} - -static s32 extract_uni_name_from_name_entry(struct name_dentry_t *ep, u16 *uniname, - s32 order) -{ - int i, len = 0; - - for (i = 0; i < 30; i += 2) { - *uniname = GET16_A(ep->unicode_0_14 + i); - if (*uniname == 0x0) - return len; - uniname++; - len++; - } - - *uniname = 0x0; - return len; -} - -/* return values of exfat_find_dir_entry() - * >= 0 : return dir entiry position with the name in dir - * -1 : (root dir, ".") it is the root dir itself - * -2 : entry with the name does not exist - */ -s32 exfat_find_dir_entry(struct super_block *sb, struct chain_t *p_dir, - struct uni_name_t *p_uniname, s32 num_entries, - struct dos_name_t *p_dosname, u32 type) -{ - int i = 0, dentry = 0, num_ext_entries = 0, len, step; - s32 order = 0; - bool is_feasible_entry = false; - s32 dentries_per_clu, num_empty = 0; - u32 entry_type; - u16 entry_uniname[16], *uniname = NULL, unichar; - struct chain_t clu; - struct dentry_t *ep; - struct file_dentry_t *file_ep; - struct strm_dentry_t *strm_ep; - struct name_dentry_t *name_ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (p_dir->dir == p_fs->root_dir) { - if ((!nls_uniname_cmp(sb, p_uniname->name, - (u16 *)UNI_CUR_DIR_NAME)) || - (!nls_uniname_cmp(sb, p_uniname->name, - (u16 *)UNI_PAR_DIR_NAME))) - return -1; // special case, root directory itself - } - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - dentries_per_clu = p_fs->dentries_in_root; - else - dentries_per_clu = p_fs->dentries_per_clu; - - clu.dir = p_dir->dir; - clu.size = p_dir->size; - clu.flags = p_dir->flags; - - p_fs->hint_uentry.dir = p_dir->dir; - p_fs->hint_uentry.entry = -1; - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - while (i < dentries_per_clu) { - ep = get_entry_in_dir(sb, &clu, i, NULL); - if (!ep) - return -2; - - entry_type = exfat_get_entry_type(ep); - step = 1; - - if ((entry_type == TYPE_UNUSED) || (entry_type == TYPE_DELETED)) { - is_feasible_entry = false; - - if (p_fs->hint_uentry.entry == -1) { - num_empty++; - - if (num_empty == 1) { - p_fs->hint_uentry.clu.dir = clu.dir; - p_fs->hint_uentry.clu.size = clu.size; - p_fs->hint_uentry.clu.flags = clu.flags; - } - if ((num_empty >= num_entries) || (entry_type == TYPE_UNUSED)) - p_fs->hint_uentry.entry = dentry - (num_empty - 1); - } - - if (entry_type == TYPE_UNUSED) - return -2; - } else { - num_empty = 0; - - if ((entry_type == TYPE_FILE) || (entry_type == TYPE_DIR)) { - file_ep = (struct file_dentry_t *)ep; - if ((type == TYPE_ALL) || (type == entry_type)) { - num_ext_entries = file_ep->num_ext; - is_feasible_entry = true; - } else { - is_feasible_entry = false; - step = file_ep->num_ext + 1; - } - } else if (entry_type == TYPE_STREAM) { - if (is_feasible_entry) { - strm_ep = (struct strm_dentry_t *)ep; - if (p_uniname->name_hash == GET16_A(strm_ep->name_hash) && - p_uniname->name_len == strm_ep->name_len) { - order = 1; - } else { - is_feasible_entry = false; - step = num_ext_entries; - } - } - } else if (entry_type == TYPE_EXTEND) { - if (is_feasible_entry) { - name_ep = (struct name_dentry_t *)ep; - - if ((++order) == 2) - uniname = p_uniname->name; - else - uniname += 15; - - len = extract_uni_name_from_name_entry(name_ep, - entry_uniname, order); - - unichar = *(uniname + len); - *(uniname + len) = 0x0; - - if (nls_uniname_cmp(sb, uniname, entry_uniname)) { - is_feasible_entry = false; - step = num_ext_entries - order + 1; - } else if (order == num_ext_entries) { - p_fs->hint_uentry.dir = CLUSTER_32(~0); - p_fs->hint_uentry.entry = -1; - return dentry - (num_ext_entries); - } - - *(uniname + len) = unichar; - } - } else { - is_feasible_entry = false; - } - } - - i += step; - dentry += step; - } - - i -= dentries_per_clu; - - if (p_dir->dir == CLUSTER_32(0)) - break; /* FAT16 root_dir */ - - if (clu.flags == 0x03) { - if ((--clu.size) > 0) - clu.dir++; - else - clu.dir = CLUSTER_32(~0); - } else { - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - return -2; - } - } - - return -2; -} - -s32 exfat_count_ext_entries(struct super_block *sb, struct chain_t *p_dir, - s32 entry, struct dentry_t *p_entry) -{ - int i, count = 0; - u32 type; - struct file_dentry_t *file_ep = (struct file_dentry_t *)p_entry; - struct dentry_t *ext_ep; - - for (i = 0, entry++; i < file_ep->num_ext; i++, entry++) { - ext_ep = get_entry_in_dir(sb, p_dir, entry, NULL); - if (!ext_ep) - return -1; - - type = exfat_get_entry_type(ext_ep); - if ((type == TYPE_EXTEND) || (type == TYPE_STREAM)) - count++; - else - return count; - } - - return count; -} - -s32 count_dos_name_entries(struct super_block *sb, struct chain_t *p_dir, - u32 type) -{ - int i, count = 0; - s32 dentries_per_clu; - u32 entry_type; - struct chain_t clu; - struct dentry_t *ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - dentries_per_clu = p_fs->dentries_in_root; - else - dentries_per_clu = p_fs->dentries_per_clu; - - clu.dir = p_dir->dir; - clu.size = p_dir->size; - clu.flags = p_dir->flags; - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - for (i = 0; i < dentries_per_clu; i++) { - ep = get_entry_in_dir(sb, &clu, i, NULL); - if (!ep) - return -ENOENT; - - entry_type = exfat_get_entry_type(ep); - - if (entry_type == TYPE_UNUSED) - return count; - if (!(type & TYPE_CRITICAL_PRI) && - !(type & TYPE_BENIGN_PRI)) - continue; - - if ((type == TYPE_ALL) || (type == entry_type)) - count++; - } - - if (p_dir->dir == CLUSTER_32(0)) - break; /* FAT16 root_dir */ - - if (clu.flags == 0x03) { - if ((--clu.size) > 0) - clu.dir++; - else - clu.dir = CLUSTER_32(~0); - } else { - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - return -EIO; - } - } - - return count; -} - -bool is_dir_empty(struct super_block *sb, struct chain_t *p_dir) -{ - int i, count = 0; - s32 dentries_per_clu; - u32 type; - struct chain_t clu; - struct dentry_t *ep; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - dentries_per_clu = p_fs->dentries_in_root; - else - dentries_per_clu = p_fs->dentries_per_clu; - - clu.dir = p_dir->dir; - clu.size = p_dir->size; - clu.flags = p_dir->flags; - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - for (i = 0; i < dentries_per_clu; i++) { - ep = get_entry_in_dir(sb, &clu, i, NULL); - if (!ep) - break; - - type = exfat_get_entry_type(ep); - - if (type == TYPE_UNUSED) - return true; - if ((type != TYPE_FILE) && (type != TYPE_DIR)) - continue; - - if (p_dir->dir == CLUSTER_32(0)) /* FAT16 root_dir */ - return false; - - if (p_fs->vol_type == EXFAT) - return false; - if ((p_dir->dir == p_fs->root_dir) || ((++count) > 2)) - return false; - } - - if (p_dir->dir == CLUSTER_32(0)) - break; /* FAT16 root_dir */ - - if (clu.flags == 0x03) { - if ((--clu.size) > 0) - clu.dir++; - else - clu.dir = CLUSTER_32(~0); - } - if (exfat_fat_read(sb, clu.dir, &clu.dir) != 0) - break; - } - - return true; -} - -/* - * Name Conversion Functions - */ - -/* input : dir, uni_name - * output : num_of_entry, dos_name(format : aaaaaa~1.bbb) - */ -s32 get_num_entries_and_dos_name(struct super_block *sb, struct chain_t *p_dir, - struct uni_name_t *p_uniname, s32 *entries, - struct dos_name_t *p_dosname) -{ - s32 num_entries; - - num_entries = exfat_calc_num_entries(p_uniname); - if (num_entries == 0) - return -EINVAL; - - *entries = num_entries; - - return 0; -} - -void exfat_get_uni_name_from_ext_entry(struct super_block *sb, - struct chain_t *p_dir, s32 entry, - u16 *uniname) -{ - int i; - struct dentry_t *ep; - struct entry_set_cache_t *es; - - es = get_entry_set_in_dir(sb, p_dir, entry, ES_ALL_ENTRIES, &ep); - if (!es || es->num_entries < 3) { - if (es) - release_entry_set(es); - return; - } - - ep += 2; - - /* - * First entry : file entry - * Second entry : stream-extension entry - * Third entry : first file-name entry - * So, the index of first file-name dentry should start from 2. - */ - for (i = 2; i < es->num_entries; i++, ep++) { - if (exfat_get_entry_type(ep) == TYPE_EXTEND) - extract_uni_name_from_name_entry((struct name_dentry_t *) - ep, uniname, i); - else - goto out; - uniname += 15; - } - -out: - release_entry_set(es); -} - -s32 exfat_calc_num_entries(struct uni_name_t *p_uniname) -{ - s32 len; - - len = p_uniname->name_len; - if (len == 0) - return 0; - - /* 1 file entry + 1 stream entry + name entries */ - return (len - 1) / 15 + 3; -} - -u16 calc_checksum_2byte(void *data, s32 len, u16 chksum, s32 type) -{ - int i; - u8 *c = (u8 *)data; - - switch (type) { - case CS_DIR_ENTRY: - for (i = 0; i < len; i++, c++) { - if ((i == 2) || (i == 3)) - continue; - chksum = (((chksum & 1) << 15) | - ((chksum & 0xFFFE) >> 1)) + (u16)*c; - } - break; - default - : - for (i = 0; i < len; i++, c++) - chksum = (((chksum & 1) << 15) | - ((chksum & 0xFFFE) >> 1)) + (u16)*c; - } - - return chksum; -} - -/* - * Name Resolution Functions - */ - -/* return values of resolve_path() - * > 0 : return the length of the path - * < 0 : return error - */ -s32 resolve_path(struct inode *inode, char *path, struct chain_t *p_dir, - struct uni_name_t *p_uniname) -{ - bool lossy = false; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - - if (strscpy(name_buf, path, sizeof(name_buf)) < 0) - return -EINVAL; - - nls_cstring_to_uniname(sb, p_uniname, name_buf, &lossy); - if (lossy) - return -EINVAL; - - fid->size = i_size_read(inode); - - p_dir->dir = fid->start_clu; - p_dir->size = (s32)(fid->size >> p_fs->cluster_size_bits); - p_dir->flags = fid->flags; - - return 0; -} - -s32 exfat_mount(struct super_block *sb, struct pbr_sector_t *p_pbr) -{ - struct bpbex_t *p_bpb = (struct bpbex_t *)p_pbr->bpb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - if (p_bpb->num_fats == 0) - return -EFSCORRUPTED; - - p_fs->sectors_per_clu = 1 << p_bpb->sectors_per_clu_bits; - p_fs->sectors_per_clu_bits = p_bpb->sectors_per_clu_bits; - p_fs->cluster_size_bits = p_fs->sectors_per_clu_bits + - p_bd->sector_size_bits; - p_fs->cluster_size = 1 << p_fs->cluster_size_bits; - - p_fs->num_FAT_sectors = GET32(p_bpb->fat_length); - - p_fs->FAT1_start_sector = p_fs->PBR_sector + GET32(p_bpb->fat_offset); - if (p_bpb->num_fats == 1) - p_fs->FAT2_start_sector = p_fs->FAT1_start_sector; - else - p_fs->FAT2_start_sector = p_fs->FAT1_start_sector + - p_fs->num_FAT_sectors; - - p_fs->root_start_sector = p_fs->PBR_sector + GET32(p_bpb->clu_offset); - p_fs->data_start_sector = p_fs->root_start_sector; - - p_fs->num_sectors = GET64(p_bpb->vol_length); - p_fs->num_clusters = GET32(p_bpb->clu_count) + 2; - /* because the cluster index starts with 2 */ - - p_fs->vol_type = EXFAT; - p_fs->vol_id = GET32(p_bpb->vol_serial); - - p_fs->root_dir = GET32(p_bpb->root_cluster); - p_fs->dentries_in_root = 0; - p_fs->dentries_per_clu = 1 << (p_fs->cluster_size_bits - - DENTRY_SIZE_BITS); - - p_fs->vol_flag = (u32)GET16(p_bpb->vol_flags); - p_fs->clu_srch_ptr = 2; - p_fs->used_clusters = UINT_MAX; - - return 0; -} - -s32 create_dir(struct inode *inode, struct chain_t *p_dir, - struct uni_name_t *p_uniname, struct file_id_t *fid) -{ - s32 ret, dentry, num_entries; - u64 size; - struct chain_t clu; - struct dos_name_t dos_name; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries, - &dos_name); - if (ret) - return ret; - - /* find_empty_entry must be called before alloc_cluster */ - dentry = find_empty_entry(inode, p_dir, num_entries); - if (dentry < 0) - return -ENOSPC; - - clu.dir = CLUSTER_32(~0); - clu.size = 0; - clu.flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - - /* (1) allocate a cluster */ - ret = exfat_alloc_cluster(sb, 1, &clu); - if (ret < 0) - return ret; - else if (ret == 0) - return -ENOSPC; - - ret = clear_cluster(sb, clu.dir); - if (ret != 0) - return ret; - - size = p_fs->cluster_size; - - /* (2) update the directory entry */ - /* make sub-dir entry in parent directory */ - ret = exfat_init_dir_entry(sb, p_dir, dentry, TYPE_DIR, clu.dir, - size); - if (ret != 0) - return ret; - - ret = exfat_init_ext_entry(sb, p_dir, dentry, num_entries, p_uniname, - &dos_name); - if (ret != 0) - return ret; - - fid->dir.dir = p_dir->dir; - fid->dir.size = p_dir->size; - fid->dir.flags = p_dir->flags; - fid->entry = dentry; - - fid->attr = ATTR_SUBDIR; - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - fid->size = size; - fid->start_clu = clu.dir; - - fid->type = TYPE_DIR; - fid->rwoffset = 0; - fid->hint_last_off = -1; - - return 0; -} - -s32 create_file(struct inode *inode, struct chain_t *p_dir, - struct uni_name_t *p_uniname, u8 mode, struct file_id_t *fid) -{ - s32 ret, dentry, num_entries; - struct dos_name_t dos_name; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, &num_entries, - &dos_name); - if (ret) - return ret; - - /* find_empty_entry must be called before alloc_cluster() */ - dentry = find_empty_entry(inode, p_dir, num_entries); - if (dentry < 0) - return -ENOSPC; - - /* (1) update the directory entry */ - /* fill the dos name directory entry information of the created file. - * the first cluster is not determined yet. (0) - */ - ret = exfat_init_dir_entry(sb, p_dir, dentry, TYPE_FILE | mode, - CLUSTER_32(0), 0); - if (ret != 0) - return ret; - - ret = exfat_init_ext_entry(sb, p_dir, dentry, num_entries, p_uniname, - &dos_name); - if (ret != 0) - return ret; - - fid->dir.dir = p_dir->dir; - fid->dir.size = p_dir->size; - fid->dir.flags = p_dir->flags; - fid->entry = dentry; - - fid->attr = ATTR_ARCHIVE | mode; - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - fid->size = 0; - fid->start_clu = CLUSTER_32(~0); - - fid->type = TYPE_FILE; - fid->rwoffset = 0; - fid->hint_last_off = -1; - - return 0; -} - -void remove_file(struct inode *inode, struct chain_t *p_dir, s32 entry) -{ - s32 num_entries; - sector_t sector; - struct dentry_t *ep; - struct super_block *sb = inode->i_sb; - - ep = get_entry_in_dir(sb, p_dir, entry, §or); - if (!ep) - return; - - exfat_buf_lock(sb, sector); - - /* exfat_buf_lock() before call count_ext_entries() */ - num_entries = exfat_count_ext_entries(sb, p_dir, entry, ep); - if (num_entries < 0) { - exfat_buf_unlock(sb, sector); - return; - } - num_entries++; - - exfat_buf_unlock(sb, sector); - - /* (1) update the directory entry */ - exfat_delete_dir_entry(sb, p_dir, entry, 0, num_entries); -} - -s32 exfat_rename_file(struct inode *inode, struct chain_t *p_dir, s32 oldentry, - struct uni_name_t *p_uniname, struct file_id_t *fid) -{ - s32 ret, newentry = -1, num_old_entries, num_new_entries; - sector_t sector_old, sector_new; - struct dos_name_t dos_name; - struct dentry_t *epold, *epnew; - struct super_block *sb = inode->i_sb; - - epold = get_entry_in_dir(sb, p_dir, oldentry, §or_old); - if (!epold) - return -ENOENT; - - exfat_buf_lock(sb, sector_old); - - /* exfat_buf_lock() before call count_ext_entries() */ - num_old_entries = exfat_count_ext_entries(sb, p_dir, oldentry, - epold); - if (num_old_entries < 0) { - exfat_buf_unlock(sb, sector_old); - return -ENOENT; - } - num_old_entries++; - - ret = get_num_entries_and_dos_name(sb, p_dir, p_uniname, - &num_new_entries, &dos_name); - if (ret) { - exfat_buf_unlock(sb, sector_old); - return ret; - } - - if (num_old_entries < num_new_entries) { - newentry = find_empty_entry(inode, p_dir, num_new_entries); - if (newentry < 0) { - exfat_buf_unlock(sb, sector_old); - return -ENOSPC; - } - - epnew = get_entry_in_dir(sb, p_dir, newentry, §or_new); - if (!epnew) { - exfat_buf_unlock(sb, sector_old); - return -ENOENT; - } - - memcpy((void *)epnew, (void *)epold, DENTRY_SIZE); - if (exfat_get_entry_type(epnew) == TYPE_FILE) { - exfat_set_entry_attr(epnew, - exfat_get_entry_attr(epnew) | - ATTR_ARCHIVE); - fid->attr |= ATTR_ARCHIVE; - } - exfat_buf_modify(sb, sector_new); - exfat_buf_unlock(sb, sector_old); - - epold = get_entry_in_dir(sb, p_dir, oldentry + 1, - §or_old); - exfat_buf_lock(sb, sector_old); - epnew = get_entry_in_dir(sb, p_dir, newentry + 1, - §or_new); - - if (!epold || !epnew) { - exfat_buf_unlock(sb, sector_old); - return -ENOENT; - } - - memcpy((void *)epnew, (void *)epold, DENTRY_SIZE); - exfat_buf_modify(sb, sector_new); - exfat_buf_unlock(sb, sector_old); - - ret = exfat_init_ext_entry(sb, p_dir, newentry, - num_new_entries, p_uniname, - &dos_name); - if (ret != 0) - return ret; - - exfat_delete_dir_entry(sb, p_dir, oldentry, 0, - num_old_entries); - fid->entry = newentry; - } else { - if (exfat_get_entry_type(epold) == TYPE_FILE) { - exfat_set_entry_attr(epold, - exfat_get_entry_attr(epold) | - ATTR_ARCHIVE); - fid->attr |= ATTR_ARCHIVE; - } - exfat_buf_modify(sb, sector_old); - exfat_buf_unlock(sb, sector_old); - - ret = exfat_init_ext_entry(sb, p_dir, oldentry, - num_new_entries, p_uniname, - &dos_name); - if (ret != 0) - return ret; - - exfat_delete_dir_entry(sb, p_dir, oldentry, num_new_entries, - num_old_entries); - } - - return 0; -} - -s32 move_file(struct inode *inode, struct chain_t *p_olddir, s32 oldentry, - struct chain_t *p_newdir, struct uni_name_t *p_uniname, - struct file_id_t *fid) -{ - s32 ret, newentry, num_new_entries, num_old_entries; - sector_t sector_mov, sector_new; - struct dos_name_t dos_name; - struct dentry_t *epmov, *epnew; - struct super_block *sb = inode->i_sb; - - epmov = get_entry_in_dir(sb, p_olddir, oldentry, §or_mov); - if (!epmov) - return -ENOENT; - - /* check if the source and target directory is the same */ - if (exfat_get_entry_type(epmov) == TYPE_DIR && - exfat_get_entry_clu0(epmov) == p_newdir->dir) - return -EINVAL; - - exfat_buf_lock(sb, sector_mov); - - /* exfat_buf_lock() before call count_ext_entries() */ - num_old_entries = exfat_count_ext_entries(sb, p_olddir, oldentry, - epmov); - if (num_old_entries < 0) { - exfat_buf_unlock(sb, sector_mov); - return -ENOENT; - } - num_old_entries++; - - ret = get_num_entries_and_dos_name(sb, p_newdir, p_uniname, - &num_new_entries, &dos_name); - if (ret) { - exfat_buf_unlock(sb, sector_mov); - return ret; - } - - newentry = find_empty_entry(inode, p_newdir, num_new_entries); - if (newentry < 0) { - exfat_buf_unlock(sb, sector_mov); - return -ENOSPC; - } - - epnew = get_entry_in_dir(sb, p_newdir, newentry, §or_new); - if (!epnew) { - exfat_buf_unlock(sb, sector_mov); - return -ENOENT; - } - - memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE); - if (exfat_get_entry_type(epnew) == TYPE_FILE) { - exfat_set_entry_attr(epnew, exfat_get_entry_attr(epnew) | - ATTR_ARCHIVE); - fid->attr |= ATTR_ARCHIVE; - } - exfat_buf_modify(sb, sector_new); - exfat_buf_unlock(sb, sector_mov); - - epmov = get_entry_in_dir(sb, p_olddir, oldentry + 1, - §or_mov); - exfat_buf_lock(sb, sector_mov); - epnew = get_entry_in_dir(sb, p_newdir, newentry + 1, - §or_new); - if (!epmov || !epnew) { - exfat_buf_unlock(sb, sector_mov); - return -ENOENT; - } - - memcpy((void *)epnew, (void *)epmov, DENTRY_SIZE); - exfat_buf_modify(sb, sector_new); - exfat_buf_unlock(sb, sector_mov); - - ret = exfat_init_ext_entry(sb, p_newdir, newentry, num_new_entries, - p_uniname, &dos_name); - if (ret != 0) - return ret; - - exfat_delete_dir_entry(sb, p_olddir, oldentry, 0, num_old_entries); - - fid->dir.dir = p_newdir->dir; - fid->dir.size = p_newdir->size; - fid->dir.flags = p_newdir->flags; - - fid->entry = newentry; - - return 0; -} - -/* - * Sector Read/Write Functions - */ - -int sector_read(struct super_block *sb, sector_t sec, struct buffer_head **bh, - bool read) -{ - s32 ret = -EIO; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if ((sec >= (p_fs->PBR_sector + p_fs->num_sectors)) && - (p_fs->num_sectors > 0)) { - pr_err("[EXFAT] %s: out of range error! (sec = %llu)\n", - __func__, (unsigned long long)sec); - fs_error(sb); - return ret; - } - - if (!p_fs->dev_ejected) { - ret = exfat_bdev_read(sb, sec, bh, 1, read); - if (ret != 0) - p_fs->dev_ejected = 1; - } - - return ret; -} - -int sector_write(struct super_block *sb, sector_t sec, struct buffer_head *bh, - bool sync) -{ - s32 ret = -EIO; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (sec >= (p_fs->PBR_sector + p_fs->num_sectors) && - (p_fs->num_sectors > 0)) { - pr_err("[EXFAT] %s: out of range error! (sec = %llu)\n", - __func__, (unsigned long long)sec); - fs_error(sb); - return ret; - } - - if (!bh) { - pr_err("[EXFAT] %s: bh is NULL!\n", __func__); - fs_error(sb); - return ret; - } - - if (!p_fs->dev_ejected) { - ret = exfat_bdev_write(sb, sec, bh, 1, sync); - if (ret != 0) - p_fs->dev_ejected = 1; - } - - return ret; -} - -int multi_sector_read(struct super_block *sb, sector_t sec, - struct buffer_head **bh, s32 num_secs, bool read) -{ - s32 ret = -EIO; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors)) && - (p_fs->num_sectors > 0)) { - pr_err("[EXFAT] %s: out of range error! (sec = %llu, num_secs = %d)\n", - __func__, (unsigned long long)sec, num_secs); - fs_error(sb); - return ret; - } - - if (!p_fs->dev_ejected) { - ret = exfat_bdev_read(sb, sec, bh, num_secs, read); - if (ret != 0) - p_fs->dev_ejected = 1; - } - - return ret; -} - -int multi_sector_write(struct super_block *sb, sector_t sec, - struct buffer_head *bh, s32 num_secs, bool sync) -{ - s32 ret = -EIO; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if ((sec + num_secs) > (p_fs->PBR_sector + p_fs->num_sectors) && - (p_fs->num_sectors > 0)) { - pr_err("[EXFAT] %s: out of range error! (sec = %llu, num_secs = %d)\n", - __func__, (unsigned long long)sec, num_secs); - fs_error(sb); - return ret; - } - if (!bh) { - pr_err("[EXFAT] %s: bh is NULL!\n", __func__); - fs_error(sb); - return ret; - } - - if (!p_fs->dev_ejected) { - ret = exfat_bdev_write(sb, sec, bh, num_secs, sync); - if (ret != 0) - p_fs->dev_ejected = 1; - } - - return ret; -} diff --git a/drivers/staging/exfat/exfat_nls.c b/drivers/staging/exfat/exfat_nls.c deleted file mode 100644 index 91e8b0c4dce7..000000000000 --- a/drivers/staging/exfat/exfat_nls.c +++ /dev/null @@ -1,212 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/string.h> -#include <linux/nls.h> -#include "exfat.h" - -static u16 bad_uni_chars[] = { - /* " * / : < > ? \ | */ - 0x0022, 0x002A, 0x002F, 0x003A, - 0x003C, 0x003E, 0x003F, 0x005C, 0x007C, - 0 -}; - -static int convert_ch_to_uni(struct nls_table *nls, u16 *uni, u8 *ch, - bool *lossy) -{ - int len; - - *uni = 0x0; - - if (ch[0] < 0x80) { - *uni = (u16)ch[0]; - return 1; - } - - len = nls->char2uni(ch, NLS_MAX_CHARSET_SIZE, uni); - if (len < 0) { - /* conversion failed */ - pr_info("%s: fail to use nls\n", __func__); - if (lossy) - *lossy = true; - *uni = (u16)'_'; - if (!strcmp(nls->charset, "utf8")) - return 1; - else - return 2; - } - - return len; -} - -static int convert_uni_to_ch(struct nls_table *nls, u8 *ch, u16 uni, - bool *lossy) -{ - int len; - - ch[0] = 0x0; - - if (uni < 0x0080) { - ch[0] = (u8)uni; - return 1; - } - - len = nls->uni2char(uni, ch, NLS_MAX_CHARSET_SIZE); - if (len < 0) { - /* conversion failed */ - pr_info("%s: fail to use nls\n", __func__); - if (lossy) - *lossy = true; - ch[0] = '_'; - return 1; - } - - return len; -} - -u16 nls_upper(struct super_block *sb, u16 a) -{ - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - if (EXFAT_SB(sb)->options.casesensitive) - return a; - if (p_fs->vol_utbl && p_fs->vol_utbl[get_col_index(a)]) - return p_fs->vol_utbl[get_col_index(a)][get_row_index(a)]; - else - return a; -} - -static u16 *nls_wstrchr(u16 *str, u16 wchar) -{ - while (*str) { - if (*(str++) == wchar) - return str; - } - - return NULL; -} - -int nls_uniname_cmp(struct super_block *sb, u16 *a, u16 *b) -{ - int i; - - for (i = 0; i < MAX_NAME_LENGTH; i++, a++, b++) { - if (nls_upper(sb, *a) != nls_upper(sb, *b)) - return 1; - if (*a == 0x0) - return 0; - } - return 0; -} - -void nls_uniname_to_cstring(struct super_block *sb, u8 *p_cstring, - struct uni_name_t *p_uniname) -{ - int i, j, len; - u8 buf[MAX_CHARSET_SIZE]; - u16 *uniname = p_uniname->name; - struct nls_table *nls = EXFAT_SB(sb)->nls_io; - - if (!nls) { - len = utf16s_to_utf8s(uniname, MAX_NAME_LENGTH, - UTF16_HOST_ENDIAN, p_cstring, - MAX_NAME_LENGTH); - p_cstring[len] = 0; - return; - } - - i = 0; - while (i < (MAX_NAME_LENGTH - 1)) { - if (*uniname == (u16)'\0') - break; - - len = convert_uni_to_ch(nls, buf, *uniname, NULL); - - if (len > 1) { - for (j = 0; j < len; j++) - *p_cstring++ = (char)*(buf + j); - } else { /* len == 1 */ - *p_cstring++ = (char)*buf; - } - - uniname++; - i++; - } - - *p_cstring = '\0'; -} - -void nls_cstring_to_uniname(struct super_block *sb, - struct uni_name_t *p_uniname, u8 *p_cstring, - bool *p_lossy) -{ - int i, j; - bool lossy = false; - u8 *end_of_name; - u8 upname[MAX_NAME_LENGTH * 2]; - u16 *uniname = p_uniname->name; - struct nls_table *nls = EXFAT_SB(sb)->nls_io; - - /* strip all trailing spaces */ - end_of_name = p_cstring + strlen(p_cstring); - - while (*(--end_of_name) == ' ') { - if (end_of_name < p_cstring) - break; - } - *(++end_of_name) = '\0'; - - if (strcmp(p_cstring, ".") && strcmp(p_cstring, "..")) { - /* strip all trailing periods */ - while (*(--end_of_name) == '.') { - if (end_of_name < p_cstring) - break; - } - *(++end_of_name) = '\0'; - } - - if (*p_cstring == '\0') - lossy = true; - - if (!nls) { - i = utf8s_to_utf16s(p_cstring, MAX_NAME_LENGTH, - UTF16_HOST_ENDIAN, uniname, - MAX_NAME_LENGTH); - for (j = 0; j < i; j++) - SET16_A(upname + j * 2, nls_upper(sb, uniname[j])); - uniname[i] = '\0'; - } else { - i = 0; - j = 0; - while (j < (MAX_NAME_LENGTH - 1)) { - if (*(p_cstring + i) == '\0') - break; - - i += convert_ch_to_uni(nls, uniname, - (u8 *)(p_cstring + i), &lossy); - - if ((*uniname < 0x0020) || - nls_wstrchr(bad_uni_chars, *uniname)) - lossy = true; - - SET16_A(upname + j * 2, nls_upper(sb, *uniname)); - - uniname++; - j++; - } - - if (*(p_cstring + i) != '\0') - lossy = true; - *uniname = (u16)'\0'; - } - - p_uniname->name_len = j; - p_uniname->name_hash = calc_checksum_2byte(upname, j << 1, 0, - CS_DEFAULT); - - if (p_lossy) - *p_lossy = lossy; -} diff --git a/drivers/staging/exfat/exfat_super.c b/drivers/staging/exfat/exfat_super.c deleted file mode 100644 index b81d2a87b82e..000000000000 --- a/drivers/staging/exfat/exfat_super.c +++ /dev/null @@ -1,3883 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/module.h> -#include <linux/init.h> -#include <linux/time.h> -#include <linux/slab.h> -#include <linux/mm.h> -#include <linux/seq_file.h> -#include <linux/pagemap.h> -#include <linux/mpage.h> -#include <linux/buffer_head.h> -#include <linux/exportfs.h> -#include <linux/mount.h> -#include <linux/vfs.h> -#include <linux/aio.h> -#include <linux/iversion.h> -#include <linux/parser.h> -#include <linux/uio.h> -#include <linux/writeback.h> -#include <linux/log2.h> -#include <linux/hash.h> -#include <linux/backing-dev.h> -#include <linux/sched.h> -#include <linux/fs_struct.h> -#include <linux/namei.h> -#include <linux/random.h> -#include <linux/string.h> -#include <linux/nls.h> -#include <linux/mutex.h> -#include <linux/swap.h> - -#define EXFAT_VERSION "1.3.0" - -#include "exfat.h" - -static struct kmem_cache *exfat_inode_cachep; - -static int exfat_default_codepage = CONFIG_STAGING_EXFAT_DEFAULT_CODEPAGE; -static char exfat_default_iocharset[] = CONFIG_STAGING_EXFAT_DEFAULT_IOCHARSET; - -#define INC_IVERSION(x) (inode_inc_iversion(x)) -#define GET_IVERSION(x) (inode_peek_iversion_raw(x)) -#define SET_IVERSION(x, y) (inode_set_iversion(x, y)) - -static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos); -static int exfat_sync_inode(struct inode *inode); -static struct inode *exfat_build_inode(struct super_block *sb, - struct file_id_t *fid, loff_t i_pos); -static int exfat_write_inode(struct inode *inode, - struct writeback_control *wbc); -static void exfat_write_super(struct super_block *sb); - -#define UNIX_SECS_1980 315532800L -#define UNIX_SECS_2108 4354819200L - -/* Convert a FAT time/date pair to a UNIX date (seconds since 1 1 70). */ -static void exfat_time_fat2unix(struct timespec64 *ts, struct date_time_t *tp) -{ - ts->tv_sec = mktime64(tp->Year + 1980, tp->Month + 1, tp->Day, - tp->Hour, tp->Minute, tp->Second); - - ts->tv_nsec = tp->MilliSecond * NSEC_PER_MSEC; -} - -/* Convert linear UNIX date to a FAT time/date pair. */ -static void exfat_time_unix2fat(struct timespec64 *ts, struct date_time_t *tp) -{ - time64_t second = ts->tv_sec; - struct tm tm; - - time64_to_tm(second, 0, &tm); - - if (second < UNIX_SECS_1980) { - tp->MilliSecond = 0; - tp->Second = 0; - tp->Minute = 0; - tp->Hour = 0; - tp->Day = 1; - tp->Month = 1; - tp->Year = 0; - return; - } - - if (second >= UNIX_SECS_2108) { - tp->MilliSecond = 999; - tp->Second = 59; - tp->Minute = 59; - tp->Hour = 23; - tp->Day = 31; - tp->Month = 12; - tp->Year = 127; - return; - } - - tp->MilliSecond = ts->tv_nsec / NSEC_PER_MSEC; - tp->Second = tm.tm_sec; - tp->Minute = tm.tm_min; - tp->Hour = tm.tm_hour; - tp->Day = tm.tm_mday; - tp->Month = tm.tm_mon + 1; - tp->Year = tm.tm_year + 1900 - 1980; -} - -struct timestamp_t *tm_current(struct timestamp_t *tp) -{ - time64_t second = ktime_get_real_seconds(); - struct tm tm; - - time64_to_tm(second, 0, &tm); - - if (second < UNIX_SECS_1980) { - tp->sec = 0; - tp->min = 0; - tp->hour = 0; - tp->day = 1; - tp->mon = 1; - tp->year = 0; - return tp; - } - - if (second >= UNIX_SECS_2108) { - tp->sec = 59; - tp->min = 59; - tp->hour = 23; - tp->day = 31; - tp->mon = 12; - tp->year = 127; - return tp; - } - - tp->sec = tm.tm_sec; - tp->min = tm.tm_min; - tp->hour = tm.tm_hour; - tp->day = tm.tm_mday; - tp->mon = tm.tm_mon + 1; - tp->year = tm.tm_year + 1900 - 1980; - - return tp; -} - -static void __lock_super(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - mutex_lock(&sbi->s_lock); -} - -static void __unlock_super(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - mutex_unlock(&sbi->s_lock); -} - -static int __is_sb_dirty(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - return sbi->s_dirt; -} - -static void __set_sb_clean(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - sbi->s_dirt = 0; -} - -static int __exfat_revalidate(struct dentry *dentry) -{ - return 0; -} - -static int exfat_revalidate(struct dentry *dentry, unsigned int flags) -{ - if (flags & LOOKUP_RCU) - return -ECHILD; - - if (dentry->d_inode) - return 1; - return __exfat_revalidate(dentry); -} - -static int exfat_revalidate_ci(struct dentry *dentry, unsigned int flags) -{ - if (flags & LOOKUP_RCU) - return -ECHILD; - - if (dentry->d_inode) - return 1; - - if (!flags) - return 0; - - if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET)) - return 0; - - return __exfat_revalidate(dentry); -} - -static unsigned int __exfat_striptail_len(unsigned int len, const char *name) -{ - while (len && name[len - 1] == '.') - len--; - return len; -} - -static unsigned int exfat_striptail_len(const struct qstr *qstr) -{ - return __exfat_striptail_len(qstr->len, qstr->name); -} - -static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr) -{ - qstr->hash = full_name_hash(dentry, qstr->name, - exfat_striptail_len(qstr)); - return 0; -} - -static int exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr) -{ - struct super_block *sb = dentry->d_sb; - const unsigned char *name; - unsigned int len; - unsigned long hash; - - name = qstr->name; - len = exfat_striptail_len(qstr); - - hash = init_name_hash(dentry); - while (len--) - hash = partial_name_hash(nls_upper(sb, *name++), hash); - qstr->hash = end_name_hash(hash); - - return 0; -} - -static int exfat_cmpi(const struct dentry *dentry, unsigned int len, - const char *str, const struct qstr *name) -{ - struct nls_table *t = EXFAT_SB(dentry->d_sb)->nls_io; - unsigned int alen, blen; - - alen = exfat_striptail_len(name); - blen = __exfat_striptail_len(len, str); - if (alen == blen) { - if (!t) { - if (strncasecmp(name->name, str, alen) == 0) - return 0; - } else { - if (nls_strnicmp(t, name->name, str, alen) == 0) - return 0; - } - } - return 1; -} - -static int exfat_cmp(const struct dentry *dentry, unsigned int len, - const char *str, const struct qstr *name) -{ - unsigned int alen, blen; - - alen = exfat_striptail_len(name); - blen = __exfat_striptail_len(len, str); - if (alen == blen) { - if (strncmp(name->name, str, alen) == 0) - return 0; - } - return 1; -} - -static const struct dentry_operations exfat_ci_dentry_ops = { - .d_revalidate = exfat_revalidate_ci, - .d_hash = exfat_d_hashi, - .d_compare = exfat_cmpi, -}; - -static const struct dentry_operations exfat_dentry_ops = { - .d_revalidate = exfat_revalidate, - .d_hash = exfat_d_hash, - .d_compare = exfat_cmp, -}; - -static DEFINE_MUTEX(z_mutex); - -static inline void fs_sync(struct super_block *sb, bool do_sync) -{ - if (do_sync) - exfat_bdev_sync(sb); -} - -/* - * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to - * save ATTR_RO instead of ->i_mode. - * - * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only - * bit, it's just used as flag for app. - */ -static inline int exfat_mode_can_hold_ro(struct inode *inode) -{ - struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb); - - if (S_ISDIR(inode->i_mode)) - return 0; - - if ((~sbi->options.fs_fmask) & 0222) - return 1; - return 0; -} - -/* Convert attribute bits and a mask to the UNIX mode. */ -static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi, u32 attr, - mode_t mode) -{ - if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR)) - mode &= ~0222; - - if (attr & ATTR_SUBDIR) - return (mode & ~sbi->options.fs_dmask) | S_IFDIR; - else if (attr & ATTR_SYMLINK) - return (mode & ~sbi->options.fs_dmask) | S_IFLNK; - else - return (mode & ~sbi->options.fs_fmask) | S_IFREG; -} - -/* Return the FAT attribute byte for this inode */ -static inline u32 exfat_make_attr(struct inode *inode) -{ - if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & 0222)) - return (EXFAT_I(inode)->fid.attr) | ATTR_READONLY; - else - return EXFAT_I(inode)->fid.attr; -} - -static inline void exfat_save_attr(struct inode *inode, u32 attr) -{ - if (exfat_mode_can_hold_ro(inode)) - EXFAT_I(inode)->fid.attr = attr & ATTR_RWMASK; - else - EXFAT_I(inode)->fid.attr = attr & (ATTR_RWMASK | ATTR_READONLY); -} - -static int ffsMountVol(struct super_block *sb) -{ - int i, ret; - struct pbr_sector_t *p_pbr; - struct buffer_head *tmp_bh = NULL; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - pr_info("[EXFAT] trying to mount...\n"); - - mutex_lock(&z_mutex); - - exfat_buf_init(sb); - - mutex_init(&p_fs->v_mutex); - p_fs->dev_ejected = 0; - - /* open the block device */ - exfat_bdev_open(sb); - - if (p_bd->sector_size < sb->s_blocksize) { - printk(KERN_INFO "EXFAT: mount failed - sector size %d less than blocksize %ld\n", - p_bd->sector_size, sb->s_blocksize); - ret = -EINVAL; - goto out; - } - if (p_bd->sector_size > sb->s_blocksize) - sb_set_blocksize(sb, p_bd->sector_size); - - /* read Sector 0 */ - if (sector_read(sb, 0, &tmp_bh, 1) != 0) { - ret = -EIO; - goto out; - } - - p_fs->PBR_sector = 0; - - p_pbr = (struct pbr_sector_t *)tmp_bh->b_data; - - /* check the validity of PBR */ - if (GET16_A(p_pbr->signature) != PBR_SIGNATURE) { - brelse(tmp_bh); - exfat_bdev_close(sb); - ret = -EFSCORRUPTED; - goto out; - } - - /* fill fs_struct */ - for (i = 0; i < 53; i++) - if (p_pbr->bpb[i]) - break; - - if (i < 53) { - /* Not sure how we'd get here, but complain if it does */ - ret = -EINVAL; - pr_info("EXFAT: Attempted to mount VFAT filesystem\n"); - goto out; - } else { - ret = exfat_mount(sb, p_pbr); - } - - brelse(tmp_bh); - - if (ret) { - exfat_bdev_close(sb); - goto out; - } - - ret = load_alloc_bitmap(sb); - if (ret) { - exfat_bdev_close(sb); - goto out; - } - ret = load_upcase_table(sb); - if (ret) { - free_alloc_bitmap(sb); - exfat_bdev_close(sb); - goto out; - } - - if (p_fs->dev_ejected) { - free_upcase_table(sb); - free_alloc_bitmap(sb); - exfat_bdev_close(sb); - ret = -EIO; - goto out; - } - - pr_info("[EXFAT] mounted successfully\n"); - -out: - mutex_unlock(&z_mutex); - - return ret; -} - -static int ffsUmountVol(struct super_block *sb) -{ - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - int err = 0; - - pr_info("[EXFAT] trying to unmount...\n"); - - mutex_lock(&z_mutex); - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); - - free_upcase_table(sb); - free_alloc_bitmap(sb); - - exfat_fat_release_all(sb); - exfat_buf_release_all(sb); - - /* close the block device */ - exfat_bdev_close(sb); - - if (p_fs->dev_ejected) { - pr_info("[EXFAT] unmounted with media errors. Device is already ejected.\n"); - err = -EIO; - } - - exfat_buf_shutdown(sb); - - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - mutex_unlock(&z_mutex); - - pr_info("[EXFAT] unmounted successfully\n"); - - return err; -} - -static int ffsGetVolInfo(struct super_block *sb, struct vol_info_t *info) -{ - int err = 0; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - /* check the validity of pointer parameters */ - if (!info) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - if (p_fs->used_clusters == UINT_MAX) - p_fs->used_clusters = exfat_count_used_clusters(sb); - - info->FatType = p_fs->vol_type; - info->ClusterSize = p_fs->cluster_size; - info->NumClusters = p_fs->num_clusters - 2; /* clu 0 & 1 */ - info->UsedClusters = p_fs->used_clusters; - info->FreeClusters = info->NumClusters - info->UsedClusters; - - if (p_fs->dev_ejected) - err = -EIO; - - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return err; -} - -static int ffsSyncVol(struct super_block *sb, bool do_sync) -{ - int err = 0; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* synchronize the file system */ - fs_sync(sb, do_sync); - fs_set_vol_flags(sb, VOL_CLEAN); - - if (p_fs->dev_ejected) - err = -EIO; - - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return err; -} - -/*----------------------------------------------------------------------*/ -/* File Operation Functions */ -/*----------------------------------------------------------------------*/ - -static int ffsLookupFile(struct inode *inode, char *path, struct file_id_t *fid) -{ - int ret, dentry, num_entries; - struct chain_t dir; - struct uni_name_t uni_name; - struct dos_name_t dos_name; - struct dentry_t *ep, *ep2; - struct entry_set_cache_t *es = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - pr_debug("%s entered\n", __func__); - - /* check the validity of pointer parameters */ - if (!fid || !path || (*path == '\0')) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check the validity of directory name in the given pathname */ - ret = resolve_path(inode, path, &dir, &uni_name); - if (ret) - goto out; - - ret = get_num_entries_and_dos_name(sb, &dir, &uni_name, &num_entries, - &dos_name); - if (ret) - goto out; - - /* search the file name for directories */ - dentry = exfat_find_dir_entry(sb, &dir, &uni_name, num_entries, - &dos_name, TYPE_ALL); - if (dentry < -1) { - ret = -ENOENT; - goto out; - } - - fid->dir.dir = dir.dir; - fid->dir.size = dir.size; - fid->dir.flags = dir.flags; - fid->entry = dentry; - - if (dentry == -1) { - fid->type = TYPE_DIR; - fid->rwoffset = 0; - fid->hint_last_off = -1; - - fid->attr = ATTR_SUBDIR; - fid->flags = 0x01; - fid->size = 0; - fid->start_clu = p_fs->root_dir; - } else { - es = get_entry_set_in_dir(sb, &dir, dentry, - ES_2_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - ep2 = ep + 1; - - fid->type = exfat_get_entry_type(ep); - fid->rwoffset = 0; - fid->hint_last_off = -1; - fid->attr = exfat_get_entry_attr(ep); - - fid->size = exfat_get_entry_size(ep2); - if ((fid->type == TYPE_FILE) && (fid->size == 0)) { - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - fid->start_clu = CLUSTER_32(~0); - } else { - fid->flags = exfat_get_entry_flag(ep2); - fid->start_clu = exfat_get_entry_clu0(ep2); - } - - release_entry_set(es); - } - - if (p_fs->dev_ejected) - ret = -EIO; -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsCreateFile(struct inode *inode, char *path, u8 mode, - struct file_id_t *fid) -{ - struct chain_t dir; - struct uni_name_t uni_name; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - int ret = 0; - - /* check the validity of pointer parameters */ - if (!fid || !path || (*path == '\0')) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check the validity of directory name in the given pathname */ - ret = resolve_path(inode, path, &dir, &uni_name); - if (ret) - goto out; - - fs_set_vol_flags(sb, VOL_DIRTY); - - /* create a new file */ - ret = create_file(inode, &dir, &uni_name, mode, fid); - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsReadFile(struct inode *inode, struct file_id_t *fid, void *buffer, - u64 count, u64 *rcount) -{ - s32 offset, sec_offset, clu_offset; - u32 clu; - int ret = 0; - sector_t LogSector; - u64 oneblkread, read_bytes; - struct buffer_head *tmp_bh = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - /* check the validity of the given file id */ - if (!fid) - return -EINVAL; - - /* check the validity of pointer parameters */ - if (!buffer) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check if the given file ID is opened */ - if (fid->type != TYPE_FILE) { - ret = -EPERM; - goto out; - } - - if (fid->rwoffset > fid->size) - fid->rwoffset = fid->size; - - if (count > (fid->size - fid->rwoffset)) - count = fid->size - fid->rwoffset; - - if (count == 0) { - if (rcount) - *rcount = 0; - ret = 0; - goto out; - } - - read_bytes = 0; - - while (count > 0) { - clu_offset = (s32)(fid->rwoffset >> p_fs->cluster_size_bits); - clu = fid->start_clu; - - if (fid->flags == 0x03) { - clu += clu_offset; - } else { - /* hint information */ - if ((clu_offset > 0) && (fid->hint_last_off > 0) && - (clu_offset >= fid->hint_last_off)) { - clu_offset -= fid->hint_last_off; - clu = fid->hint_last_clu; - } - - while (clu_offset > 0) { - /* clu = exfat_fat_read(sb, clu); */ - if (exfat_fat_read(sb, clu, &clu) == -1) { - ret = -EIO; - goto out; - } - - clu_offset--; - } - } - - /* hint information */ - fid->hint_last_off = (s32)(fid->rwoffset >> - p_fs->cluster_size_bits); - fid->hint_last_clu = clu; - - /* byte offset in cluster */ - offset = (s32)(fid->rwoffset & (p_fs->cluster_size - 1)); - - /* sector offset in cluster */ - sec_offset = offset >> p_bd->sector_size_bits; - - /* byte offset in sector */ - offset &= p_bd->sector_size_mask; - - LogSector = START_SECTOR(clu) + sec_offset; - - oneblkread = (u64)(p_bd->sector_size - offset); - if (oneblkread > count) - oneblkread = count; - - if ((offset == 0) && (oneblkread == p_bd->sector_size)) { - if (sector_read(sb, LogSector, &tmp_bh, 1) != - 0) - goto err_out; - memcpy((char *)buffer + read_bytes, - (char *)tmp_bh->b_data, (s32)oneblkread); - } else { - if (sector_read(sb, LogSector, &tmp_bh, 1) != - 0) - goto err_out; - memcpy((char *)buffer + read_bytes, - (char *)tmp_bh->b_data + offset, - (s32)oneblkread); - } - count -= oneblkread; - read_bytes += oneblkread; - fid->rwoffset += oneblkread; - } - brelse(tmp_bh); - -/* How did this ever work and not leak a brlse()?? */ -err_out: - /* set the size of read bytes */ - if (rcount) - *rcount = read_bytes; - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsWriteFile(struct inode *inode, struct file_id_t *fid, - void *buffer, u64 count, u64 *wcount) -{ - bool modified = false; - s32 offset, sec_offset, clu_offset; - s32 num_clusters, num_alloc, num_alloced = (s32)~0; - int ret = 0; - u32 clu, last_clu; - sector_t LogSector; - u64 oneblkwrite, write_bytes; - struct chain_t new_clu; - struct timestamp_t tm; - struct dentry_t *ep, *ep2; - struct entry_set_cache_t *es = NULL; - struct buffer_head *tmp_bh = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - - /* check the validity of the given file id */ - if (!fid) - return -EINVAL; - - /* check the validity of pointer parameters */ - if (!buffer) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check if the given file ID is opened */ - if (fid->type != TYPE_FILE) { - ret = -EPERM; - goto out; - } - - if (fid->rwoffset > fid->size) - fid->rwoffset = fid->size; - - if (count == 0) { - if (wcount) - *wcount = 0; - ret = 0; - goto out; - } - - fs_set_vol_flags(sb, VOL_DIRTY); - - if (fid->size == 0) - num_clusters = 0; - else - num_clusters = (s32)((fid->size - 1) >> - p_fs->cluster_size_bits) + 1; - - write_bytes = 0; - - while (count > 0) { - clu_offset = (s32)(fid->rwoffset >> p_fs->cluster_size_bits); - clu = fid->start_clu; - last_clu = fid->start_clu; - - if (fid->flags == 0x03) { - if ((clu_offset > 0) && (clu != CLUSTER_32(~0))) { - last_clu += clu_offset - 1; - - if (clu_offset == num_clusters) - clu = CLUSTER_32(~0); - else - clu += clu_offset; - } - } else { - /* hint information */ - if ((clu_offset > 0) && (fid->hint_last_off > 0) && - (clu_offset >= fid->hint_last_off)) { - clu_offset -= fid->hint_last_off; - clu = fid->hint_last_clu; - } - - while ((clu_offset > 0) && (clu != CLUSTER_32(~0))) { - last_clu = clu; - /* clu = exfat_fat_read(sb, clu); */ - if (exfat_fat_read(sb, clu, &clu) == -1) { - ret = -EIO; - goto out; - } - clu_offset--; - } - } - - if (clu == CLUSTER_32(~0)) { - num_alloc = (s32)((count - 1) >> - p_fs->cluster_size_bits) + 1; - new_clu.dir = (last_clu == CLUSTER_32(~0)) ? - CLUSTER_32(~0) : last_clu + 1; - new_clu.size = 0; - new_clu.flags = fid->flags; - - /* (1) allocate a chain of clusters */ - num_alloced = exfat_alloc_cluster(sb, - num_alloc, - &new_clu); - if (num_alloced == 0) - break; - if (num_alloced < 0) { - ret = num_alloced; - goto out; - } - - /* (2) append to the FAT chain */ - if (last_clu == CLUSTER_32(~0)) { - if (new_clu.flags == 0x01) - fid->flags = 0x01; - fid->start_clu = new_clu.dir; - modified = true; - } else { - if (new_clu.flags != fid->flags) { - exfat_chain_cont_cluster(sb, - fid->start_clu, - num_clusters); - fid->flags = 0x01; - modified = true; - } - if (new_clu.flags == 0x01) - exfat_fat_write(sb, last_clu, new_clu.dir); - } - - num_clusters += num_alloced; - clu = new_clu.dir; - } - - /* hint information */ - fid->hint_last_off = (s32)(fid->rwoffset >> - p_fs->cluster_size_bits); - fid->hint_last_clu = clu; - - /* byte offset in cluster */ - offset = (s32)(fid->rwoffset & (p_fs->cluster_size - 1)); - - /* sector offset in cluster */ - sec_offset = offset >> p_bd->sector_size_bits; - - /* byte offset in sector */ - offset &= p_bd->sector_size_mask; - - LogSector = START_SECTOR(clu) + sec_offset; - - oneblkwrite = (u64)(p_bd->sector_size - offset); - if (oneblkwrite > count) - oneblkwrite = count; - - if ((offset == 0) && (oneblkwrite == p_bd->sector_size)) { - if (sector_read(sb, LogSector, &tmp_bh, 0) != - 0) - goto err_out; - memcpy((char *)tmp_bh->b_data, - (char *)buffer + write_bytes, (s32)oneblkwrite); - if (sector_write(sb, LogSector, tmp_bh, 0) != - 0) { - brelse(tmp_bh); - goto err_out; - } - } else { - if ((offset > 0) || - ((fid->rwoffset + oneblkwrite) < fid->size)) { - if (sector_read(sb, LogSector, &tmp_bh, 1) != - 0) - goto err_out; - } else { - if (sector_read(sb, LogSector, &tmp_bh, 0) != - 0) - goto err_out; - } - - memcpy((char *)tmp_bh->b_data + offset, - (char *)buffer + write_bytes, (s32)oneblkwrite); - if (sector_write(sb, LogSector, tmp_bh, 0) != - 0) { - brelse(tmp_bh); - goto err_out; - } - } - - count -= oneblkwrite; - write_bytes += oneblkwrite; - fid->rwoffset += oneblkwrite; - - fid->attr |= ATTR_ARCHIVE; - - if (fid->size < fid->rwoffset) { - fid->size = fid->rwoffset; - modified = true; - } - } - - brelse(tmp_bh); - - /* (3) update the direcoty entry */ - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_ALL_ENTRIES, &ep); - if (!es) - goto err_out; - ep2 = ep + 1; - - exfat_set_entry_time(ep, tm_current(&tm), TM_MODIFY); - exfat_set_entry_attr(ep, fid->attr); - - if (modified) { - if (exfat_get_entry_flag(ep2) != fid->flags) - exfat_set_entry_flag(ep2, fid->flags); - - if (exfat_get_entry_size(ep2) != fid->size) - exfat_set_entry_size(ep2, fid->size); - - if (exfat_get_entry_clu0(ep2) != fid->start_clu) - exfat_set_entry_clu0(ep2, fid->start_clu); - } - - update_dir_checksum_with_entry_set(sb, es); - release_entry_set(es); - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - -err_out: - /* set the size of written bytes */ - if (wcount) - *wcount = write_bytes; - - if (num_alloced == 0) - ret = -ENOSPC; - - else if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsTruncateFile(struct inode *inode, u64 old_size, u64 new_size) -{ - s32 num_clusters; - u32 last_clu = CLUSTER_32(0); - int ret = 0; - struct chain_t clu; - struct timestamp_t tm; - struct dentry_t *ep, *ep2; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - struct entry_set_cache_t *es = NULL; - - pr_debug("%s entered (inode %p size %llu)\n", __func__, inode, - new_size); - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check if the given file ID is opened */ - if (fid->type != TYPE_FILE) { - ret = -EPERM; - goto out; - } - - if (fid->size != old_size) { - pr_err("[EXFAT] truncate : can't skip it because of size-mismatch(old:%lld->fid:%lld).\n", - old_size, fid->size); - } - - if (old_size <= new_size) { - ret = 0; - goto out; - } - - fs_set_vol_flags(sb, VOL_DIRTY); - - clu.dir = fid->start_clu; - clu.size = (s32)((old_size - 1) >> p_fs->cluster_size_bits) + 1; - clu.flags = fid->flags; - - if (new_size > 0) { - num_clusters = (s32)((new_size - 1) >> - p_fs->cluster_size_bits) + 1; - - if (clu.flags == 0x03) { - clu.dir += num_clusters; - } else { - while (num_clusters > 0) { - last_clu = clu.dir; - if (exfat_fat_read(sb, clu.dir, &clu.dir) == -1) { - ret = -EIO; - goto out; - } - num_clusters--; - } - } - - clu.size -= num_clusters; - } - - fid->size = new_size; - fid->attr |= ATTR_ARCHIVE; - if (new_size == 0) { - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - fid->start_clu = CLUSTER_32(~0); - } - - /* (1) update the directory entry */ - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_ALL_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - ep2 = ep + 1; - - exfat_set_entry_time(ep, tm_current(&tm), TM_MODIFY); - exfat_set_entry_attr(ep, fid->attr); - - exfat_set_entry_size(ep2, new_size); - if (new_size == 0) { - exfat_set_entry_flag(ep2, 0x01); - exfat_set_entry_clu0(ep2, CLUSTER_32(0)); - } - - update_dir_checksum_with_entry_set(sb, es); - release_entry_set(es); - - /* (2) cut off from the FAT chain */ - if (last_clu != CLUSTER_32(0)) { - if (fid->flags == 0x01) - exfat_fat_write(sb, last_clu, CLUSTER_32(~0)); - } - - /* (3) free the clusters */ - exfat_free_cluster(sb, &clu, 0); - - /* hint information */ - fid->hint_last_off = -1; - if (fid->rwoffset > fid->size) - fid->rwoffset = fid->size; - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - pr_debug("%s exited (%d)\n", __func__, ret); - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static void update_parent_info(struct file_id_t *fid, - struct inode *parent_inode) -{ - struct fs_info_t *p_fs = &(EXFAT_SB(parent_inode->i_sb)->fs_info); - struct file_id_t *parent_fid = &(EXFAT_I(parent_inode)->fid); - - if (unlikely((parent_fid->flags != fid->dir.flags) || - (parent_fid->size != - (fid->dir.size << p_fs->cluster_size_bits)) || - (parent_fid->start_clu != fid->dir.dir))) { - fid->dir.dir = parent_fid->start_clu; - fid->dir.flags = parent_fid->flags; - fid->dir.size = ((parent_fid->size + (p_fs->cluster_size - 1)) - >> p_fs->cluster_size_bits); - } -} - -static int ffsMoveFile(struct inode *old_parent_inode, struct file_id_t *fid, - struct inode *new_parent_inode, struct dentry *new_dentry) -{ - s32 ret; - s32 dentry; - struct chain_t olddir, newdir; - struct chain_t *p_dir = NULL; - struct uni_name_t uni_name; - struct dentry_t *ep; - struct super_block *sb = old_parent_inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - u8 *new_path = (u8 *)new_dentry->d_name.name; - struct inode *new_inode = new_dentry->d_inode; - int num_entries; - struct file_id_t *new_fid = NULL; - s32 new_entry = 0; - - /* check the validity of the given file id */ - if (!fid) - return -EINVAL; - - /* check the validity of pointer parameters */ - if (!new_path || (*new_path == '\0')) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - update_parent_info(fid, old_parent_inode); - - olddir.dir = fid->dir.dir; - olddir.size = fid->dir.size; - olddir.flags = fid->dir.flags; - - dentry = fid->entry; - - /* check if the old file is "." or ".." */ - if (p_fs->vol_type != EXFAT) { - if ((olddir.dir != p_fs->root_dir) && (dentry < 2)) { - ret = -EPERM; - goto out2; - } - } - - ep = get_entry_in_dir(sb, &olddir, dentry, NULL); - if (!ep) { - ret = -ENOENT; - goto out2; - } - - if (exfat_get_entry_attr(ep) & ATTR_READONLY) { - ret = -EPERM; - goto out2; - } - - /* check whether new dir is existing directory and empty */ - if (new_inode) { - u32 entry_type; - - ret = -ENOENT; - new_fid = &EXFAT_I(new_inode)->fid; - - update_parent_info(new_fid, new_parent_inode); - - p_dir = &new_fid->dir; - new_entry = new_fid->entry; - ep = get_entry_in_dir(sb, p_dir, new_entry, NULL); - if (!ep) - goto out; - - entry_type = exfat_get_entry_type(ep); - - if (entry_type == TYPE_DIR) { - struct chain_t new_clu; - - new_clu.dir = new_fid->start_clu; - new_clu.size = (s32)((new_fid->size - 1) >> - p_fs->cluster_size_bits) + 1; - new_clu.flags = new_fid->flags; - - if (!is_dir_empty(sb, &new_clu)) { - ret = -EEXIST; - goto out; - } - } - } - - /* check the validity of directory name in the given new pathname */ - ret = resolve_path(new_parent_inode, new_path, &newdir, &uni_name); - if (ret) - goto out2; - - fs_set_vol_flags(sb, VOL_DIRTY); - - if (olddir.dir == newdir.dir) - ret = exfat_rename_file(new_parent_inode, &olddir, dentry, - &uni_name, fid); - else - ret = move_file(new_parent_inode, &olddir, dentry, &newdir, - &uni_name, fid); - - if ((ret == 0) && new_inode) { - /* delete entries of new_dir */ - ep = get_entry_in_dir(sb, p_dir, new_entry, NULL); - if (!ep) - goto out; - - num_entries = exfat_count_ext_entries(sb, p_dir, - new_entry, ep); - if (num_entries < 0) - goto out; - exfat_delete_dir_entry(sb, p_dir, new_entry, 0, - num_entries + 1); - } -out: -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; -out2: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsRemoveFile(struct inode *inode, struct file_id_t *fid) -{ - s32 dentry; - int ret = 0; - struct chain_t dir, clu_to_free; - struct dentry_t *ep; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - /* check the validity of the given file id */ - if (!fid) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - dir.dir = fid->dir.dir; - dir.size = fid->dir.size; - dir.flags = fid->dir.flags; - - dentry = fid->entry; - - ep = get_entry_in_dir(sb, &dir, dentry, NULL); - if (!ep) { - ret = -ENOENT; - goto out; - } - - if (exfat_get_entry_attr(ep) & ATTR_READONLY) { - ret = -EPERM; - goto out; - } - fs_set_vol_flags(sb, VOL_DIRTY); - - /* (1) update the directory entry */ - remove_file(inode, &dir, dentry); - - clu_to_free.dir = fid->start_clu; - clu_to_free.size = (s32)((fid->size - 1) >> p_fs->cluster_size_bits) + 1; - clu_to_free.flags = fid->flags; - - /* (2) free the clusters */ - exfat_free_cluster(sb, &clu_to_free, 0); - - fid->size = 0; - fid->start_clu = CLUSTER_32(~0); - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -#if 0 -/* Not currently wired up */ -static int ffsSetAttr(struct inode *inode, u32 attr) -{ - u32 type; - int ret = 0; - sector_t sector = 0; - struct dentry_t *ep; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0; - struct entry_set_cache_t *es = NULL; - - if (fid->attr == attr) { - if (p_fs->dev_ejected) - return -EIO; - return 0; - } - - if (is_dir) { - if ((fid->dir.dir == p_fs->root_dir) && - (fid->entry == -1)) { - if (p_fs->dev_ejected) - return -EIO; - return 0; - } - } - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* get the directory entry of given file */ - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_ALL_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - - type = exfat_get_entry_type(ep); - - if (((type == TYPE_FILE) && (attr & ATTR_SUBDIR)) || - ((type == TYPE_DIR) && (!(attr & ATTR_SUBDIR)))) { - if (p_fs->dev_ejected) - ret = -EIO; - else - ret = -EINVAL; - - release_entry_set(es); - goto out; - } - - fs_set_vol_flags(sb, VOL_DIRTY); - - /* set the file attribute */ - fid->attr = attr; - exfat_set_entry_attr(ep, attr); - - update_dir_checksum_with_entry_set(sb, es); - release_entry_set(es); - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} -#endif - -static int ffsReadStat(struct inode *inode, struct dir_entry_t *info) -{ - s32 count; - int ret = 0; - struct chain_t dir; - struct uni_name_t uni_name; - struct timestamp_t tm; - struct dentry_t *ep, *ep2; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - struct entry_set_cache_t *es = NULL; - u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0; - - pr_debug("%s entered\n", __func__); - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - if (is_dir) { - if ((fid->dir.dir == p_fs->root_dir) && - (fid->entry == -1)) { - info->Attr = ATTR_SUBDIR; - memset((char *)&info->CreateTimestamp, 0, - sizeof(struct date_time_t)); - memset((char *)&info->ModifyTimestamp, 0, - sizeof(struct date_time_t)); - memset((char *)&info->AccessTimestamp, 0, - sizeof(struct date_time_t)); - strcpy(info->ShortName, "."); - strcpy(info->Name, "."); - - dir.dir = p_fs->root_dir; - dir.flags = 0x01; - - if (p_fs->root_dir == CLUSTER_32(0)) { - /* FAT16 root_dir */ - info->Size = p_fs->dentries_in_root << - DENTRY_SIZE_BITS; - } else { - info->Size = count_num_clusters(sb, &dir) << - p_fs->cluster_size_bits; - } - - count = count_dos_name_entries(sb, &dir, TYPE_DIR); - if (count < 0) { - ret = count; /* propagate error upward */ - goto out; - } - info->NumSubdirs = count; - - if (p_fs->dev_ejected) - ret = -EIO; - goto out; - } - } - - /* get the directory entry of given file or directory */ - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_2_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - ep2 = ep + 1; - - /* set FILE_INFO structure using the acquired struct dentry_t */ - info->Attr = exfat_get_entry_attr(ep); - - exfat_get_entry_time(ep, &tm, TM_CREATE); - info->CreateTimestamp.Year = tm.year; - info->CreateTimestamp.Month = tm.mon; - info->CreateTimestamp.Day = tm.day; - info->CreateTimestamp.Hour = tm.hour; - info->CreateTimestamp.Minute = tm.min; - info->CreateTimestamp.Second = tm.sec; - info->CreateTimestamp.MilliSecond = 0; - - exfat_get_entry_time(ep, &tm, TM_MODIFY); - info->ModifyTimestamp.Year = tm.year; - info->ModifyTimestamp.Month = tm.mon; - info->ModifyTimestamp.Day = tm.day; - info->ModifyTimestamp.Hour = tm.hour; - info->ModifyTimestamp.Minute = tm.min; - info->ModifyTimestamp.Second = tm.sec; - info->ModifyTimestamp.MilliSecond = 0; - - memset((char *)&info->AccessTimestamp, 0, sizeof(struct date_time_t)); - - *uni_name.name = 0x0; - /* XXX this is very bad for exfat cuz name is already included in es. - * API should be revised - */ - exfat_get_uni_name_from_ext_entry(sb, &fid->dir, fid->entry, - uni_name.name); - nls_uniname_to_cstring(sb, info->Name, &uni_name); - - info->NumSubdirs = 2; - - info->Size = exfat_get_entry_size(ep2); - - release_entry_set(es); - - if (is_dir) { - dir.dir = fid->start_clu; - dir.flags = 0x01; - - if (info->Size == 0) - info->Size = (u64)count_num_clusters(sb, &dir) << - p_fs->cluster_size_bits; - - count = count_dos_name_entries(sb, &dir, TYPE_DIR); - if (count < 0) { - ret = count; /* propagate error upward */ - goto out; - } - info->NumSubdirs += count; - } - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - pr_debug("%s exited successfully\n", __func__); - return ret; -} - -static int ffsWriteStat(struct inode *inode, struct dir_entry_t *info) -{ - int ret = 0; - struct timestamp_t tm; - struct dentry_t *ep, *ep2; - struct entry_set_cache_t *es = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - u8 is_dir = (fid->type == TYPE_DIR) ? 1 : 0; - - pr_debug("%s entered (inode %p info %p\n", __func__, inode, info); - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - if (is_dir) { - if ((fid->dir.dir == p_fs->root_dir) && - (fid->entry == -1)) { - if (p_fs->dev_ejected) - ret = -EIO; - ret = 0; - goto out; - } - } - - fs_set_vol_flags(sb, VOL_DIRTY); - - /* get the directory entry of given file or directory */ - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_ALL_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - ep2 = ep + 1; - - exfat_set_entry_attr(ep, info->Attr); - - /* set FILE_INFO structure using the acquired struct dentry_t */ - tm.sec = info->CreateTimestamp.Second; - tm.min = info->CreateTimestamp.Minute; - tm.hour = info->CreateTimestamp.Hour; - tm.day = info->CreateTimestamp.Day; - tm.mon = info->CreateTimestamp.Month; - tm.year = info->CreateTimestamp.Year; - exfat_set_entry_time(ep, &tm, TM_CREATE); - - tm.sec = info->ModifyTimestamp.Second; - tm.min = info->ModifyTimestamp.Minute; - tm.hour = info->ModifyTimestamp.Hour; - tm.day = info->ModifyTimestamp.Day; - tm.mon = info->ModifyTimestamp.Month; - tm.year = info->ModifyTimestamp.Year; - exfat_set_entry_time(ep, &tm, TM_MODIFY); - - exfat_set_entry_size(ep2, info->Size); - - update_dir_checksum_with_entry_set(sb, es); - release_entry_set(es); - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - pr_debug("%s exited (%d)\n", __func__, ret); - - return ret; -} - -static int ffsMapCluster(struct inode *inode, s32 clu_offset, u32 *clu) -{ - s32 num_clusters, num_alloced; - bool modified = false; - u32 last_clu; - int ret = 0; - struct chain_t new_clu; - struct dentry_t *ep; - struct entry_set_cache_t *es = NULL; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - - /* check the validity of pointer parameters */ - if (!clu) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - fid->rwoffset = (s64)(clu_offset) << p_fs->cluster_size_bits; - - if (EXFAT_I(inode)->mmu_private == 0) - num_clusters = 0; - else - num_clusters = (s32)((EXFAT_I(inode)->mmu_private - 1) >> - p_fs->cluster_size_bits) + 1; - - *clu = last_clu = fid->start_clu; - - if (fid->flags == 0x03) { - if ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) { - last_clu += clu_offset - 1; - - if (clu_offset == num_clusters) - *clu = CLUSTER_32(~0); - else - *clu += clu_offset; - } - } else { - /* hint information */ - if ((clu_offset > 0) && (fid->hint_last_off > 0) && - (clu_offset >= fid->hint_last_off)) { - clu_offset -= fid->hint_last_off; - *clu = fid->hint_last_clu; - } - - while ((clu_offset > 0) && (*clu != CLUSTER_32(~0))) { - last_clu = *clu; - if (exfat_fat_read(sb, *clu, clu) == -1) { - ret = -EIO; - goto out; - } - clu_offset--; - } - } - - if (*clu == CLUSTER_32(~0)) { - fs_set_vol_flags(sb, VOL_DIRTY); - - new_clu.dir = (last_clu == CLUSTER_32(~0)) ? CLUSTER_32(~0) : - last_clu + 1; - new_clu.size = 0; - new_clu.flags = fid->flags; - - /* (1) allocate a cluster */ - num_alloced = exfat_alloc_cluster(sb, 1, &new_clu); - if (num_alloced < 0) { - ret = -EIO; - goto out; - } else if (num_alloced == 0) { - ret = -ENOSPC; - goto out; - } - - /* (2) append to the FAT chain */ - if (last_clu == CLUSTER_32(~0)) { - if (new_clu.flags == 0x01) - fid->flags = 0x01; - fid->start_clu = new_clu.dir; - modified = true; - } else { - if (new_clu.flags != fid->flags) { - exfat_chain_cont_cluster(sb, fid->start_clu, - num_clusters); - fid->flags = 0x01; - modified = true; - } - if (new_clu.flags == 0x01) - exfat_fat_write(sb, last_clu, new_clu.dir); - } - - num_clusters += num_alloced; - *clu = new_clu.dir; - - es = get_entry_set_in_dir(sb, &fid->dir, fid->entry, - ES_ALL_ENTRIES, &ep); - if (!es) { - ret = -ENOENT; - goto out; - } - /* get stream entry */ - ep++; - - /* (3) update directory entry */ - if (modified) { - if (exfat_get_entry_flag(ep) != fid->flags) - exfat_set_entry_flag(ep, fid->flags); - - if (exfat_get_entry_clu0(ep) != fid->start_clu) - exfat_set_entry_clu0(ep, fid->start_clu); - } - - update_dir_checksum_with_entry_set(sb, es); - release_entry_set(es); - - /* add number of new blocks to inode */ - inode->i_blocks += num_alloced << (p_fs->cluster_size_bits - 9); - } - - /* hint information */ - fid->hint_last_off = (s32)(fid->rwoffset >> p_fs->cluster_size_bits); - fid->hint_last_clu = *clu; - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -/*----------------------------------------------------------------------*/ -/* Directory Operation Functions */ -/*----------------------------------------------------------------------*/ - -static int ffsCreateDir(struct inode *inode, char *path, struct file_id_t *fid) -{ - int ret = 0; - struct chain_t dir; - struct uni_name_t uni_name; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - pr_debug("%s entered\n", __func__); - - /* check the validity of pointer parameters */ - if (!fid || !path || (*path == '\0')) - return -EINVAL; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - /* check the validity of directory name in the given old pathname */ - ret = resolve_path(inode, path, &dir, &uni_name); - if (ret) - goto out; - - fs_set_vol_flags(sb, VOL_DIRTY); - - ret = create_dir(inode, &dir, &uni_name, fid); - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsReadDir(struct inode *inode, struct dir_entry_t *dir_entry) -{ - int i, dentry, clu_offset; - int ret = 0; - s32 dentries_per_clu, dentries_per_clu_bits = 0; - u32 type; - sector_t sector; - struct chain_t dir, clu; - struct uni_name_t uni_name; - struct timestamp_t tm; - struct dentry_t *ep; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - - /* check the validity of pointer parameters */ - if (!dir_entry) - return -EINVAL; - - /* check if the given file ID is opened */ - if (fid->type != TYPE_DIR) - return -ENOTDIR; - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - if (fid->entry == -1) { - dir.dir = p_fs->root_dir; - dir.flags = 0x01; - } else { - dir.dir = fid->start_clu; - dir.size = (s32)(fid->size >> p_fs->cluster_size_bits); - dir.flags = fid->flags; - } - - dentry = (s32)fid->rwoffset; - - if (dir.dir == CLUSTER_32(0)) { - /* FAT16 root_dir */ - dentries_per_clu = p_fs->dentries_in_root; - - if (dentry == dentries_per_clu) { - clu.dir = CLUSTER_32(~0); - } else { - clu.dir = dir.dir; - clu.size = dir.size; - clu.flags = dir.flags; - } - } else { - dentries_per_clu = p_fs->dentries_per_clu; - dentries_per_clu_bits = ilog2(dentries_per_clu); - - clu_offset = dentry >> dentries_per_clu_bits; - clu.dir = dir.dir; - clu.size = dir.size; - clu.flags = dir.flags; - - if (clu.flags == 0x03) { - clu.dir += clu_offset; - clu.size -= clu_offset; - } else { - /* hint_information */ - if ((clu_offset > 0) && (fid->hint_last_off > 0) && - (clu_offset >= fid->hint_last_off)) { - clu_offset -= fid->hint_last_off; - clu.dir = fid->hint_last_clu; - } - - while (clu_offset > 0) { - /* clu.dir = exfat_fat_read(sb, clu.dir); */ - if (exfat_fat_read(sb, clu.dir, &clu.dir) == -1) { - ret = -EIO; - goto out; - } - clu_offset--; - } - } - } - - while (clu.dir != CLUSTER_32(~0)) { - if (p_fs->dev_ejected) - break; - - if (dir.dir == CLUSTER_32(0)) /* FAT16 root_dir */ - i = dentry % dentries_per_clu; - else - i = dentry & (dentries_per_clu - 1); - - for ( ; i < dentries_per_clu; i++, dentry++) { - ep = get_entry_in_dir(sb, &clu, i, §or); - if (!ep) { - ret = -ENOENT; - goto out; - } - type = exfat_get_entry_type(ep); - - if (type == TYPE_UNUSED) - break; - - if ((type != TYPE_FILE) && (type != TYPE_DIR)) - continue; - - exfat_buf_lock(sb, sector); - dir_entry->Attr = exfat_get_entry_attr(ep); - - exfat_get_entry_time(ep, &tm, TM_CREATE); - dir_entry->CreateTimestamp.Year = tm.year; - dir_entry->CreateTimestamp.Month = tm.mon; - dir_entry->CreateTimestamp.Day = tm.day; - dir_entry->CreateTimestamp.Hour = tm.hour; - dir_entry->CreateTimestamp.Minute = tm.min; - dir_entry->CreateTimestamp.Second = tm.sec; - dir_entry->CreateTimestamp.MilliSecond = 0; - - exfat_get_entry_time(ep, &tm, TM_MODIFY); - dir_entry->ModifyTimestamp.Year = tm.year; - dir_entry->ModifyTimestamp.Month = tm.mon; - dir_entry->ModifyTimestamp.Day = tm.day; - dir_entry->ModifyTimestamp.Hour = tm.hour; - dir_entry->ModifyTimestamp.Minute = tm.min; - dir_entry->ModifyTimestamp.Second = tm.sec; - dir_entry->ModifyTimestamp.MilliSecond = 0; - - memset((char *)&dir_entry->AccessTimestamp, 0, - sizeof(struct date_time_t)); - - *uni_name.name = 0x0; - exfat_get_uni_name_from_ext_entry(sb, &dir, dentry, - uni_name.name); - nls_uniname_to_cstring(sb, dir_entry->Name, &uni_name); - exfat_buf_unlock(sb, sector); - - ep = get_entry_in_dir(sb, &clu, i + 1, NULL); - if (!ep) { - ret = -ENOENT; - goto out; - } - - dir_entry->Size = exfat_get_entry_size(ep); - - /* hint information */ - if (dir.dir == CLUSTER_32(0)) { /* FAT16 root_dir */ - } else { - fid->hint_last_off = dentry >> - dentries_per_clu_bits; - fid->hint_last_clu = clu.dir; - } - - fid->rwoffset = (s64)(++dentry); - - if (p_fs->dev_ejected) - ret = -EIO; - goto out; - } - - if (dir.dir == CLUSTER_32(0)) - break; /* FAT16 root_dir */ - - if (clu.flags == 0x03) { - if ((--clu.size) > 0) - clu.dir++; - else - clu.dir = CLUSTER_32(~0); - } else { - /* clu.dir = exfat_fat_read(sb, clu.dir); */ - if (exfat_fat_read(sb, clu.dir, &clu.dir) == -1) { - ret = -EIO; - goto out; - } - } - } - - *dir_entry->Name = '\0'; - - fid->rwoffset = (s64)(++dentry); - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -static int ffsRemoveDir(struct inode *inode, struct file_id_t *fid) -{ - s32 dentry; - int ret = 0; - struct chain_t dir, clu_to_free; - struct super_block *sb = inode->i_sb; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - /* check the validity of the given file id */ - if (!fid) - return -EINVAL; - - dir.dir = fid->dir.dir; - dir.size = fid->dir.size; - dir.flags = fid->dir.flags; - - dentry = fid->entry; - - /* check if the file is "." or ".." */ - if (p_fs->vol_type != EXFAT) { - if ((dir.dir != p_fs->root_dir) && (dentry < 2)) - return -EPERM; - } - - /* acquire the lock for file system critical section */ - mutex_lock(&p_fs->v_mutex); - - clu_to_free.dir = fid->start_clu; - clu_to_free.size = (s32)((fid->size - 1) >> p_fs->cluster_size_bits) + 1; - clu_to_free.flags = fid->flags; - - if (!is_dir_empty(sb, &clu_to_free)) { - ret = -ENOTEMPTY; - goto out; - } - - fs_set_vol_flags(sb, VOL_DIRTY); - - /* (1) update the directory entry */ - remove_file(inode, &dir, dentry); - - /* (2) free the clusters */ - exfat_free_cluster(sb, &clu_to_free, 1); - - fid->size = 0; - fid->start_clu = CLUSTER_32(~0); - fid->flags = (p_fs->vol_type == EXFAT) ? 0x03 : 0x01; - -#ifndef CONFIG_STAGING_EXFAT_DELAYED_SYNC - fs_sync(sb, true); - fs_set_vol_flags(sb, VOL_CLEAN); -#endif - - if (p_fs->dev_ejected) - ret = -EIO; - -out: - /* release the lock for file system critical section */ - mutex_unlock(&p_fs->v_mutex); - - return ret; -} - -/*======================================================================*/ -/* Directory Entry Operations */ -/*======================================================================*/ - -static int exfat_readdir(struct file *filp, struct dir_context *ctx) -{ - struct inode *inode = file_inode(filp); - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct fs_info_t *p_fs = &sbi->fs_info; - struct bd_info_t *p_bd = &(EXFAT_SB(sb)->bd_info); - struct dir_entry_t de; - unsigned long inum; - loff_t cpos; - int err = 0; - - __lock_super(sb); - - cpos = ctx->pos; - /* Fake . and .. for the root directory. */ - if ((p_fs->vol_type == EXFAT) || (inode->i_ino == EXFAT_ROOT_INO)) { - while (cpos < 2) { - if (inode->i_ino == EXFAT_ROOT_INO) - inum = EXFAT_ROOT_INO; - else if (cpos == 0) - inum = inode->i_ino; - else /* (cpos == 1) */ - inum = parent_ino(filp->f_path.dentry); - - if (!dir_emit_dots(filp, ctx)) - goto out; - cpos++; - ctx->pos++; - } - if (cpos == 2) - cpos = 0; - } - if (cpos & (DENTRY_SIZE - 1)) { - err = -ENOENT; - goto out; - } - -get_new: - EXFAT_I(inode)->fid.size = i_size_read(inode); - EXFAT_I(inode)->fid.rwoffset = cpos >> DENTRY_SIZE_BITS; - - err = ffsReadDir(inode, &de); - if (err) { - /* at least we tried to read a sector - * move cpos to next sector position (should be aligned) - */ - if (err == -EIO) { - cpos += 1 << p_bd->sector_size_bits; - cpos &= ~((1 << p_bd->sector_size_bits) - 1); - } - - goto end_of_dir; - } - - cpos = EXFAT_I(inode)->fid.rwoffset << DENTRY_SIZE_BITS; - - if (!de.Name[0]) - goto end_of_dir; - - if (!memcmp(de.ShortName, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH)) { - inum = inode->i_ino; - } else if (!memcmp(de.ShortName, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH)) { - inum = parent_ino(filp->f_path.dentry); - } else { - loff_t i_pos = ((loff_t)EXFAT_I(inode)->fid.start_clu << 32) | - ((EXFAT_I(inode)->fid.rwoffset - 1) & 0xffffffff); - struct inode *tmp = exfat_iget(sb, i_pos); - - if (tmp) { - inum = tmp->i_ino; - iput(tmp); - } else { - inum = iunique(sb, EXFAT_ROOT_INO); - } - } - - if (!dir_emit(ctx, de.Name, strlen(de.Name), inum, - (de.Attr & ATTR_SUBDIR) ? DT_DIR : DT_REG)) - goto out; - - ctx->pos = cpos; - goto get_new; - -end_of_dir: - ctx->pos = cpos; -out: - __unlock_super(sb); - return err; -} - -static int exfat_ioctl_volume_id(struct inode *dir) -{ - struct super_block *sb = dir->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct fs_info_t *p_fs = &sbi->fs_info; - - return p_fs->vol_id; -} - -static long exfat_generic_ioctl(struct file *filp, unsigned int cmd, - unsigned long arg) -{ - struct inode *inode = filp->f_path.dentry->d_inode; -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - unsigned int flags; -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - - switch (cmd) { - case EXFAT_IOCTL_GET_VOLUME_ID: - return exfat_ioctl_volume_id(inode); -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - case EXFAT_IOC_GET_DEBUGFLAGS: { - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - flags = sbi->debug_flags; - return put_user(flags, (int __user *)arg); - } - case EXFAT_IOC_SET_DEBUGFLAGS: { - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if (get_user(flags, (int __user *)arg)) - return -EFAULT; - - __lock_super(sb); - sbi->debug_flags = flags; - __unlock_super(sb); - - return 0; - } -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - default: - return -ENOTTY; /* Inappropriate ioctl for device */ - } -} - -static const struct file_operations exfat_dir_operations = { - .llseek = generic_file_llseek, - .read = generic_read_dir, - .iterate = exfat_readdir, - .unlocked_ioctl = exfat_generic_ioctl, - .fsync = generic_file_fsync, -}; - -static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, - bool excl) -{ - struct super_block *sb = dir->i_sb; - struct timespec64 curtime; - struct inode *inode; - struct file_id_t fid; - loff_t i_pos; - int err; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, FM_REGULAR, &fid); - if (err) - goto out; - - INC_IVERSION(dir); - curtime = current_time(dir); - dir->i_ctime = curtime; - dir->i_mtime = curtime; - dir->i_atime = curtime; - if (IS_DIRSYNC(dir)) - (void)exfat_sync_inode(dir); - else - mark_inode_dirty(dir); - - i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff); - - inode = exfat_build_inode(sb, &fid, i_pos); - if (IS_ERR(inode)) { - err = PTR_ERR(inode); - goto out; - } - INC_IVERSION(inode); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - inode->i_ctime = curtime; - /* - * timestamp is already written, so mark_inode_dirty() is unnecessary. - */ - - dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode); - d_instantiate(dentry, inode); - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_find(struct inode *dir, struct qstr *qname, - struct file_id_t *fid) -{ - int err; - - if (qname->len == 0) - return -ENOENT; - - err = ffsLookupFile(dir, (u8 *)qname->name, fid); - if (err) - return -ENOENT; - - return 0; -} - -static int exfat_d_anon_disconn(struct dentry *dentry) -{ - return IS_ROOT(dentry) && (dentry->d_flags & DCACHE_DISCONNECTED); -} - -static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry, - unsigned int flags) -{ - struct super_block *sb = dir->i_sb; - struct inode *inode; - struct dentry *alias; - int err; - struct file_id_t fid; - loff_t i_pos; - u64 ret; - mode_t i_mode; - - __lock_super(sb); - pr_debug("%s entered\n", __func__); - err = exfat_find(dir, &dentry->d_name, &fid); - if (err) { - if (err == -ENOENT) { - inode = NULL; - goto out; - } - goto error; - } - - i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff); - inode = exfat_build_inode(sb, &fid, i_pos); - if (IS_ERR(inode)) { - err = PTR_ERR(inode); - goto error; - } - - i_mode = inode->i_mode; - if (S_ISLNK(i_mode) && !EXFAT_I(inode)->target) { - EXFAT_I(inode)->target = kmalloc(i_size_read(inode) + 1, - GFP_KERNEL); - if (!EXFAT_I(inode)->target) { - err = -ENOMEM; - goto error; - } - ffsReadFile(dir, &fid, EXFAT_I(inode)->target, - i_size_read(inode), &ret); - *(EXFAT_I(inode)->target + i_size_read(inode)) = '\0'; - } - - alias = d_find_alias(inode); - if (alias && !exfat_d_anon_disconn(alias)) { - BUG_ON(d_unhashed(alias)); - if (!S_ISDIR(i_mode)) - d_move(alias, dentry); - iput(inode); - __unlock_super(sb); - pr_debug("%s exited 1\n", __func__); - return alias; - } - dput(alias); -out: - __unlock_super(sb); - dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode); - dentry = d_splice_alias(inode, dentry); - if (dentry) - dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode); - pr_debug("%s exited 2\n", __func__); - return dentry; - -error: - __unlock_super(sb); - pr_debug("%s exited 3\n", __func__); - return ERR_PTR(err); -} - -static inline unsigned long exfat_hash(loff_t i_pos) -{ - return hash_32(i_pos, EXFAT_HASH_BITS); -} - -static void exfat_attach(struct inode *inode, loff_t i_pos) -{ - struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb); - struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos); - - spin_lock(&sbi->inode_hash_lock); - EXFAT_I(inode)->i_pos = i_pos; - hlist_add_head(&EXFAT_I(inode)->i_hash_fat, head); - spin_unlock(&sbi->inode_hash_lock); -} - -static void exfat_detach(struct inode *inode) -{ - struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb); - - spin_lock(&sbi->inode_hash_lock); - hlist_del_init(&EXFAT_I(inode)->i_hash_fat); - EXFAT_I(inode)->i_pos = 0; - spin_unlock(&sbi->inode_hash_lock); -} - -static int exfat_unlink(struct inode *dir, struct dentry *dentry) -{ - struct inode *inode = dentry->d_inode; - struct super_block *sb = dir->i_sb; - struct timespec64 curtime; - int err; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - EXFAT_I(inode)->fid.size = i_size_read(inode); - - err = ffsRemoveFile(dir, &(EXFAT_I(inode)->fid)); - if (err) - goto out; - - INC_IVERSION(dir); - curtime = current_time(dir); - dir->i_mtime = curtime; - dir->i_atime = curtime; - if (IS_DIRSYNC(dir)) - (void)exfat_sync_inode(dir); - else - mark_inode_dirty(dir); - - clear_nlink(inode); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - exfat_detach(inode); - remove_inode_hash(inode); - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_symlink(struct inode *dir, struct dentry *dentry, - const char *target) -{ - struct super_block *sb = dir->i_sb; - struct timespec64 curtime; - struct inode *inode; - struct file_id_t fid; - loff_t i_pos; - int err; - u64 len = (u64)strlen(target); - u64 ret; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - err = ffsCreateFile(dir, (u8 *)dentry->d_name.name, FM_SYMLINK, &fid); - if (err) - goto out; - - - err = ffsWriteFile(dir, &fid, (char *)target, len, &ret); - - if (err) { - ffsRemoveFile(dir, &fid); - goto out; - } - - INC_IVERSION(dir); - curtime = current_time(dir); - dir->i_ctime = curtime; - dir->i_mtime = curtime; - dir->i_atime = curtime; - if (IS_DIRSYNC(dir)) - (void)exfat_sync_inode(dir); - else - mark_inode_dirty(dir); - - i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff); - - inode = exfat_build_inode(sb, &fid, i_pos); - if (IS_ERR(inode)) { - err = PTR_ERR(inode); - goto out; - } - INC_IVERSION(inode); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - inode->i_ctime = curtime; - /* timestamp is already written, so mark_inode_dirty() is unneeded. */ - - EXFAT_I(inode)->target = kmemdup(target, len + 1, GFP_KERNEL); - if (!EXFAT_I(inode)->target) { - err = -ENOMEM; - goto out; - } - - dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode); - d_instantiate(dentry, inode); - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) -{ - struct super_block *sb = dir->i_sb; - struct timespec64 curtime; - struct inode *inode; - struct file_id_t fid; - loff_t i_pos; - int err; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - err = ffsCreateDir(dir, (u8 *)dentry->d_name.name, &fid); - if (err) - goto out; - - INC_IVERSION(dir); - curtime = current_time(dir); - dir->i_ctime = curtime; - dir->i_mtime = curtime; - dir->i_atime = curtime; - if (IS_DIRSYNC(dir)) - (void)exfat_sync_inode(dir); - else - mark_inode_dirty(dir); - inc_nlink(dir); - - i_pos = ((loff_t)fid.dir.dir << 32) | (fid.entry & 0xffffffff); - - inode = exfat_build_inode(sb, &fid, i_pos); - if (IS_ERR(inode)) { - err = PTR_ERR(inode); - goto out; - } - INC_IVERSION(inode); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - inode->i_ctime = curtime; - /* timestamp is already written, so mark_inode_dirty() is unneeded. */ - - dentry->d_time = GET_IVERSION(dentry->d_parent->d_inode); - d_instantiate(dentry, inode); - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_rmdir(struct inode *dir, struct dentry *dentry) -{ - struct inode *inode = dentry->d_inode; - struct super_block *sb = dir->i_sb; - struct timespec64 curtime; - int err; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - EXFAT_I(inode)->fid.size = i_size_read(inode); - - err = ffsRemoveDir(dir, &(EXFAT_I(inode)->fid)); - if (err) - goto out; - - INC_IVERSION(dir); - curtime = current_time(dir); - dir->i_mtime = curtime; - dir->i_atime = curtime; - if (IS_DIRSYNC(dir)) - (void)exfat_sync_inode(dir); - else - mark_inode_dirty(dir); - drop_nlink(dir); - - clear_nlink(inode); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - exfat_detach(inode); - remove_inode_hash(inode); - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry, - unsigned int flags) -{ - struct inode *old_inode, *new_inode; - struct super_block *sb = old_dir->i_sb; - struct timespec64 curtime; - loff_t i_pos; - int err; - - if (flags) - return -EINVAL; - - __lock_super(sb); - - pr_debug("%s entered\n", __func__); - - old_inode = old_dentry->d_inode; - new_inode = new_dentry->d_inode; - - EXFAT_I(old_inode)->fid.size = i_size_read(old_inode); - - err = ffsMoveFile(old_dir, &(EXFAT_I(old_inode)->fid), new_dir, - new_dentry); - if (err) - goto out; - - INC_IVERSION(new_dir); - curtime = current_time(new_dir); - new_dir->i_ctime = curtime; - new_dir->i_mtime = curtime; - new_dir->i_atime = curtime; - - if (IS_DIRSYNC(new_dir)) - (void)exfat_sync_inode(new_dir); - else - mark_inode_dirty(new_dir); - - i_pos = ((loff_t)EXFAT_I(old_inode)->fid.dir.dir << 32) | - (EXFAT_I(old_inode)->fid.entry & 0xffffffff); - - exfat_detach(old_inode); - exfat_attach(old_inode, i_pos); - if (IS_DIRSYNC(new_dir)) - (void)exfat_sync_inode(old_inode); - else - mark_inode_dirty(old_inode); - - if ((S_ISDIR(old_inode->i_mode)) && (old_dir != new_dir)) { - drop_nlink(old_dir); - if (!new_inode) - inc_nlink(new_dir); - } - INC_IVERSION(old_dir); - curtime = current_time(old_dir); - old_dir->i_ctime = curtime; - old_dir->i_mtime = curtime; - if (IS_DIRSYNC(old_dir)) - (void)exfat_sync_inode(old_dir); - else - mark_inode_dirty(old_dir); - - if (new_inode) { - exfat_detach(new_inode); - drop_nlink(new_inode); - if (S_ISDIR(new_inode->i_mode)) - drop_nlink(new_inode); - new_inode->i_ctime = current_time(new_inode); - } - -out: - __unlock_super(sb); - pr_debug("%s exited\n", __func__); - return err; -} - -static int exfat_cont_expand(struct inode *inode, loff_t size) -{ - struct address_space *mapping = inode->i_mapping; - loff_t start = i_size_read(inode), count = size - i_size_read(inode); - struct timespec64 curtime; - int err, err2; - - err = generic_cont_expand_simple(inode, size); - if (err != 0) - return err; - - curtime = current_time(inode); - inode->i_ctime = curtime; - inode->i_mtime = curtime; - mark_inode_dirty(inode); - - if (IS_SYNC(inode)) { - err = filemap_fdatawrite_range(mapping, start, - start + count - 1); - err2 = sync_mapping_buffers(mapping); - err = (err) ? (err) : (err2); - err2 = write_inode_now(inode, 1); - err = (err) ? (err) : (err2); - if (!err) - err = filemap_fdatawait_range(mapping, start, - start + count - 1); - } - return err; -} - -static int exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode) -{ - mode_t allow_utime = sbi->options.allow_utime; - - if (!uid_eq(current_fsuid(), inode->i_uid)) { - if (in_group_p(inode->i_gid)) - allow_utime >>= 3; - if (allow_utime & MAY_WRITE) - return 1; - } - - /* use a default check */ - return 0; -} - -static int exfat_sanitize_mode(const struct exfat_sb_info *sbi, - struct inode *inode, umode_t *mode_ptr) -{ - mode_t i_mode, mask, perm; - - i_mode = inode->i_mode; - - if (S_ISREG(i_mode) || S_ISLNK(i_mode)) - mask = sbi->options.fs_fmask; - else - mask = sbi->options.fs_dmask; - - perm = *mode_ptr & ~(S_IFMT | mask); - - /* Of the r and x bits, all (subject to umask) must be present.*/ - if ((perm & 0555) != (i_mode & 0555)) - return -EPERM; - - if (exfat_mode_can_hold_ro(inode)) { - /* - * Of the w bits, either all (subject to umask) or none must be - * present. - */ - if ((perm & 0222) && ((perm & 0222) != (0222 & ~mask))) - return -EPERM; - } else { - /* - * If exfat_mode_can_hold_ro(inode) is false, can't change w - * bits. - */ - if ((perm & 0222) != (0222 & ~mask)) - return -EPERM; - } - - *mode_ptr &= S_IFMT | perm; - - return 0; -} - -static void exfat_truncate(struct inode *inode, loff_t old_size) -{ - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct fs_info_t *p_fs = &sbi->fs_info; - struct timespec64 curtime; - int err; - - __lock_super(sb); - - /* - * This protects against truncating a file bigger than it was then - * trying to write into the hole. - */ - if (EXFAT_I(inode)->mmu_private > i_size_read(inode)) - EXFAT_I(inode)->mmu_private = i_size_read(inode); - - if (EXFAT_I(inode)->fid.start_clu == 0) - goto out; - - err = ffsTruncateFile(inode, old_size, i_size_read(inode)); - if (err) - goto out; - - curtime = current_time(inode); - inode->i_ctime = curtime; - inode->i_mtime = curtime; - if (IS_DIRSYNC(inode)) - (void)exfat_sync_inode(inode); - else - mark_inode_dirty(inode); - - inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1)) & - ~((loff_t)p_fs->cluster_size - 1)) >> 9; -out: - __unlock_super(sb); -} - -static int exfat_setattr(struct dentry *dentry, struct iattr *attr) -{ - struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb); - struct inode *inode = dentry->d_inode; - unsigned int ia_valid; - int error; - loff_t old_size; - - pr_debug("%s entered\n", __func__); - - if ((attr->ia_valid & ATTR_SIZE) && - attr->ia_size > i_size_read(inode)) { - error = exfat_cont_expand(inode, attr->ia_size); - if (error || attr->ia_valid == ATTR_SIZE) - return error; - attr->ia_valid &= ~ATTR_SIZE; - } - - ia_valid = attr->ia_valid; - - if ((ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) && - exfat_allow_set_time(sbi, inode)) { - attr->ia_valid &= ~(ATTR_MTIME_SET | - ATTR_ATIME_SET | - ATTR_TIMES_SET); - } - - error = setattr_prepare(dentry, attr); - attr->ia_valid = ia_valid; - if (error) - return error; - - if (((attr->ia_valid & ATTR_UID) && - (!uid_eq(attr->ia_uid, sbi->options.fs_uid))) || - ((attr->ia_valid & ATTR_GID) && - (!gid_eq(attr->ia_gid, sbi->options.fs_gid))) || - ((attr->ia_valid & ATTR_MODE) && - (attr->ia_mode & ~(S_IFREG | S_IFLNK | S_IFDIR | 0777)))) { - return -EPERM; - } - - /* - * We don't return -EPERM here. Yes, strange, but this is too - * old behavior. - */ - if (attr->ia_valid & ATTR_MODE) { - if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0) - attr->ia_valid &= ~ATTR_MODE; - } - - EXFAT_I(inode)->fid.size = i_size_read(inode); - - if (attr->ia_valid & ATTR_SIZE) { - old_size = i_size_read(inode); - down_write(&EXFAT_I(inode)->truncate_lock); - truncate_setsize(inode, attr->ia_size); - exfat_truncate(inode, old_size); - up_write(&EXFAT_I(inode)->truncate_lock); - } - setattr_copy(inode, attr); - mark_inode_dirty(inode); - - pr_debug("%s exited\n", __func__); - return error; -} - -static int exfat_getattr(const struct path *path, struct kstat *stat, - u32 request_mask, unsigned int flags) -{ - struct inode *inode = path->dentry->d_inode; - - pr_debug("%s entered\n", __func__); - - generic_fillattr(inode, stat); - stat->blksize = EXFAT_SB(inode->i_sb)->fs_info.cluster_size; - - pr_debug("%s exited\n", __func__); - return 0; -} - -static const struct inode_operations exfat_dir_inode_operations = { - .create = exfat_create, - .lookup = exfat_lookup, - .unlink = exfat_unlink, - .symlink = exfat_symlink, - .mkdir = exfat_mkdir, - .rmdir = exfat_rmdir, - .rename = exfat_rename, - .setattr = exfat_setattr, - .getattr = exfat_getattr, -}; - -/*======================================================================*/ -/* File Operations */ -/*======================================================================*/ -static const char *exfat_get_link(struct dentry *dentry, struct inode *inode, - struct delayed_call *done) -{ - struct exfat_inode_info *ei = EXFAT_I(inode); - - if (ei->target) { - char *cookie = ei->target; - - if (cookie) - return (char *)(ei->target); - } - return NULL; -} - -static const struct inode_operations exfat_symlink_inode_operations = { - .get_link = exfat_get_link, -}; - -static int exfat_file_release(struct inode *inode, struct file *filp) -{ - struct super_block *sb = inode->i_sb; - - EXFAT_I(inode)->fid.size = i_size_read(inode); - ffsSyncVol(sb, false); - return 0; -} - -static const struct file_operations exfat_file_operations = { - .llseek = generic_file_llseek, - .read_iter = generic_file_read_iter, - .write_iter = generic_file_write_iter, - .mmap = generic_file_mmap, - .release = exfat_file_release, - .unlocked_ioctl = exfat_generic_ioctl, - .fsync = generic_file_fsync, - .splice_read = generic_file_splice_read, -}; - -static const struct inode_operations exfat_file_inode_operations = { - .setattr = exfat_setattr, - .getattr = exfat_getattr, -}; - -/*======================================================================*/ -/* Address Space Operations */ -/*======================================================================*/ - -static int exfat_bmap(struct inode *inode, sector_t sector, sector_t *phys, - unsigned long *mapped_blocks, int *create) -{ - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct fs_info_t *p_fs = &sbi->fs_info; - const unsigned long blocksize = sb->s_blocksize; - const unsigned char blocksize_bits = sb->s_blocksize_bits; - sector_t last_block; - int err, clu_offset, sec_offset; - unsigned int cluster; - - *phys = 0; - *mapped_blocks = 0; - - last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits; - if (sector >= last_block) { - if (*create == 0) - return 0; - } else { - *create = 0; - } - - /* cluster offset */ - clu_offset = sector >> p_fs->sectors_per_clu_bits; - - /* sector offset in cluster */ - sec_offset = sector & (p_fs->sectors_per_clu - 1); - - EXFAT_I(inode)->fid.size = i_size_read(inode); - - err = ffsMapCluster(inode, clu_offset, &cluster); - - if (!err && (cluster != CLUSTER_32(~0))) { - *phys = START_SECTOR(cluster) + sec_offset; - *mapped_blocks = p_fs->sectors_per_clu - sec_offset; - } - - return 0; -} - -static int exfat_get_block(struct inode *inode, sector_t iblock, - struct buffer_head *bh_result, int create) -{ - struct super_block *sb = inode->i_sb; - unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits; - int err; - unsigned long mapped_blocks; - sector_t phys; - - __lock_super(sb); - - err = exfat_bmap(inode, iblock, &phys, &mapped_blocks, &create); - if (err) { - __unlock_super(sb); - return err; - } - - if (phys) { - max_blocks = min(mapped_blocks, max_blocks); - if (create) { - EXFAT_I(inode)->mmu_private += max_blocks << - sb->s_blocksize_bits; - set_buffer_new(bh_result); - } - map_bh(bh_result, sb, phys); - } - - bh_result->b_size = max_blocks << sb->s_blocksize_bits; - __unlock_super(sb); - - return 0; -} - -static int exfat_readpage(struct file *file, struct page *page) -{ - return mpage_readpage(page, exfat_get_block); -} - -static int exfat_readpages(struct file *file, struct address_space *mapping, - struct list_head *pages, unsigned int nr_pages) -{ - return mpage_readpages(mapping, pages, nr_pages, exfat_get_block); -} - -static int exfat_writepage(struct page *page, struct writeback_control *wbc) -{ - return block_write_full_page(page, exfat_get_block, wbc); -} - -static int exfat_writepages(struct address_space *mapping, - struct writeback_control *wbc) -{ - return mpage_writepages(mapping, wbc, exfat_get_block); -} - -static void exfat_write_failed(struct address_space *mapping, loff_t to) -{ - struct inode *inode = mapping->host; - - if (to > i_size_read(inode)) { - truncate_pagecache(inode, i_size_read(inode)); - EXFAT_I(inode)->fid.size = i_size_read(inode); - exfat_truncate(inode, i_size_read(inode)); - } -} - -static int exfat_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned int len, unsigned int flags, - struct page **pagep, void **fsdata) -{ - int ret; - - *pagep = NULL; - ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata, - exfat_get_block, - &EXFAT_I(mapping->host)->mmu_private); - - if (ret < 0) - exfat_write_failed(mapping, pos + len); - return ret; -} - -static int exfat_write_end(struct file *file, struct address_space *mapping, - loff_t pos, unsigned int len, unsigned int copied, - struct page *pagep, void *fsdata) -{ - struct inode *inode = mapping->host; - struct file_id_t *fid = &(EXFAT_I(inode)->fid); - struct timespec64 curtime; - int err; - - err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata); - - if (err < len) - exfat_write_failed(mapping, pos + len); - - if (!(err < 0) && !(fid->attr & ATTR_ARCHIVE)) { - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_ctime = curtime; - fid->attr |= ATTR_ARCHIVE; - mark_inode_dirty(inode); - } - return err; -} - -static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter) -{ - struct inode *inode = iocb->ki_filp->f_mapping->host; - struct address_space *mapping = iocb->ki_filp->f_mapping; - ssize_t ret; - int rw; - - rw = iov_iter_rw(iter); - - if (rw == WRITE) { - if (EXFAT_I(inode)->mmu_private < iov_iter_count(iter)) - return 0; - } - ret = blockdev_direct_IO(iocb, inode, iter, exfat_get_block); - - if ((ret < 0) && (rw & WRITE)) - exfat_write_failed(mapping, iov_iter_count(iter)); - return ret; -} - -static sector_t _exfat_bmap(struct address_space *mapping, sector_t block) -{ - sector_t blocknr; - - /* exfat_get_cluster() assumes the requested blocknr isn't truncated. */ - down_read(&EXFAT_I(mapping->host)->truncate_lock); - blocknr = generic_block_bmap(mapping, block, exfat_get_block); - up_read(&EXFAT_I(mapping->host)->truncate_lock); - - return blocknr; -} - -static const struct address_space_operations exfat_aops = { - .readpage = exfat_readpage, - .readpages = exfat_readpages, - .writepage = exfat_writepage, - .writepages = exfat_writepages, - .write_begin = exfat_write_begin, - .write_end = exfat_write_end, - .direct_IO = exfat_direct_IO, - .bmap = _exfat_bmap -}; - -/*======================================================================*/ -/* Super Operations */ -/*======================================================================*/ - -static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct exfat_inode_info *info; - struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos); - struct inode *inode = NULL; - - spin_lock(&sbi->inode_hash_lock); - hlist_for_each_entry(info, head, i_hash_fat) { - BUG_ON(info->vfs_inode.i_sb != sb); - - if (i_pos != info->i_pos) - continue; - inode = igrab(&info->vfs_inode); - if (inode) - break; - } - spin_unlock(&sbi->inode_hash_lock); - return inode; -} - -/* doesn't deal with root inode */ -static int exfat_fill_inode(struct inode *inode, struct file_id_t *fid) -{ - struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb); - struct fs_info_t *p_fs = &sbi->fs_info; - struct dir_entry_t info; - - memcpy(&(EXFAT_I(inode)->fid), fid, sizeof(struct file_id_t)); - - ffsReadStat(inode, &info); - - EXFAT_I(inode)->i_pos = 0; - EXFAT_I(inode)->target = NULL; - inode->i_uid = sbi->options.fs_uid; - inode->i_gid = sbi->options.fs_gid; - INC_IVERSION(inode); - inode->i_generation = prandom_u32(); - - if (info.Attr & ATTR_SUBDIR) { /* directory */ - inode->i_generation &= ~1; - inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777); - inode->i_op = &exfat_dir_inode_operations; - inode->i_fop = &exfat_dir_operations; - - i_size_write(inode, info.Size); - EXFAT_I(inode)->mmu_private = i_size_read(inode); - set_nlink(inode, info.NumSubdirs); - } else if (info.Attr & ATTR_SYMLINK) { /* symbolic link */ - inode->i_generation |= 1; - inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777); - inode->i_op = &exfat_symlink_inode_operations; - - i_size_write(inode, info.Size); - EXFAT_I(inode)->mmu_private = i_size_read(inode); - } else { /* regular file */ - inode->i_generation |= 1; - inode->i_mode = exfat_make_mode(sbi, info.Attr, 0777); - inode->i_op = &exfat_file_inode_operations; - inode->i_fop = &exfat_file_operations; - inode->i_mapping->a_ops = &exfat_aops; - inode->i_mapping->nrpages = 0; - - i_size_write(inode, info.Size); - EXFAT_I(inode)->mmu_private = i_size_read(inode); - } - exfat_save_attr(inode, info.Attr); - - inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1)) - & ~((loff_t)p_fs->cluster_size - 1)) >> 9; - - exfat_time_fat2unix(&inode->i_mtime, &info.ModifyTimestamp); - exfat_time_fat2unix(&inode->i_ctime, &info.CreateTimestamp); - exfat_time_fat2unix(&inode->i_atime, &info.AccessTimestamp); - - return 0; -} - -static struct inode *exfat_build_inode(struct super_block *sb, - struct file_id_t *fid, loff_t i_pos) -{ - struct inode *inode; - int err; - - inode = exfat_iget(sb, i_pos); - if (inode) - goto out; - inode = new_inode(sb); - if (!inode) { - inode = ERR_PTR(-ENOMEM); - goto out; - } - inode->i_ino = iunique(sb, EXFAT_ROOT_INO); - SET_IVERSION(inode, 1); - err = exfat_fill_inode(inode, fid); - if (err) { - iput(inode); - inode = ERR_PTR(err); - goto out; - } - exfat_attach(inode, i_pos); - insert_inode_hash(inode); -out: - return inode; -} - -static int exfat_sync_inode(struct inode *inode) -{ - return exfat_write_inode(inode, NULL); -} - -static struct inode *exfat_alloc_inode(struct super_block *sb) -{ - struct exfat_inode_info *ei; - - ei = kmem_cache_alloc(exfat_inode_cachep, GFP_NOFS); - if (!ei) - return NULL; - - init_rwsem(&ei->truncate_lock); - - return &ei->vfs_inode; -} - -static void exfat_destroy_inode(struct inode *inode) -{ - kfree(EXFAT_I(inode)->target); - EXFAT_I(inode)->target = NULL; - - kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode)); -} - -static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc) -{ - struct dir_entry_t info; - - if (inode->i_ino == EXFAT_ROOT_INO) - return 0; - - info.Attr = exfat_make_attr(inode); - info.Size = i_size_read(inode); - - exfat_time_unix2fat(&inode->i_mtime, &info.ModifyTimestamp); - exfat_time_unix2fat(&inode->i_ctime, &info.CreateTimestamp); - exfat_time_unix2fat(&inode->i_atime, &info.AccessTimestamp); - - ffsWriteStat(inode, &info); - - return 0; -} - -static void exfat_evict_inode(struct inode *inode) -{ - truncate_inode_pages(&inode->i_data, 0); - - if (!inode->i_nlink) - i_size_write(inode, 0); - invalidate_inode_buffers(inode); - clear_inode(inode); - exfat_detach(inode); - - remove_inode_hash(inode); -} - -static void exfat_free_super(struct exfat_sb_info *sbi) -{ - if (sbi->nls_disk) - unload_nls(sbi->nls_disk); - if (sbi->nls_io) - unload_nls(sbi->nls_io); - if (sbi->options.iocharset != exfat_default_iocharset) - kfree(sbi->options.iocharset); - /* mutex_init is in exfat_fill_super function. only for 3.7+ */ - mutex_destroy(&sbi->s_lock); - kvfree(sbi); -} - -static void exfat_put_super(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - - if (__is_sb_dirty(sb)) - exfat_write_super(sb); - - ffsUmountVol(sb); - - sb->s_fs_info = NULL; - exfat_free_super(sbi); -} - -static void exfat_write_super(struct super_block *sb) -{ - __lock_super(sb); - - __set_sb_clean(sb); - - if (!sb_rdonly(sb)) - ffsSyncVol(sb, true); - - __unlock_super(sb); -} - -static int exfat_sync_fs(struct super_block *sb, int wait) -{ - int err = 0; - - if (__is_sb_dirty(sb)) { - __lock_super(sb); - __set_sb_clean(sb); - err = ffsSyncVol(sb, true); - __unlock_super(sb); - } - - return err; -} - -static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf) -{ - struct super_block *sb = dentry->d_sb; - u64 id = huge_encode_dev(sb->s_bdev->bd_dev); - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - struct vol_info_t info; - - if (p_fs->used_clusters == UINT_MAX) { - if (ffsGetVolInfo(sb, &info) == -EIO) - return -EIO; - - } else { - info.FatType = p_fs->vol_type; - info.ClusterSize = p_fs->cluster_size; - info.NumClusters = p_fs->num_clusters - 2; - info.UsedClusters = p_fs->used_clusters; - info.FreeClusters = info.NumClusters - info.UsedClusters; - - if (p_fs->dev_ejected) - pr_info("[EXFAT] statfs on device that is ejected\n"); - } - - buf->f_type = sb->s_magic; - buf->f_bsize = info.ClusterSize; - buf->f_blocks = info.NumClusters; - buf->f_bfree = info.FreeClusters; - buf->f_bavail = info.FreeClusters; - buf->f_fsid.val[0] = (u32)id; - buf->f_fsid.val[1] = (u32)(id >> 32); - buf->f_namelen = 260; - - return 0; -} - -static int exfat_remount(struct super_block *sb, int *flags, char *data) -{ - *flags |= SB_NODIRATIME; - return 0; -} - -static int exfat_show_options(struct seq_file *m, struct dentry *root) -{ - struct exfat_sb_info *sbi = EXFAT_SB(root->d_sb); - struct exfat_mount_options *opts = &sbi->options; - - if (__kuid_val(opts->fs_uid)) - seq_printf(m, ",uid=%u", __kuid_val(opts->fs_uid)); - if (__kgid_val(opts->fs_gid)) - seq_printf(m, ",gid=%u", __kgid_val(opts->fs_gid)); - seq_printf(m, ",fmask=%04o", opts->fs_fmask); - seq_printf(m, ",dmask=%04o", opts->fs_dmask); - if (opts->allow_utime) - seq_printf(m, ",allow_utime=%04o", opts->allow_utime); - if (sbi->nls_disk) - seq_printf(m, ",codepage=%s", sbi->nls_disk->charset); - if (sbi->nls_io) - seq_printf(m, ",iocharset=%s", sbi->nls_io->charset); - seq_printf(m, ",namecase=%u", opts->casesensitive); - if (opts->errors == EXFAT_ERRORS_CONT) - seq_puts(m, ",errors=continue"); - else if (opts->errors == EXFAT_ERRORS_PANIC) - seq_puts(m, ",errors=panic"); - else - seq_puts(m, ",errors=remount-ro"); -#ifdef CONFIG_STAGING_EXFAT_DISCARD - if (opts->discard) - seq_puts(m, ",discard"); -#endif - return 0; -} - -static const struct super_operations exfat_sops = { - .alloc_inode = exfat_alloc_inode, - .destroy_inode = exfat_destroy_inode, - .write_inode = exfat_write_inode, - .evict_inode = exfat_evict_inode, - .put_super = exfat_put_super, - .sync_fs = exfat_sync_fs, - .statfs = exfat_statfs, - .remount_fs = exfat_remount, - .show_options = exfat_show_options, -}; - -/*======================================================================*/ -/* Export Operations */ -/*======================================================================*/ - -static struct inode *exfat_nfs_get_inode(struct super_block *sb, u64 ino, - u32 generation) -{ - struct inode *inode = NULL; - - if (ino < EXFAT_ROOT_INO) - return inode; - inode = ilookup(sb, ino); - - if (inode && generation && (inode->i_generation != generation)) { - iput(inode); - inode = NULL; - } - - return inode; -} - -static struct dentry *exfat_fh_to_dentry(struct super_block *sb, - struct fid *fid, int fh_len, - int fh_type) -{ - return generic_fh_to_dentry(sb, fid, fh_len, fh_type, - exfat_nfs_get_inode); -} - -static struct dentry *exfat_fh_to_parent(struct super_block *sb, - struct fid *fid, int fh_len, - int fh_type) -{ - return generic_fh_to_parent(sb, fid, fh_len, fh_type, - exfat_nfs_get_inode); -} - -static const struct export_operations exfat_export_ops = { - .fh_to_dentry = exfat_fh_to_dentry, - .fh_to_parent = exfat_fh_to_parent, -}; - -/*======================================================================*/ -/* Super Block Read Operations */ -/*======================================================================*/ - -enum { - Opt_uid, - Opt_gid, - Opt_umask, - Opt_dmask, - Opt_fmask, - Opt_allow_utime, - Opt_codepage, - Opt_charset, - Opt_namecase, - Opt_debug, - Opt_err_cont, - Opt_err_panic, - Opt_err_ro, - Opt_utf8_hack, - Opt_err, -#ifdef CONFIG_STAGING_EXFAT_DISCARD - Opt_discard, -#endif /* EXFAT_CONFIG_DISCARD */ -}; - -static const match_table_t exfat_tokens = { - {Opt_uid, "uid=%u"}, - {Opt_gid, "gid=%u"}, - {Opt_umask, "umask=%o"}, - {Opt_dmask, "dmask=%o"}, - {Opt_fmask, "fmask=%o"}, - {Opt_allow_utime, "allow_utime=%o"}, - {Opt_codepage, "codepage=%u"}, - {Opt_charset, "iocharset=%s"}, - {Opt_namecase, "namecase=%u"}, - {Opt_debug, "debug"}, - {Opt_err_cont, "errors=continue"}, - {Opt_err_panic, "errors=panic"}, - {Opt_err_ro, "errors=remount-ro"}, - {Opt_utf8_hack, "utf8"}, -#ifdef CONFIG_STAGING_EXFAT_DISCARD - {Opt_discard, "discard"}, -#endif /* CONFIG_STAGING_EXFAT_DISCARD */ - {Opt_err, NULL} -}; - -static int parse_options(char *options, int silent, int *debug, - struct exfat_mount_options *opts) -{ - char *p; - substring_t args[MAX_OPT_ARGS]; - int option; - char *iocharset; - - opts->fs_uid = current_uid(); - opts->fs_gid = current_gid(); - opts->fs_fmask = current->fs->umask; - opts->fs_dmask = current->fs->umask; - opts->allow_utime = U16_MAX; - opts->codepage = exfat_default_codepage; - opts->iocharset = exfat_default_iocharset; - opts->casesensitive = 0; - opts->errors = EXFAT_ERRORS_RO; -#ifdef CONFIG_STAGING_EXFAT_DISCARD - opts->discard = 0; -#endif - *debug = 0; - - if (!options) - goto out; - - while ((p = strsep(&options, ","))) { - int token; - - if (!*p) - continue; - - token = match_token(p, exfat_tokens, args); - switch (token) { - case Opt_uid: - if (match_int(&args[0], &option)) - return 0; - opts->fs_uid = KUIDT_INIT(option); - break; - case Opt_gid: - if (match_int(&args[0], &option)) - return 0; - opts->fs_gid = KGIDT_INIT(option); - break; - case Opt_umask: - case Opt_dmask: - case Opt_fmask: - if (match_octal(&args[0], &option)) - return 0; - if (token != Opt_dmask) - opts->fs_fmask = option; - if (token != Opt_fmask) - opts->fs_dmask = option; - break; - case Opt_allow_utime: - if (match_octal(&args[0], &option)) - return 0; - opts->allow_utime = option & 0022; - break; - case Opt_codepage: - if (match_int(&args[0], &option)) - return 0; - opts->codepage = option; - break; - case Opt_charset: - if (opts->iocharset != exfat_default_iocharset) - kfree(opts->iocharset); - iocharset = match_strdup(&args[0]); - if (!iocharset) - return -ENOMEM; - opts->iocharset = iocharset; - break; - case Opt_namecase: - if (match_int(&args[0], &option)) - return 0; - opts->casesensitive = option; - break; - case Opt_err_cont: - opts->errors = EXFAT_ERRORS_CONT; - break; - case Opt_err_panic: - opts->errors = EXFAT_ERRORS_PANIC; - break; - case Opt_err_ro: - opts->errors = EXFAT_ERRORS_RO; - break; - case Opt_debug: - *debug = 1; - break; -#ifdef CONFIG_STAGING_EXFAT_DISCARD - case Opt_discard: - opts->discard = 1; - break; -#endif /* CONFIG_STAGING_EXFAT_DISCARD */ - case Opt_utf8_hack: - break; - default: - if (!silent) - pr_err("[EXFAT] Unrecognized mount option %s or missing value\n", - p); - return -EINVAL; - } - } - -out: - if (opts->allow_utime == U16_MAX) - opts->allow_utime = ~opts->fs_dmask & 0022; - - return 0; -} - -static void exfat_hash_init(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - int i; - - spin_lock_init(&sbi->inode_hash_lock); - for (i = 0; i < EXFAT_HASH_SIZE; i++) - INIT_HLIST_HEAD(&sbi->inode_hashtable[i]); -} - -static int exfat_read_root(struct inode *inode) -{ - struct super_block *sb = inode->i_sb; - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct fs_info_t *p_fs = &sbi->fs_info; - struct timespec64 curtime; - struct dir_entry_t info; - - EXFAT_I(inode)->fid.dir.dir = p_fs->root_dir; - EXFAT_I(inode)->fid.dir.flags = 0x01; - EXFAT_I(inode)->fid.entry = -1; - EXFAT_I(inode)->fid.start_clu = p_fs->root_dir; - EXFAT_I(inode)->fid.flags = 0x01; - EXFAT_I(inode)->fid.type = TYPE_DIR; - EXFAT_I(inode)->fid.rwoffset = 0; - EXFAT_I(inode)->fid.hint_last_off = -1; - - EXFAT_I(inode)->target = NULL; - - ffsReadStat(inode, &info); - - inode->i_uid = sbi->options.fs_uid; - inode->i_gid = sbi->options.fs_gid; - INC_IVERSION(inode); - inode->i_generation = 0; - inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, 0777); - inode->i_op = &exfat_dir_inode_operations; - inode->i_fop = &exfat_dir_operations; - - i_size_write(inode, info.Size); - inode->i_blocks = ((i_size_read(inode) + (p_fs->cluster_size - 1)) - & ~((loff_t)p_fs->cluster_size - 1)) >> 9; - EXFAT_I(inode)->i_pos = ((loff_t)p_fs->root_dir << 32) | 0xffffffff; - EXFAT_I(inode)->mmu_private = i_size_read(inode); - - exfat_save_attr(inode, ATTR_SUBDIR); - curtime = current_time(inode); - inode->i_mtime = curtime; - inode->i_atime = curtime; - inode->i_ctime = curtime; - set_nlink(inode, info.NumSubdirs + 2); - - return 0; -} - -static void setup_dops(struct super_block *sb) -{ - if (EXFAT_SB(sb)->options.casesensitive == 0) - sb->s_d_op = &exfat_ci_dentry_ops; - else - sb->s_d_op = &exfat_dentry_ops; -} - -static int exfat_fill_super(struct super_block *sb, void *data, int silent) -{ - struct inode *root_inode = NULL; - struct exfat_sb_info *sbi; - int debug, ret; - long error; - - /* - * GFP_KERNEL is ok here, because while we do hold the - * supeblock lock, memory pressure can't call back into - * the filesystem, since we're only just about to mount - * it and have no inodes etc active! - */ - sbi = kvzalloc(sizeof(*sbi), GFP_KERNEL); - if (!sbi) - return -ENOMEM; - mutex_init(&sbi->s_lock); - sb->s_fs_info = sbi; - sb->s_flags |= SB_NODIRATIME; - sb->s_magic = EXFAT_SUPER_MAGIC; - sb->s_op = &exfat_sops; - sb->s_export_op = &exfat_export_ops; - - error = parse_options(data, silent, &debug, &sbi->options); - if (error) - goto out_fail; - - setup_dops(sb); - - error = -EIO; - sb_min_blocksize(sb, 512); - sb->s_maxbytes = 0x7fffffffffffffffLL; /* maximum file size */ - - ret = ffsMountVol(sb); - if (ret) { - if (!silent) - pr_err("[EXFAT] ffsMountVol failed\n"); - - goto out_fail; - } - - /* set up enough so that it can read an inode */ - exfat_hash_init(sb); - - /* - * The low byte of FAT's first entry must have same value with - * media-field. But in real world, too many devices is - * writing wrong value. So, removed that validity check. - * - * if (FAT_FIRST_ENT(sb, media) != first) - */ - - sbi->nls_io = load_nls(sbi->options.iocharset); - - error = -ENOMEM; - root_inode = new_inode(sb); - if (!root_inode) - goto out_fail2; - root_inode->i_ino = EXFAT_ROOT_INO; - SET_IVERSION(root_inode, 1); - - error = exfat_read_root(root_inode); - if (error < 0) - goto out_fail2; - error = -ENOMEM; - exfat_attach(root_inode, EXFAT_I(root_inode)->i_pos); - insert_inode_hash(root_inode); - sb->s_root = d_make_root(root_inode); - if (!sb->s_root) { - pr_err("[EXFAT] Getting the root inode failed\n"); - goto out_fail2; - } - - return 0; - -out_fail2: - ffsUmountVol(sb); -out_fail: - if (root_inode) - iput(root_inode); - sb->s_fs_info = NULL; - exfat_free_super(sbi); - return error; -} - -static struct dentry *exfat_fs_mount(struct file_system_type *fs_type, - int flags, const char *dev_name, - void *data) -{ - return mount_bdev(fs_type, flags, dev_name, data, exfat_fill_super); -} - -static void init_once(void *foo) -{ - struct exfat_inode_info *ei = (struct exfat_inode_info *)foo; - - INIT_HLIST_NODE(&ei->i_hash_fat); - inode_init_once(&ei->vfs_inode); -} - -static int __init exfat_init_inodecache(void) -{ - exfat_inode_cachep = kmem_cache_create("exfat_inode_cache", - sizeof(struct exfat_inode_info), - 0, - (SLAB_RECLAIM_ACCOUNT | - SLAB_MEM_SPREAD), - init_once); - if (!exfat_inode_cachep) - return -ENOMEM; - return 0; -} - -static void __exit exfat_destroy_inodecache(void) -{ - /* - * Make sure all delayed rcu free inodes are flushed before we - * destroy cache. - */ - rcu_barrier(); - kmem_cache_destroy(exfat_inode_cachep); -} - -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG -static void exfat_debug_kill_sb(struct super_block *sb) -{ - struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct block_device *bdev = sb->s_bdev; - struct fs_info_t *p_fs = &(EXFAT_SB(sb)->fs_info); - - long flags; - - if (sbi) { - flags = sbi->debug_flags; - - if (flags & EXFAT_DEBUGFLAGS_INVALID_UMOUNT) { - /* - * invalidate_bdev drops all device cache include - * dirty. We use this to simulate device removal. - */ - mutex_lock(&p_fs->v_mutex); - exfat_fat_release_all(sb); - exfat_buf_release_all(sb); - mutex_unlock(&p_fs->v_mutex); - - invalidate_bdev(bdev); - } - } - - kill_block_super(sb); -} -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - -static struct file_system_type exfat_fs_type = { - .owner = THIS_MODULE, - .name = "exfat", - .mount = exfat_fs_mount, -#ifdef CONFIG_STAGING_EXFAT_KERNEL_DEBUG - .kill_sb = exfat_debug_kill_sb, -#else - .kill_sb = kill_block_super, -#endif /* CONFIG_STAGING_EXFAT_KERNEL_DEBUG */ - .fs_flags = FS_REQUIRES_DEV, -}; - -static int __init init_exfat(void) -{ - int err; - - BUILD_BUG_ON(sizeof(struct dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct dos_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct ext_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct file_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct strm_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct name_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct bmap_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct case_dentry_t) != DENTRY_SIZE); - BUILD_BUG_ON(sizeof(struct volm_dentry_t) != DENTRY_SIZE); - - pr_info("exFAT: Version %s\n", EXFAT_VERSION); - - err = exfat_init_inodecache(); - if (err) - return err; - - err = register_filesystem(&exfat_fs_type); - if (err) - return err; - - return 0; -} - -static void __exit exit_exfat(void) -{ - exfat_destroy_inodecache(); - unregister_filesystem(&exfat_fs_type); -} - -module_init(init_exfat); -module_exit(exit_exfat); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("exFAT Filesystem Driver"); -MODULE_ALIAS_FS("exfat"); diff --git a/drivers/staging/exfat/exfat_upcase.c b/drivers/staging/exfat/exfat_upcase.c deleted file mode 100644 index b91a1faa0e50..000000000000 --- a/drivers/staging/exfat/exfat_upcase.c +++ /dev/null @@ -1,740 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd. - */ - -#include <linux/types.h> -#include "exfat.h" - -const u8 uni_upcase[NUM_UPCASE << 1] = { - 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, - 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, - 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0B, 0x00, - 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, - 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0x00, - 0x14, 0x00, 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, - 0x18, 0x00, 0x19, 0x00, 0x1A, 0x00, 0x1B, 0x00, - 0x1C, 0x00, 0x1D, 0x00, 0x1E, 0x00, 0x1F, 0x00, - 0x20, 0x00, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, - 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, - 0x28, 0x00, 0x29, 0x00, 0x2A, 0x00, 0x2B, 0x00, - 0x2C, 0x00, 0x2D, 0x00, 0x2E, 0x00, 0x2F, 0x00, - 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, - 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, - 0x38, 0x00, 0x39, 0x00, 0x3A, 0x00, 0x3B, 0x00, - 0x3C, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x3F, 0x00, - 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, - 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00, - 0x48, 0x00, 0x49, 0x00, 0x4A, 0x00, 0x4B, 0x00, - 0x4C, 0x00, 0x4D, 0x00, 0x4E, 0x00, 0x4F, 0x00, - 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00, - 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00, - 0x58, 0x00, 0x59, 0x00, 0x5A, 0x00, 0x5B, 0x00, - 0x5C, 0x00, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00, - 0x60, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, - 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00, - 0x48, 0x00, 0x49, 0x00, 0x4A, 0x00, 0x4B, 0x00, - 0x4C, 0x00, 0x4D, 0x00, 0x4E, 0x00, 0x4F, 0x00, - 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00, - 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00, - 0x58, 0x00, 0x59, 0x00, 0x5A, 0x00, 0x7B, 0x00, - 0x7C, 0x00, 0x7D, 0x00, 0x7E, 0x00, 0x7F, 0x00, - 0x80, 0x00, 0x81, 0x00, 0x82, 0x00, 0x83, 0x00, - 0x84, 0x00, 0x85, 0x00, 0x86, 0x00, 0x87, 0x00, - 0x88, 0x00, 0x89, 0x00, 0x8A, 0x00, 0x8B, 0x00, - 0x8C, 0x00, 0x8D, 0x00, 0x8E, 0x00, 0x8F, 0x00, - 0x90, 0x00, 0x91, 0x00, 0x92, 0x00, 0x93, 0x00, - 0x94, 0x00, 0x95, 0x00, 0x96, 0x00, 0x97, 0x00, - 0x98, 0x00, 0x99, 0x00, 0x9A, 0x00, 0x9B, 0x00, - 0x9C, 0x00, 0x9D, 0x00, 0x9E, 0x00, 0x9F, 0x00, - 0xA0, 0x00, 0xA1, 0x00, 0xA2, 0x00, 0xA3, 0x00, - 0xA4, 0x00, 0xA5, 0x00, 0xA6, 0x00, 0xA7, 0x00, - 0xA8, 0x00, 0xA9, 0x00, 0xAA, 0x00, 0xAB, 0x00, - 0xAC, 0x00, 0xAD, 0x00, 0xAE, 0x00, 0xAF, 0x00, - 0xB0, 0x00, 0xB1, 0x00, 0xB2, 0x00, 0xB3, 0x00, - 0xB4, 0x00, 0xB5, 0x00, 0xB6, 0x00, 0xB7, 0x00, - 0xB8, 0x00, 0xB9, 0x00, 0xBA, 0x00, 0xBB, 0x00, - 0xBC, 0x00, 0xBD, 0x00, 0xBE, 0x00, 0xBF, 0x00, - 0xC0, 0x00, 0xC1, 0x00, 0xC2, 0x00, 0xC3, 0x00, - 0xC4, 0x00, 0xC5, 0x00, 0xC6, 0x00, 0xC7, 0x00, - 0xC8, 0x00, 0xC9, 0x00, 0xCA, 0x00, 0xCB, 0x00, - 0xCC, 0x00, 0xCD, 0x00, 0xCE, 0x00, 0xCF, 0x00, - 0xD0, 0x00, 0xD1, 0x00, 0xD2, 0x00, 0xD3, 0x00, - 0xD4, 0x00, 0xD5, 0x00, 0xD6, 0x00, 0xD7, 0x00, - 0xD8, 0x00, 0xD9, 0x00, 0xDA, 0x00, 0xDB, 0x00, - 0xDC, 0x00, 0xDD, 0x00, 0xDE, 0x00, 0xDF, 0x00, - 0xC0, 0x00, 0xC1, 0x00, 0xC2, 0x00, 0xC3, 0x00, - 0xC4, 0x00, 0xC5, 0x00, 0xC6, 0x00, 0xC7, 0x00, - 0xC8, 0x00, 0xC9, 0x00, 0xCA, 0x00, 0xCB, 0x00, - 0xCC, 0x00, 0xCD, 0x00, 0xCE, 0x00, 0xCF, 0x00, - 0xD0, 0x00, 0xD1, 0x00, 0xD2, 0x00, 0xD3, 0x00, - 0xD4, 0x00, 0xD5, 0x00, 0xD6, 0x00, 0xF7, 0x00, - 0xD8, 0x00, 0xD9, 0x00, 0xDA, 0x00, 0xDB, 0x00, - 0xDC, 0x00, 0xDD, 0x00, 0xDE, 0x00, 0x78, 0x01, - 0x00, 0x01, 0x00, 0x01, 0x02, 0x01, 0x02, 0x01, - 0x04, 0x01, 0x04, 0x01, 0x06, 0x01, 0x06, 0x01, - 0x08, 0x01, 0x08, 0x01, 0x0A, 0x01, 0x0A, 0x01, - 0x0C, 0x01, 0x0C, 0x01, 0x0E, 0x01, 0x0E, 0x01, - 0x10, 0x01, 0x10, 0x01, 0x12, 0x01, 0x12, 0x01, - 0x14, 0x01, 0x14, 0x01, 0x16, 0x01, 0x16, 0x01, - 0x18, 0x01, 0x18, 0x01, 0x1A, 0x01, 0x1A, 0x01, - 0x1C, 0x01, 0x1C, 0x01, 0x1E, 0x01, 0x1E, 0x01, - 0x20, 0x01, 0x20, 0x01, 0x22, 0x01, 0x22, 0x01, - 0x24, 0x01, 0x24, 0x01, 0x26, 0x01, 0x26, 0x01, - 0x28, 0x01, 0x28, 0x01, 0x2A, 0x01, 0x2A, 0x01, - 0x2C, 0x01, 0x2C, 0x01, 0x2E, 0x01, 0x2E, 0x01, - 0x30, 0x01, 0x31, 0x01, 0x32, 0x01, 0x32, 0x01, - 0x34, 0x01, 0x34, 0x01, 0x36, 0x01, 0x36, 0x01, - 0x38, 0x01, 0x39, 0x01, 0x39, 0x01, 0x3B, 0x01, - 0x3B, 0x01, 0x3D, 0x01, 0x3D, 0x01, 0x3F, 0x01, - 0x3F, 0x01, 0x41, 0x01, 0x41, 0x01, 0x43, 0x01, - 0x43, 0x01, 0x45, 0x01, 0x45, 0x01, 0x47, 0x01, - 0x47, 0x01, 0x49, 0x01, 0x4A, 0x01, 0x4A, 0x01, - 0x4C, 0x01, 0x4C, 0x01, 0x4E, 0x01, 0x4E, 0x01, - 0x50, 0x01, 0x50, 0x01, 0x52, 0x01, 0x52, 0x01, - 0x54, 0x01, 0x54, 0x01, 0x56, 0x01, 0x56, 0x01, - 0x58, 0x01, 0x58, 0x01, 0x5A, 0x01, 0x5A, 0x01, - 0x5C, 0x01, 0x5C, 0x01, 0x5E, 0x01, 0x5E, 0x01, - 0x60, 0x01, 0x60, 0x01, 0x62, 0x01, 0x62, 0x01, - 0x64, 0x01, 0x64, 0x01, 0x66, 0x01, 0x66, 0x01, - 0x68, 0x01, 0x68, 0x01, 0x6A, 0x01, 0x6A, 0x01, - 0x6C, 0x01, 0x6C, 0x01, 0x6E, 0x01, 0x6E, 0x01, - 0x70, 0x01, 0x70, 0x01, 0x72, 0x01, 0x72, 0x01, - 0x74, 0x01, 0x74, 0x01, 0x76, 0x01, 0x76, 0x01, - 0x78, 0x01, 0x79, 0x01, 0x79, 0x01, 0x7B, 0x01, - 0x7B, 0x01, 0x7D, 0x01, 0x7D, 0x01, 0x7F, 0x01, - 0x43, 0x02, 0x81, 0x01, 0x82, 0x01, 0x82, 0x01, - 0x84, 0x01, 0x84, 0x01, 0x86, 0x01, 0x87, 0x01, - 0x87, 0x01, 0x89, 0x01, 0x8A, 0x01, 0x8B, 0x01, - 0x8B, 0x01, 0x8D, 0x01, 0x8E, 0x01, 0x8F, 0x01, - 0x90, 0x01, 0x91, 0x01, 0x91, 0x01, 0x93, 0x01, - 0x94, 0x01, 0xF6, 0x01, 0x96, 0x01, 0x97, 0x01, - 0x98, 0x01, 0x98, 0x01, 0x3D, 0x02, 0x9B, 0x01, - 0x9C, 0x01, 0x9D, 0x01, 0x20, 0x02, 0x9F, 0x01, - 0xA0, 0x01, 0xA0, 0x01, 0xA2, 0x01, 0xA2, 0x01, - 0xA4, 0x01, 0xA4, 0x01, 0xA6, 0x01, 0xA7, 0x01, - 0xA7, 0x01, 0xA9, 0x01, 0xAA, 0x01, 0xAB, 0x01, - 0xAC, 0x01, 0xAC, 0x01, 0xAE, 0x01, 0xAF, 0x01, - 0xAF, 0x01, 0xB1, 0x01, 0xB2, 0x01, 0xB3, 0x01, - 0xB3, 0x01, 0xB5, 0x01, 0xB5, 0x01, 0xB7, 0x01, - 0xB8, 0x01, 0xB8, 0x01, 0xBA, 0x01, 0xBB, 0x01, - 0xBC, 0x01, 0xBC, 0x01, 0xBE, 0x01, 0xF7, 0x01, - 0xC0, 0x01, 0xC1, 0x01, 0xC2, 0x01, 0xC3, 0x01, - 0xC4, 0x01, 0xC5, 0x01, 0xC4, 0x01, 0xC7, 0x01, - 0xC8, 0x01, 0xC7, 0x01, 0xCA, 0x01, 0xCB, 0x01, - 0xCA, 0x01, 0xCD, 0x01, 0xCD, 0x01, 0xCF, 0x01, - 0xCF, 0x01, 0xD1, 0x01, 0xD1, 0x01, 0xD3, 0x01, - 0xD3, 0x01, 0xD5, 0x01, 0xD5, 0x01, 0xD7, 0x01, - 0xD7, 0x01, 0xD9, 0x01, 0xD9, 0x01, 0xDB, 0x01, - 0xDB, 0x01, 0x8E, 0x01, 0xDE, 0x01, 0xDE, 0x01, - 0xE0, 0x01, 0xE0, 0x01, 0xE2, 0x01, 0xE2, 0x01, - 0xE4, 0x01, 0xE4, 0x01, 0xE6, 0x01, 0xE6, 0x01, - 0xE8, 0x01, 0xE8, 0x01, 0xEA, 0x01, 0xEA, 0x01, - 0xEC, 0x01, 0xEC, 0x01, 0xEE, 0x01, 0xEE, 0x01, - 0xF0, 0x01, 0xF1, 0x01, 0xF2, 0x01, 0xF1, 0x01, - 0xF4, 0x01, 0xF4, 0x01, 0xF6, 0x01, 0xF7, 0x01, - 0xF8, 0x01, 0xF8, 0x01, 0xFA, 0x01, 0xFA, 0x01, - 0xFC, 0x01, 0xFC, 0x01, 0xFE, 0x01, 0xFE, 0x01, - 0x00, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x04, 0x02, 0x04, 0x02, 0x06, 0x02, 0x06, 0x02, - 0x08, 0x02, 0x08, 0x02, 0x0A, 0x02, 0x0A, 0x02, - 0x0C, 0x02, 0x0C, 0x02, 0x0E, 0x02, 0x0E, 0x02, - 0x10, 0x02, 0x10, 0x02, 0x12, 0x02, 0x12, 0x02, - 0x14, 0x02, 0x14, 0x02, 0x16, 0x02, 0x16, 0x02, - 0x18, 0x02, 0x18, 0x02, 0x1A, 0x02, 0x1A, 0x02, - 0x1C, 0x02, 0x1C, 0x02, 0x1E, 0x02, 0x1E, 0x02, - 0x20, 0x02, 0x21, 0x02, 0x22, 0x02, 0x22, 0x02, - 0x24, 0x02, 0x24, 0x02, 0x26, 0x02, 0x26, 0x02, - 0x28, 0x02, 0x28, 0x02, 0x2A, 0x02, 0x2A, 0x02, - 0x2C, 0x02, 0x2C, 0x02, 0x2E, 0x02, 0x2E, 0x02, - 0x30, 0x02, 0x30, 0x02, 0x32, 0x02, 0x32, 0x02, - 0x34, 0x02, 0x35, 0x02, 0x36, 0x02, 0x37, 0x02, - 0x38, 0x02, 0x39, 0x02, 0x65, 0x2C, 0x3B, 0x02, - 0x3B, 0x02, 0x3D, 0x02, 0x66, 0x2C, 0x3F, 0x02, - 0x40, 0x02, 0x41, 0x02, 0x41, 0x02, 0x43, 0x02, - 0x44, 0x02, 0x45, 0x02, 0x46, 0x02, 0x46, 0x02, - 0x48, 0x02, 0x48, 0x02, 0x4A, 0x02, 0x4A, 0x02, - 0x4C, 0x02, 0x4C, 0x02, 0x4E, 0x02, 0x4E, 0x02, - 0x50, 0x02, 0x51, 0x02, 0x52, 0x02, 0x81, 0x01, - 0x86, 0x01, 0x55, 0x02, 0x89, 0x01, 0x8A, 0x01, - 0x58, 0x02, 0x8F, 0x01, 0x5A, 0x02, 0x90, 0x01, - 0x5C, 0x02, 0x5D, 0x02, 0x5E, 0x02, 0x5F, 0x02, - 0x93, 0x01, 0x61, 0x02, 0x62, 0x02, 0x94, 0x01, - 0x64, 0x02, 0x65, 0x02, 0x66, 0x02, 0x67, 0x02, - 0x97, 0x01, 0x96, 0x01, 0x6A, 0x02, 0x62, 0x2C, - 0x6C, 0x02, 0x6D, 0x02, 0x6E, 0x02, 0x9C, 0x01, - 0x70, 0x02, 0x71, 0x02, 0x9D, 0x01, 0x73, 0x02, - 0x74, 0x02, 0x9F, 0x01, 0x76, 0x02, 0x77, 0x02, - 0x78, 0x02, 0x79, 0x02, 0x7A, 0x02, 0x7B, 0x02, - 0x7C, 0x02, 0x64, 0x2C, 0x7E, 0x02, 0x7F, 0x02, - 0xA6, 0x01, 0x81, 0x02, 0x82, 0x02, 0xA9, 0x01, - 0x84, 0x02, 0x85, 0x02, 0x86, 0x02, 0x87, 0x02, - 0xAE, 0x01, 0x44, 0x02, 0xB1, 0x01, 0xB2, 0x01, - 0x45, 0x02, 0x8D, 0x02, 0x8E, 0x02, 0x8F, 0x02, - 0x90, 0x02, 0x91, 0x02, 0xB7, 0x01, 0x93, 0x02, - 0x94, 0x02, 0x95, 0x02, 0x96, 0x02, 0x97, 0x02, - 0x98, 0x02, 0x99, 0x02, 0x9A, 0x02, 0x9B, 0x02, - 0x9C, 0x02, 0x9D, 0x02, 0x9E, 0x02, 0x9F, 0x02, - 0xA0, 0x02, 0xA1, 0x02, 0xA2, 0x02, 0xA3, 0x02, - 0xA4, 0x02, 0xA5, 0x02, 0xA6, 0x02, 0xA7, 0x02, - 0xA8, 0x02, 0xA9, 0x02, 0xAA, 0x02, 0xAB, 0x02, - 0xAC, 0x02, 0xAD, 0x02, 0xAE, 0x02, 0xAF, 0x02, - 0xB0, 0x02, 0xB1, 0x02, 0xB2, 0x02, 0xB3, 0x02, - 0xB4, 0x02, 0xB5, 0x02, 0xB6, 0x02, 0xB7, 0x02, - 0xB8, 0x02, 0xB9, 0x02, 0xBA, 0x02, 0xBB, 0x02, - 0xBC, 0x02, 0xBD, 0x02, 0xBE, 0x02, 0xBF, 0x02, - 0xC0, 0x02, 0xC1, 0x02, 0xC2, 0x02, 0xC3, 0x02, - 0xC4, 0x02, 0xC5, 0x02, 0xC6, 0x02, 0xC7, 0x02, - 0xC8, 0x02, 0xC9, 0x02, 0xCA, 0x02, 0xCB, 0x02, - 0xCC, 0x02, 0xCD, 0x02, 0xCE, 0x02, 0xCF, 0x02, - 0xD0, 0x02, 0xD1, 0x02, 0xD2, 0x02, 0xD3, 0x02, - 0xD4, 0x02, 0xD5, 0x02, 0xD6, 0x02, 0xD7, 0x02, - 0xD8, 0x02, 0xD9, 0x02, 0xDA, 0x02, 0xDB, 0x02, - 0xDC, 0x02, 0xDD, 0x02, 0xDE, 0x02, 0xDF, 0x02, - 0xE0, 0x02, 0xE1, 0x02, 0xE2, 0x02, 0xE3, 0x02, - 0xE4, 0x02, 0xE5, 0x02, 0xE6, 0x02, 0xE7, 0x02, - 0xE8, 0x02, 0xE9, 0x02, 0xEA, 0x02, 0xEB, 0x02, - 0xEC, 0x02, 0xED, 0x02, 0xEE, 0x02, 0xEF, 0x02, - 0xF0, 0x02, 0xF1, 0x02, 0xF2, 0x02, 0xF3, 0x02, - 0xF4, 0x02, 0xF5, 0x02, 0xF6, 0x02, 0xF7, 0x02, - 0xF8, 0x02, 0xF9, 0x02, 0xFA, 0x02, 0xFB, 0x02, - 0xFC, 0x02, 0xFD, 0x02, 0xFE, 0x02, 0xFF, 0x02, - 0x00, 0x03, 0x01, 0x03, 0x02, 0x03, 0x03, 0x03, - 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x07, 0x03, - 0x08, 0x03, 0x09, 0x03, 0x0A, 0x03, 0x0B, 0x03, - 0x0C, 0x03, 0x0D, 0x03, 0x0E, 0x03, 0x0F, 0x03, - 0x10, 0x03, 0x11, 0x03, 0x12, 0x03, 0x13, 0x03, - 0x14, 0x03, 0x15, 0x03, 0x16, 0x03, 0x17, 0x03, - 0x18, 0x03, 0x19, 0x03, 0x1A, 0x03, 0x1B, 0x03, - 0x1C, 0x03, 0x1D, 0x03, 0x1E, 0x03, 0x1F, 0x03, - 0x20, 0x03, 0x21, 0x03, 0x22, 0x03, 0x23, 0x03, - 0x24, 0x03, 0x25, 0x03, 0x26, 0x03, 0x27, 0x03, - 0x28, 0x03, 0x29, 0x03, 0x2A, 0x03, 0x2B, 0x03, - 0x2C, 0x03, 0x2D, 0x03, 0x2E, 0x03, 0x2F, 0x03, - 0x30, 0x03, 0x31, 0x03, 0x32, 0x03, 0x33, 0x03, - 0x34, 0x03, 0x35, 0x03, 0x36, 0x03, 0x37, 0x03, - 0x38, 0x03, 0x39, 0x03, 0x3A, 0x03, 0x3B, 0x03, - 0x3C, 0x03, 0x3D, 0x03, 0x3E, 0x03, 0x3F, 0x03, - 0x40, 0x03, 0x41, 0x03, 0x42, 0x03, 0x43, 0x03, - 0x44, 0x03, 0x45, 0x03, 0x46, 0x03, 0x47, 0x03, - 0x48, 0x03, 0x49, 0x03, 0x4A, 0x03, 0x4B, 0x03, - 0x4C, 0x03, 0x4D, 0x03, 0x4E, 0x03, 0x4F, 0x03, - 0x50, 0x03, 0x51, 0x03, 0x52, 0x03, 0x53, 0x03, - 0x54, 0x03, 0x55, 0x03, 0x56, 0x03, 0x57, 0x03, - 0x58, 0x03, 0x59, 0x03, 0x5A, 0x03, 0x5B, 0x03, - 0x5C, 0x03, 0x5D, 0x03, 0x5E, 0x03, 0x5F, 0x03, - 0x60, 0x03, 0x61, 0x03, 0x62, 0x03, 0x63, 0x03, - 0x64, 0x03, 0x65, 0x03, 0x66, 0x03, 0x67, 0x03, - 0x68, 0x03, 0x69, 0x03, 0x6A, 0x03, 0x6B, 0x03, - 0x6C, 0x03, 0x6D, 0x03, 0x6E, 0x03, 0x6F, 0x03, - 0x70, 0x03, 0x71, 0x03, 0x72, 0x03, 0x73, 0x03, - 0x74, 0x03, 0x75, 0x03, 0x76, 0x03, 0x77, 0x03, - 0x78, 0x03, 0x79, 0x03, 0x7A, 0x03, 0xFD, 0x03, - 0xFE, 0x03, 0xFF, 0x03, 0x7E, 0x03, 0x7F, 0x03, - 0x80, 0x03, 0x81, 0x03, 0x82, 0x03, 0x83, 0x03, - 0x84, 0x03, 0x85, 0x03, 0x86, 0x03, 0x87, 0x03, - 0x88, 0x03, 0x89, 0x03, 0x8A, 0x03, 0x8B, 0x03, - 0x8C, 0x03, 0x8D, 0x03, 0x8E, 0x03, 0x8F, 0x03, - 0x90, 0x03, 0x91, 0x03, 0x92, 0x03, 0x93, 0x03, - 0x94, 0x03, 0x95, 0x03, 0x96, 0x03, 0x97, 0x03, - 0x98, 0x03, 0x99, 0x03, 0x9A, 0x03, 0x9B, 0x03, - 0x9C, 0x03, 0x9D, 0x03, 0x9E, 0x03, 0x9F, 0x03, - 0xA0, 0x03, 0xA1, 0x03, 0xA2, 0x03, 0xA3, 0x03, - 0xA4, 0x03, 0xA5, 0x03, 0xA6, 0x03, 0xA7, 0x03, - 0xA8, 0x03, 0xA9, 0x03, 0xAA, 0x03, 0xAB, 0x03, - 0x86, 0x03, 0x88, 0x03, 0x89, 0x03, 0x8A, 0x03, - 0xB0, 0x03, 0x91, 0x03, 0x92, 0x03, 0x93, 0x03, - 0x94, 0x03, 0x95, 0x03, 0x96, 0x03, 0x97, 0x03, - 0x98, 0x03, 0x99, 0x03, 0x9A, 0x03, 0x9B, 0x03, - 0x9C, 0x03, 0x9D, 0x03, 0x9E, 0x03, 0x9F, 0x03, - 0xA0, 0x03, 0xA1, 0x03, 0xA3, 0x03, 0xA3, 0x03, - 0xA4, 0x03, 0xA5, 0x03, 0xA6, 0x03, 0xA7, 0x03, - 0xA8, 0x03, 0xA9, 0x03, 0xAA, 0x03, 0xAB, 0x03, - 0x8C, 0x03, 0x8E, 0x03, 0x8F, 0x03, 0xCF, 0x03, - 0xD0, 0x03, 0xD1, 0x03, 0xD2, 0x03, 0xD3, 0x03, - 0xD4, 0x03, 0xD5, 0x03, 0xD6, 0x03, 0xD7, 0x03, - 0xD8, 0x03, 0xD8, 0x03, 0xDA, 0x03, 0xDA, 0x03, - 0xDC, 0x03, 0xDC, 0x03, 0xDE, 0x03, 0xDE, 0x03, - 0xE0, 0x03, 0xE0, 0x03, 0xE2, 0x03, 0xE2, 0x03, - 0xE4, 0x03, 0xE4, 0x03, 0xE6, 0x03, 0xE6, 0x03, - 0xE8, 0x03, 0xE8, 0x03, 0xEA, 0x03, 0xEA, 0x03, - 0xEC, 0x03, 0xEC, 0x03, 0xEE, 0x03, 0xEE, 0x03, - 0xF0, 0x03, 0xF1, 0x03, 0xF9, 0x03, 0xF3, 0x03, - 0xF4, 0x03, 0xF5, 0x03, 0xF6, 0x03, 0xF7, 0x03, - 0xF7, 0x03, 0xF9, 0x03, 0xFA, 0x03, 0xFA, 0x03, - 0xFC, 0x03, 0xFD, 0x03, 0xFE, 0x03, 0xFF, 0x03, - 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x04, - 0x04, 0x04, 0x05, 0x04, 0x06, 0x04, 0x07, 0x04, - 0x08, 0x04, 0x09, 0x04, 0x0A, 0x04, 0x0B, 0x04, - 0x0C, 0x04, 0x0D, 0x04, 0x0E, 0x04, 0x0F, 0x04, - 0x10, 0x04, 0x11, 0x04, 0x12, 0x04, 0x13, 0x04, - 0x14, 0x04, 0x15, 0x04, 0x16, 0x04, 0x17, 0x04, - 0x18, 0x04, 0x19, 0x04, 0x1A, 0x04, 0x1B, 0x04, - 0x1C, 0x04, 0x1D, 0x04, 0x1E, 0x04, 0x1F, 0x04, - 0x20, 0x04, 0x21, 0x04, 0x22, 0x04, 0x23, 0x04, - 0x24, 0x04, 0x25, 0x04, 0x26, 0x04, 0x27, 0x04, - 0x28, 0x04, 0x29, 0x04, 0x2A, 0x04, 0x2B, 0x04, - 0x2C, 0x04, 0x2D, 0x04, 0x2E, 0x04, 0x2F, 0x04, - 0x10, 0x04, 0x11, 0x04, 0x12, 0x04, 0x13, 0x04, - 0x14, 0x04, 0x15, 0x04, 0x16, 0x04, 0x17, 0x04, - 0x18, 0x04, 0x19, 0x04, 0x1A, 0x04, 0x1B, 0x04, - 0x1C, 0x04, 0x1D, 0x04, 0x1E, 0x04, 0x1F, 0x04, - 0x20, 0x04, 0x21, 0x04, 0x22, 0x04, 0x23, 0x04, - 0x24, 0x04, 0x25, 0x04, 0x26, 0x04, 0x27, 0x04, - 0x28, 0x04, 0x29, 0x04, 0x2A, 0x04, 0x2B, 0x04, - 0x2C, 0x04, 0x2D, 0x04, 0x2E, 0x04, 0x2F, 0x04, - 0x00, 0x04, 0x01, 0x04, 0x02, 0x04, 0x03, 0x04, - 0x04, 0x04, 0x05, 0x04, 0x06, 0x04, 0x07, 0x04, - 0x08, 0x04, 0x09, 0x04, 0x0A, 0x04, 0x0B, 0x04, - 0x0C, 0x04, 0x0D, 0x04, 0x0E, 0x04, 0x0F, 0x04, - 0x60, 0x04, 0x60, 0x04, 0x62, 0x04, 0x62, 0x04, - 0x64, 0x04, 0x64, 0x04, 0x66, 0x04, 0x66, 0x04, - 0x68, 0x04, 0x68, 0x04, 0x6A, 0x04, 0x6A, 0x04, - 0x6C, 0x04, 0x6C, 0x04, 0x6E, 0x04, 0x6E, 0x04, - 0x70, 0x04, 0x70, 0x04, 0x72, 0x04, 0x72, 0x04, - 0x74, 0x04, 0x74, 0x04, 0x76, 0x04, 0x76, 0x04, - 0x78, 0x04, 0x78, 0x04, 0x7A, 0x04, 0x7A, 0x04, - 0x7C, 0x04, 0x7C, 0x04, 0x7E, 0x04, 0x7E, 0x04, - 0x80, 0x04, 0x80, 0x04, 0x82, 0x04, 0x83, 0x04, - 0x84, 0x04, 0x85, 0x04, 0x86, 0x04, 0x87, 0x04, - 0x88, 0x04, 0x89, 0x04, 0x8A, 0x04, 0x8A, 0x04, - 0x8C, 0x04, 0x8C, 0x04, 0x8E, 0x04, 0x8E, 0x04, - 0x90, 0x04, 0x90, 0x04, 0x92, 0x04, 0x92, 0x04, - 0x94, 0x04, 0x94, 0x04, 0x96, 0x04, 0x96, 0x04, - 0x98, 0x04, 0x98, 0x04, 0x9A, 0x04, 0x9A, 0x04, - 0x9C, 0x04, 0x9C, 0x04, 0x9E, 0x04, 0x9E, 0x04, - 0xA0, 0x04, 0xA0, 0x04, 0xA2, 0x04, 0xA2, 0x04, - 0xA4, 0x04, 0xA4, 0x04, 0xA6, 0x04, 0xA6, 0x04, - 0xA8, 0x04, 0xA8, 0x04, 0xAA, 0x04, 0xAA, 0x04, - 0xAC, 0x04, 0xAC, 0x04, 0xAE, 0x04, 0xAE, 0x04, - 0xB0, 0x04, 0xB0, 0x04, 0xB2, 0x04, 0xB2, 0x04, - 0xB4, 0x04, 0xB4, 0x04, 0xB6, 0x04, 0xB6, 0x04, - 0xB8, 0x04, 0xB8, 0x04, 0xBA, 0x04, 0xBA, 0x04, - 0xBC, 0x04, 0xBC, 0x04, 0xBE, 0x04, 0xBE, 0x04, - 0xC0, 0x04, 0xC1, 0x04, 0xC1, 0x04, 0xC3, 0x04, - 0xC3, 0x04, 0xC5, 0x04, 0xC5, 0x04, 0xC7, 0x04, - 0xC7, 0x04, 0xC9, 0x04, 0xC9, 0x04, 0xCB, 0x04, - 0xCB, 0x04, 0xCD, 0x04, 0xCD, 0x04, 0xC0, 0x04, - 0xD0, 0x04, 0xD0, 0x04, 0xD2, 0x04, 0xD2, 0x04, - 0xD4, 0x04, 0xD4, 0x04, 0xD6, 0x04, 0xD6, 0x04, - 0xD8, 0x04, 0xD8, 0x04, 0xDA, 0x04, 0xDA, 0x04, - 0xDC, 0x04, 0xDC, 0x04, 0xDE, 0x04, 0xDE, 0x04, - 0xE0, 0x04, 0xE0, 0x04, 0xE2, 0x04, 0xE2, 0x04, - 0xE4, 0x04, 0xE4, 0x04, 0xE6, 0x04, 0xE6, 0x04, - 0xE8, 0x04, 0xE8, 0x04, 0xEA, 0x04, 0xEA, 0x04, - 0xEC, 0x04, 0xEC, 0x04, 0xEE, 0x04, 0xEE, 0x04, - 0xF0, 0x04, 0xF0, 0x04, 0xF2, 0x04, 0xF2, 0x04, - 0xF4, 0x04, 0xF4, 0x04, 0xF6, 0x04, 0xF6, 0x04, - 0xF8, 0x04, 0xF8, 0x04, 0xFA, 0x04, 0xFA, 0x04, - 0xFC, 0x04, 0xFC, 0x04, 0xFE, 0x04, 0xFE, 0x04, - 0x00, 0x05, 0x00, 0x05, 0x02, 0x05, 0x02, 0x05, - 0x04, 0x05, 0x04, 0x05, 0x06, 0x05, 0x06, 0x05, - 0x08, 0x05, 0x08, 0x05, 0x0A, 0x05, 0x0A, 0x05, - 0x0C, 0x05, 0x0C, 0x05, 0x0E, 0x05, 0x0E, 0x05, - 0x10, 0x05, 0x10, 0x05, 0x12, 0x05, 0x12, 0x05, - 0x14, 0x05, 0x15, 0x05, 0x16, 0x05, 0x17, 0x05, - 0x18, 0x05, 0x19, 0x05, 0x1A, 0x05, 0x1B, 0x05, - 0x1C, 0x05, 0x1D, 0x05, 0x1E, 0x05, 0x1F, 0x05, - 0x20, 0x05, 0x21, 0x05, 0x22, 0x05, 0x23, 0x05, - 0x24, 0x05, 0x25, 0x05, 0x26, 0x05, 0x27, 0x05, - 0x28, 0x05, 0x29, 0x05, 0x2A, 0x05, 0x2B, 0x05, - 0x2C, 0x05, 0x2D, 0x05, 0x2E, 0x05, 0x2F, 0x05, - 0x30, 0x05, 0x31, 0x05, 0x32, 0x05, 0x33, 0x05, - 0x34, 0x05, 0x35, 0x05, 0x36, 0x05, 0x37, 0x05, - 0x38, 0x05, 0x39, 0x05, 0x3A, 0x05, 0x3B, 0x05, - 0x3C, 0x05, 0x3D, 0x05, 0x3E, 0x05, 0x3F, 0x05, - 0x40, 0x05, 0x41, 0x05, 0x42, 0x05, 0x43, 0x05, - 0x44, 0x05, 0x45, 0x05, 0x46, 0x05, 0x47, 0x05, - 0x48, 0x05, 0x49, 0x05, 0x4A, 0x05, 0x4B, 0x05, - 0x4C, 0x05, 0x4D, 0x05, 0x4E, 0x05, 0x4F, 0x05, - 0x50, 0x05, 0x51, 0x05, 0x52, 0x05, 0x53, 0x05, - 0x54, 0x05, 0x55, 0x05, 0x56, 0x05, 0x57, 0x05, - 0x58, 0x05, 0x59, 0x05, 0x5A, 0x05, 0x5B, 0x05, - 0x5C, 0x05, 0x5D, 0x05, 0x5E, 0x05, 0x5F, 0x05, - 0x60, 0x05, 0x31, 0x05, 0x32, 0x05, 0x33, 0x05, - 0x34, 0x05, 0x35, 0x05, 0x36, 0x05, 0x37, 0x05, - 0x38, 0x05, 0x39, 0x05, 0x3A, 0x05, 0x3B, 0x05, - 0x3C, 0x05, 0x3D, 0x05, 0x3E, 0x05, 0x3F, 0x05, - 0x40, 0x05, 0x41, 0x05, 0x42, 0x05, 0x43, 0x05, - 0x44, 0x05, 0x45, 0x05, 0x46, 0x05, 0x47, 0x05, - 0x48, 0x05, 0x49, 0x05, 0x4A, 0x05, 0x4B, 0x05, - 0x4C, 0x05, 0x4D, 0x05, 0x4E, 0x05, 0x4F, 0x05, - 0x50, 0x05, 0x51, 0x05, 0x52, 0x05, 0x53, 0x05, - 0x54, 0x05, 0x55, 0x05, 0x56, 0x05, 0xFF, 0xFF, - 0xF6, 0x17, 0x63, 0x2C, 0x7E, 0x1D, 0x7F, 0x1D, - 0x80, 0x1D, 0x81, 0x1D, 0x82, 0x1D, 0x83, 0x1D, - 0x84, 0x1D, 0x85, 0x1D, 0x86, 0x1D, 0x87, 0x1D, - 0x88, 0x1D, 0x89, 0x1D, 0x8A, 0x1D, 0x8B, 0x1D, - 0x8C, 0x1D, 0x8D, 0x1D, 0x8E, 0x1D, 0x8F, 0x1D, - 0x90, 0x1D, 0x91, 0x1D, 0x92, 0x1D, 0x93, 0x1D, - 0x94, 0x1D, 0x95, 0x1D, 0x96, 0x1D, 0x97, 0x1D, - 0x98, 0x1D, 0x99, 0x1D, 0x9A, 0x1D, 0x9B, 0x1D, - 0x9C, 0x1D, 0x9D, 0x1D, 0x9E, 0x1D, 0x9F, 0x1D, - 0xA0, 0x1D, 0xA1, 0x1D, 0xA2, 0x1D, 0xA3, 0x1D, - 0xA4, 0x1D, 0xA5, 0x1D, 0xA6, 0x1D, 0xA7, 0x1D, - 0xA8, 0x1D, 0xA9, 0x1D, 0xAA, 0x1D, 0xAB, 0x1D, - 0xAC, 0x1D, 0xAD, 0x1D, 0xAE, 0x1D, 0xAF, 0x1D, - 0xB0, 0x1D, 0xB1, 0x1D, 0xB2, 0x1D, 0xB3, 0x1D, - 0xB4, 0x1D, 0xB5, 0x1D, 0xB6, 0x1D, 0xB7, 0x1D, - 0xB8, 0x1D, 0xB9, 0x1D, 0xBA, 0x1D, 0xBB, 0x1D, - 0xBC, 0x1D, 0xBD, 0x1D, 0xBE, 0x1D, 0xBF, 0x1D, - 0xC0, 0x1D, 0xC1, 0x1D, 0xC2, 0x1D, 0xC3, 0x1D, - 0xC4, 0x1D, 0xC5, 0x1D, 0xC6, 0x1D, 0xC7, 0x1D, - 0xC8, 0x1D, 0xC9, 0x1D, 0xCA, 0x1D, 0xCB, 0x1D, - 0xCC, 0x1D, 0xCD, 0x1D, 0xCE, 0x1D, 0xCF, 0x1D, - 0xD0, 0x1D, 0xD1, 0x1D, 0xD2, 0x1D, 0xD3, 0x1D, - 0xD4, 0x1D, 0xD5, 0x1D, 0xD6, 0x1D, 0xD7, 0x1D, - 0xD8, 0x1D, 0xD9, 0x1D, 0xDA, 0x1D, 0xDB, 0x1D, - 0xDC, 0x1D, 0xDD, 0x1D, 0xDE, 0x1D, 0xDF, 0x1D, - 0xE0, 0x1D, 0xE1, 0x1D, 0xE2, 0x1D, 0xE3, 0x1D, - 0xE4, 0x1D, 0xE5, 0x1D, 0xE6, 0x1D, 0xE7, 0x1D, - 0xE8, 0x1D, 0xE9, 0x1D, 0xEA, 0x1D, 0xEB, 0x1D, - 0xEC, 0x1D, 0xED, 0x1D, 0xEE, 0x1D, 0xEF, 0x1D, - 0xF0, 0x1D, 0xF1, 0x1D, 0xF2, 0x1D, 0xF3, 0x1D, - 0xF4, 0x1D, 0xF5, 0x1D, 0xF6, 0x1D, 0xF7, 0x1D, - 0xF8, 0x1D, 0xF9, 0x1D, 0xFA, 0x1D, 0xFB, 0x1D, - 0xFC, 0x1D, 0xFD, 0x1D, 0xFE, 0x1D, 0xFF, 0x1D, - 0x00, 0x1E, 0x00, 0x1E, 0x02, 0x1E, 0x02, 0x1E, - 0x04, 0x1E, 0x04, 0x1E, 0x06, 0x1E, 0x06, 0x1E, - 0x08, 0x1E, 0x08, 0x1E, 0x0A, 0x1E, 0x0A, 0x1E, - 0x0C, 0x1E, 0x0C, 0x1E, 0x0E, 0x1E, 0x0E, 0x1E, - 0x10, 0x1E, 0x10, 0x1E, 0x12, 0x1E, 0x12, 0x1E, - 0x14, 0x1E, 0x14, 0x1E, 0x16, 0x1E, 0x16, 0x1E, - 0x18, 0x1E, 0x18, 0x1E, 0x1A, 0x1E, 0x1A, 0x1E, - 0x1C, 0x1E, 0x1C, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, - 0x20, 0x1E, 0x20, 0x1E, 0x22, 0x1E, 0x22, 0x1E, - 0x24, 0x1E, 0x24, 0x1E, 0x26, 0x1E, 0x26, 0x1E, - 0x28, 0x1E, 0x28, 0x1E, 0x2A, 0x1E, 0x2A, 0x1E, - 0x2C, 0x1E, 0x2C, 0x1E, 0x2E, 0x1E, 0x2E, 0x1E, - 0x30, 0x1E, 0x30, 0x1E, 0x32, 0x1E, 0x32, 0x1E, - 0x34, 0x1E, 0x34, 0x1E, 0x36, 0x1E, 0x36, 0x1E, - 0x38, 0x1E, 0x38, 0x1E, 0x3A, 0x1E, 0x3A, 0x1E, - 0x3C, 0x1E, 0x3C, 0x1E, 0x3E, 0x1E, 0x3E, 0x1E, - 0x40, 0x1E, 0x40, 0x1E, 0x42, 0x1E, 0x42, 0x1E, - 0x44, 0x1E, 0x44, 0x1E, 0x46, 0x1E, 0x46, 0x1E, - 0x48, 0x1E, 0x48, 0x1E, 0x4A, 0x1E, 0x4A, 0x1E, - 0x4C, 0x1E, 0x4C, 0x1E, 0x4E, 0x1E, 0x4E, 0x1E, - 0x50, 0x1E, 0x50, 0x1E, 0x52, 0x1E, 0x52, 0x1E, - 0x54, 0x1E, 0x54, 0x1E, 0x56, 0x1E, 0x56, 0x1E, - 0x58, 0x1E, 0x58, 0x1E, 0x5A, 0x1E, 0x5A, 0x1E, - 0x5C, 0x1E, 0x5C, 0x1E, 0x5E, 0x1E, 0x5E, 0x1E, - 0x60, 0x1E, 0x60, 0x1E, 0x62, 0x1E, 0x62, 0x1E, - 0x64, 0x1E, 0x64, 0x1E, 0x66, 0x1E, 0x66, 0x1E, - 0x68, 0x1E, 0x68, 0x1E, 0x6A, 0x1E, 0x6A, 0x1E, - 0x6C, 0x1E, 0x6C, 0x1E, 0x6E, 0x1E, 0x6E, 0x1E, - 0x70, 0x1E, 0x70, 0x1E, 0x72, 0x1E, 0x72, 0x1E, - 0x74, 0x1E, 0x74, 0x1E, 0x76, 0x1E, 0x76, 0x1E, - 0x78, 0x1E, 0x78, 0x1E, 0x7A, 0x1E, 0x7A, 0x1E, - 0x7C, 0x1E, 0x7C, 0x1E, 0x7E, 0x1E, 0x7E, 0x1E, - 0x80, 0x1E, 0x80, 0x1E, 0x82, 0x1E, 0x82, 0x1E, - 0x84, 0x1E, 0x84, 0x1E, 0x86, 0x1E, 0x86, 0x1E, - 0x88, 0x1E, 0x88, 0x1E, 0x8A, 0x1E, 0x8A, 0x1E, - 0x8C, 0x1E, 0x8C, 0x1E, 0x8E, 0x1E, 0x8E, 0x1E, - 0x90, 0x1E, 0x90, 0x1E, 0x92, 0x1E, 0x92, 0x1E, - 0x94, 0x1E, 0x94, 0x1E, 0x96, 0x1E, 0x97, 0x1E, - 0x98, 0x1E, 0x99, 0x1E, 0x9A, 0x1E, 0x9B, 0x1E, - 0x9C, 0x1E, 0x9D, 0x1E, 0x9E, 0x1E, 0x9F, 0x1E, - 0xA0, 0x1E, 0xA0, 0x1E, 0xA2, 0x1E, 0xA2, 0x1E, - 0xA4, 0x1E, 0xA4, 0x1E, 0xA6, 0x1E, 0xA6, 0x1E, - 0xA8, 0x1E, 0xA8, 0x1E, 0xAA, 0x1E, 0xAA, 0x1E, - 0xAC, 0x1E, 0xAC, 0x1E, 0xAE, 0x1E, 0xAE, 0x1E, - 0xB0, 0x1E, 0xB0, 0x1E, 0xB2, 0x1E, 0xB2, 0x1E, - 0xB4, 0x1E, 0xB4, 0x1E, 0xB6, 0x1E, 0xB6, 0x1E, - 0xB8, 0x1E, 0xB8, 0x1E, 0xBA, 0x1E, 0xBA, 0x1E, - 0xBC, 0x1E, 0xBC, 0x1E, 0xBE, 0x1E, 0xBE, 0x1E, - 0xC0, 0x1E, 0xC0, 0x1E, 0xC2, 0x1E, 0xC2, 0x1E, - 0xC4, 0x1E, 0xC4, 0x1E, 0xC6, 0x1E, 0xC6, 0x1E, - 0xC8, 0x1E, 0xC8, 0x1E, 0xCA, 0x1E, 0xCA, 0x1E, - 0xCC, 0x1E, 0xCC, 0x1E, 0xCE, 0x1E, 0xCE, 0x1E, - 0xD0, 0x1E, 0xD0, 0x1E, 0xD2, 0x1E, 0xD2, 0x1E, - 0xD4, 0x1E, 0xD4, 0x1E, 0xD6, 0x1E, 0xD6, 0x1E, - 0xD8, 0x1E, 0xD8, 0x1E, 0xDA, 0x1E, 0xDA, 0x1E, - 0xDC, 0x1E, 0xDC, 0x1E, 0xDE, 0x1E, 0xDE, 0x1E, - 0xE0, 0x1E, 0xE0, 0x1E, 0xE2, 0x1E, 0xE2, 0x1E, - 0xE4, 0x1E, 0xE4, 0x1E, 0xE6, 0x1E, 0xE6, 0x1E, - 0xE8, 0x1E, 0xE8, 0x1E, 0xEA, 0x1E, 0xEA, 0x1E, - 0xEC, 0x1E, 0xEC, 0x1E, 0xEE, 0x1E, 0xEE, 0x1E, - 0xF0, 0x1E, 0xF0, 0x1E, 0xF2, 0x1E, 0xF2, 0x1E, - 0xF4, 0x1E, 0xF4, 0x1E, 0xF6, 0x1E, 0xF6, 0x1E, - 0xF8, 0x1E, 0xF8, 0x1E, 0xFA, 0x1E, 0xFB, 0x1E, - 0xFC, 0x1E, 0xFD, 0x1E, 0xFE, 0x1E, 0xFF, 0x1E, - 0x08, 0x1F, 0x09, 0x1F, 0x0A, 0x1F, 0x0B, 0x1F, - 0x0C, 0x1F, 0x0D, 0x1F, 0x0E, 0x1F, 0x0F, 0x1F, - 0x08, 0x1F, 0x09, 0x1F, 0x0A, 0x1F, 0x0B, 0x1F, - 0x0C, 0x1F, 0x0D, 0x1F, 0x0E, 0x1F, 0x0F, 0x1F, - 0x18, 0x1F, 0x19, 0x1F, 0x1A, 0x1F, 0x1B, 0x1F, - 0x1C, 0x1F, 0x1D, 0x1F, 0x16, 0x1F, 0x17, 0x1F, - 0x18, 0x1F, 0x19, 0x1F, 0x1A, 0x1F, 0x1B, 0x1F, - 0x1C, 0x1F, 0x1D, 0x1F, 0x1E, 0x1F, 0x1F, 0x1F, - 0x28, 0x1F, 0x29, 0x1F, 0x2A, 0x1F, 0x2B, 0x1F, - 0x2C, 0x1F, 0x2D, 0x1F, 0x2E, 0x1F, 0x2F, 0x1F, - 0x28, 0x1F, 0x29, 0x1F, 0x2A, 0x1F, 0x2B, 0x1F, - 0x2C, 0x1F, 0x2D, 0x1F, 0x2E, 0x1F, 0x2F, 0x1F, - 0x38, 0x1F, 0x39, 0x1F, 0x3A, 0x1F, 0x3B, 0x1F, - 0x3C, 0x1F, 0x3D, 0x1F, 0x3E, 0x1F, 0x3F, 0x1F, - 0x38, 0x1F, 0x39, 0x1F, 0x3A, 0x1F, 0x3B, 0x1F, - 0x3C, 0x1F, 0x3D, 0x1F, 0x3E, 0x1F, 0x3F, 0x1F, - 0x48, 0x1F, 0x49, 0x1F, 0x4A, 0x1F, 0x4B, 0x1F, - 0x4C, 0x1F, 0x4D, 0x1F, 0x46, 0x1F, 0x47, 0x1F, - 0x48, 0x1F, 0x49, 0x1F, 0x4A, 0x1F, 0x4B, 0x1F, - 0x4C, 0x1F, 0x4D, 0x1F, 0x4E, 0x1F, 0x4F, 0x1F, - 0x50, 0x1F, 0x59, 0x1F, 0x52, 0x1F, 0x5B, 0x1F, - 0x54, 0x1F, 0x5D, 0x1F, 0x56, 0x1F, 0x5F, 0x1F, - 0x58, 0x1F, 0x59, 0x1F, 0x5A, 0x1F, 0x5B, 0x1F, - 0x5C, 0x1F, 0x5D, 0x1F, 0x5E, 0x1F, 0x5F, 0x1F, - 0x68, 0x1F, 0x69, 0x1F, 0x6A, 0x1F, 0x6B, 0x1F, - 0x6C, 0x1F, 0x6D, 0x1F, 0x6E, 0x1F, 0x6F, 0x1F, - 0x68, 0x1F, 0x69, 0x1F, 0x6A, 0x1F, 0x6B, 0x1F, - 0x6C, 0x1F, 0x6D, 0x1F, 0x6E, 0x1F, 0x6F, 0x1F, - 0xBA, 0x1F, 0xBB, 0x1F, 0xC8, 0x1F, 0xC9, 0x1F, - 0xCA, 0x1F, 0xCB, 0x1F, 0xDA, 0x1F, 0xDB, 0x1F, - 0xF8, 0x1F, 0xF9, 0x1F, 0xEA, 0x1F, 0xEB, 0x1F, - 0xFA, 0x1F, 0xFB, 0x1F, 0x7E, 0x1F, 0x7F, 0x1F, - 0x88, 0x1F, 0x89, 0x1F, 0x8A, 0x1F, 0x8B, 0x1F, - 0x8C, 0x1F, 0x8D, 0x1F, 0x8E, 0x1F, 0x8F, 0x1F, - 0x88, 0x1F, 0x89, 0x1F, 0x8A, 0x1F, 0x8B, 0x1F, - 0x8C, 0x1F, 0x8D, 0x1F, 0x8E, 0x1F, 0x8F, 0x1F, - 0x98, 0x1F, 0x99, 0x1F, 0x9A, 0x1F, 0x9B, 0x1F, - 0x9C, 0x1F, 0x9D, 0x1F, 0x9E, 0x1F, 0x9F, 0x1F, - 0x98, 0x1F, 0x99, 0x1F, 0x9A, 0x1F, 0x9B, 0x1F, - 0x9C, 0x1F, 0x9D, 0x1F, 0x9E, 0x1F, 0x9F, 0x1F, - 0xA8, 0x1F, 0xA9, 0x1F, 0xAA, 0x1F, 0xAB, 0x1F, - 0xAC, 0x1F, 0xAD, 0x1F, 0xAE, 0x1F, 0xAF, 0x1F, - 0xA8, 0x1F, 0xA9, 0x1F, 0xAA, 0x1F, 0xAB, 0x1F, - 0xAC, 0x1F, 0xAD, 0x1F, 0xAE, 0x1F, 0xAF, 0x1F, - 0xB8, 0x1F, 0xB9, 0x1F, 0xB2, 0x1F, 0xBC, 0x1F, - 0xB4, 0x1F, 0xB5, 0x1F, 0xB6, 0x1F, 0xB7, 0x1F, - 0xB8, 0x1F, 0xB9, 0x1F, 0xBA, 0x1F, 0xBB, 0x1F, - 0xBC, 0x1F, 0xBD, 0x1F, 0xBE, 0x1F, 0xBF, 0x1F, - 0xC0, 0x1F, 0xC1, 0x1F, 0xC2, 0x1F, 0xC3, 0x1F, - 0xC4, 0x1F, 0xC5, 0x1F, 0xC6, 0x1F, 0xC7, 0x1F, - 0xC8, 0x1F, 0xC9, 0x1F, 0xCA, 0x1F, 0xCB, 0x1F, - 0xC3, 0x1F, 0xCD, 0x1F, 0xCE, 0x1F, 0xCF, 0x1F, - 0xD8, 0x1F, 0xD9, 0x1F, 0xD2, 0x1F, 0xD3, 0x1F, - 0xD4, 0x1F, 0xD5, 0x1F, 0xD6, 0x1F, 0xD7, 0x1F, - 0xD8, 0x1F, 0xD9, 0x1F, 0xDA, 0x1F, 0xDB, 0x1F, - 0xDC, 0x1F, 0xDD, 0x1F, 0xDE, 0x1F, 0xDF, 0x1F, - 0xE8, 0x1F, 0xE9, 0x1F, 0xE2, 0x1F, 0xE3, 0x1F, - 0xE4, 0x1F, 0xEC, 0x1F, 0xE6, 0x1F, 0xE7, 0x1F, - 0xE8, 0x1F, 0xE9, 0x1F, 0xEA, 0x1F, 0xEB, 0x1F, - 0xEC, 0x1F, 0xED, 0x1F, 0xEE, 0x1F, 0xEF, 0x1F, - 0xF0, 0x1F, 0xF1, 0x1F, 0xF2, 0x1F, 0xF3, 0x1F, - 0xF4, 0x1F, 0xF5, 0x1F, 0xF6, 0x1F, 0xF7, 0x1F, - 0xF8, 0x1F, 0xF9, 0x1F, 0xFA, 0x1F, 0xFB, 0x1F, - 0xF3, 0x1F, 0xFD, 0x1F, 0xFE, 0x1F, 0xFF, 0x1F, - 0x00, 0x20, 0x01, 0x20, 0x02, 0x20, 0x03, 0x20, - 0x04, 0x20, 0x05, 0x20, 0x06, 0x20, 0x07, 0x20, - 0x08, 0x20, 0x09, 0x20, 0x0A, 0x20, 0x0B, 0x20, - 0x0C, 0x20, 0x0D, 0x20, 0x0E, 0x20, 0x0F, 0x20, - 0x10, 0x20, 0x11, 0x20, 0x12, 0x20, 0x13, 0x20, - 0x14, 0x20, 0x15, 0x20, 0x16, 0x20, 0x17, 0x20, - 0x18, 0x20, 0x19, 0x20, 0x1A, 0x20, 0x1B, 0x20, - 0x1C, 0x20, 0x1D, 0x20, 0x1E, 0x20, 0x1F, 0x20, - 0x20, 0x20, 0x21, 0x20, 0x22, 0x20, 0x23, 0x20, - 0x24, 0x20, 0x25, 0x20, 0x26, 0x20, 0x27, 0x20, - 0x28, 0x20, 0x29, 0x20, 0x2A, 0x20, 0x2B, 0x20, - 0x2C, 0x20, 0x2D, 0x20, 0x2E, 0x20, 0x2F, 0x20, - 0x30, 0x20, 0x31, 0x20, 0x32, 0x20, 0x33, 0x20, - 0x34, 0x20, 0x35, 0x20, 0x36, 0x20, 0x37, 0x20, - 0x38, 0x20, 0x39, 0x20, 0x3A, 0x20, 0x3B, 0x20, - 0x3C, 0x20, 0x3D, 0x20, 0x3E, 0x20, 0x3F, 0x20, - 0x40, 0x20, 0x41, 0x20, 0x42, 0x20, 0x43, 0x20, - 0x44, 0x20, 0x45, 0x20, 0x46, 0x20, 0x47, 0x20, - 0x48, 0x20, 0x49, 0x20, 0x4A, 0x20, 0x4B, 0x20, - 0x4C, 0x20, 0x4D, 0x20, 0x4E, 0x20, 0x4F, 0x20, - 0x50, 0x20, 0x51, 0x20, 0x52, 0x20, 0x53, 0x20, - 0x54, 0x20, 0x55, 0x20, 0x56, 0x20, 0x57, 0x20, - 0x58, 0x20, 0x59, 0x20, 0x5A, 0x20, 0x5B, 0x20, - 0x5C, 0x20, 0x5D, 0x20, 0x5E, 0x20, 0x5F, 0x20, - 0x60, 0x20, 0x61, 0x20, 0x62, 0x20, 0x63, 0x20, - 0x64, 0x20, 0x65, 0x20, 0x66, 0x20, 0x67, 0x20, - 0x68, 0x20, 0x69, 0x20, 0x6A, 0x20, 0x6B, 0x20, - 0x6C, 0x20, 0x6D, 0x20, 0x6E, 0x20, 0x6F, 0x20, - 0x70, 0x20, 0x71, 0x20, 0x72, 0x20, 0x73, 0x20, - 0x74, 0x20, 0x75, 0x20, 0x76, 0x20, 0x77, 0x20, - 0x78, 0x20, 0x79, 0x20, 0x7A, 0x20, 0x7B, 0x20, - 0x7C, 0x20, 0x7D, 0x20, 0x7E, 0x20, 0x7F, 0x20, - 0x80, 0x20, 0x81, 0x20, 0x82, 0x20, 0x83, 0x20, - 0x84, 0x20, 0x85, 0x20, 0x86, 0x20, 0x87, 0x20, - 0x88, 0x20, 0x89, 0x20, 0x8A, 0x20, 0x8B, 0x20, - 0x8C, 0x20, 0x8D, 0x20, 0x8E, 0x20, 0x8F, 0x20, - 0x90, 0x20, 0x91, 0x20, 0x92, 0x20, 0x93, 0x20, - 0x94, 0x20, 0x95, 0x20, 0x96, 0x20, 0x97, 0x20, - 0x98, 0x20, 0x99, 0x20, 0x9A, 0x20, 0x9B, 0x20, - 0x9C, 0x20, 0x9D, 0x20, 0x9E, 0x20, 0x9F, 0x20, - 0xA0, 0x20, 0xA1, 0x20, 0xA2, 0x20, 0xA3, 0x20, - 0xA4, 0x20, 0xA5, 0x20, 0xA6, 0x20, 0xA7, 0x20, - 0xA8, 0x20, 0xA9, 0x20, 0xAA, 0x20, 0xAB, 0x20, - 0xAC, 0x20, 0xAD, 0x20, 0xAE, 0x20, 0xAF, 0x20, - 0xB0, 0x20, 0xB1, 0x20, 0xB2, 0x20, 0xB3, 0x20, - 0xB4, 0x20, 0xB5, 0x20, 0xB6, 0x20, 0xB7, 0x20, - 0xB8, 0x20, 0xB9, 0x20, 0xBA, 0x20, 0xBB, 0x20, - 0xBC, 0x20, 0xBD, 0x20, 0xBE, 0x20, 0xBF, 0x20, - 0xC0, 0x20, 0xC1, 0x20, 0xC2, 0x20, 0xC3, 0x20, - 0xC4, 0x20, 0xC5, 0x20, 0xC6, 0x20, 0xC7, 0x20, - 0xC8, 0x20, 0xC9, 0x20, 0xCA, 0x20, 0xCB, 0x20, - 0xCC, 0x20, 0xCD, 0x20, 0xCE, 0x20, 0xCF, 0x20, - 0xD0, 0x20, 0xD1, 0x20, 0xD2, 0x20, 0xD3, 0x20, - 0xD4, 0x20, 0xD5, 0x20, 0xD6, 0x20, 0xD7, 0x20, - 0xD8, 0x20, 0xD9, 0x20, 0xDA, 0x20, 0xDB, 0x20, - 0xDC, 0x20, 0xDD, 0x20, 0xDE, 0x20, 0xDF, 0x20, - 0xE0, 0x20, 0xE1, 0x20, 0xE2, 0x20, 0xE3, 0x20, - 0xE4, 0x20, 0xE5, 0x20, 0xE6, 0x20, 0xE7, 0x20, - 0xE8, 0x20, 0xE9, 0x20, 0xEA, 0x20, 0xEB, 0x20, - 0xEC, 0x20, 0xED, 0x20, 0xEE, 0x20, 0xEF, 0x20, - 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, - 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20, - 0xF8, 0x20, 0xF9, 0x20, 0xFA, 0x20, 0xFB, 0x20, - 0xFC, 0x20, 0xFD, 0x20, 0xFE, 0x20, 0xFF, 0x20, - 0x00, 0x21, 0x01, 0x21, 0x02, 0x21, 0x03, 0x21, - 0x04, 0x21, 0x05, 0x21, 0x06, 0x21, 0x07, 0x21, - 0x08, 0x21, 0x09, 0x21, 0x0A, 0x21, 0x0B, 0x21, - 0x0C, 0x21, 0x0D, 0x21, 0x0E, 0x21, 0x0F, 0x21, - 0x10, 0x21, 0x11, 0x21, 0x12, 0x21, 0x13, 0x21, - 0x14, 0x21, 0x15, 0x21, 0x16, 0x21, 0x17, 0x21, - 0x18, 0x21, 0x19, 0x21, 0x1A, 0x21, 0x1B, 0x21, - 0x1C, 0x21, 0x1D, 0x21, 0x1E, 0x21, 0x1F, 0x21, - 0x20, 0x21, 0x21, 0x21, 0x22, 0x21, 0x23, 0x21, - 0x24, 0x21, 0x25, 0x21, 0x26, 0x21, 0x27, 0x21, - 0x28, 0x21, 0x29, 0x21, 0x2A, 0x21, 0x2B, 0x21, - 0x2C, 0x21, 0x2D, 0x21, 0x2E, 0x21, 0x2F, 0x21, - 0x30, 0x21, 0x31, 0x21, 0x32, 0x21, 0x33, 0x21, - 0x34, 0x21, 0x35, 0x21, 0x36, 0x21, 0x37, 0x21, - 0x38, 0x21, 0x39, 0x21, 0x3A, 0x21, 0x3B, 0x21, - 0x3C, 0x21, 0x3D, 0x21, 0x3E, 0x21, 0x3F, 0x21, - 0x40, 0x21, 0x41, 0x21, 0x42, 0x21, 0x43, 0x21, - 0x44, 0x21, 0x45, 0x21, 0x46, 0x21, 0x47, 0x21, - 0x48, 0x21, 0x49, 0x21, 0x4A, 0x21, 0x4B, 0x21, - 0x4C, 0x21, 0x4D, 0x21, 0x32, 0x21, 0x4F, 0x21, - 0x50, 0x21, 0x51, 0x21, 0x52, 0x21, 0x53, 0x21, - 0x54, 0x21, 0x55, 0x21, 0x56, 0x21, 0x57, 0x21, - 0x58, 0x21, 0x59, 0x21, 0x5A, 0x21, 0x5B, 0x21, - 0x5C, 0x21, 0x5D, 0x21, 0x5E, 0x21, 0x5F, 0x21, - 0x60, 0x21, 0x61, 0x21, 0x62, 0x21, 0x63, 0x21, - 0x64, 0x21, 0x65, 0x21, 0x66, 0x21, 0x67, 0x21, - 0x68, 0x21, 0x69, 0x21, 0x6A, 0x21, 0x6B, 0x21, - 0x6C, 0x21, 0x6D, 0x21, 0x6E, 0x21, 0x6F, 0x21, - 0x60, 0x21, 0x61, 0x21, 0x62, 0x21, 0x63, 0x21, - 0x64, 0x21, 0x65, 0x21, 0x66, 0x21, 0x67, 0x21, - 0x68, 0x21, 0x69, 0x21, 0x6A, 0x21, 0x6B, 0x21, - 0x6C, 0x21, 0x6D, 0x21, 0x6E, 0x21, 0x6F, 0x21, - 0x80, 0x21, 0x81, 0x21, 0x82, 0x21, 0x83, 0x21, - 0x83, 0x21, 0xFF, 0xFF, 0x4B, 0x03, 0xB6, 0x24, - 0xB7, 0x24, 0xB8, 0x24, 0xB9, 0x24, 0xBA, 0x24, - 0xBB, 0x24, 0xBC, 0x24, 0xBD, 0x24, 0xBE, 0x24, - 0xBF, 0x24, 0xC0, 0x24, 0xC1, 0x24, 0xC2, 0x24, - 0xC3, 0x24, 0xC4, 0x24, 0xC5, 0x24, 0xC6, 0x24, - 0xC7, 0x24, 0xC8, 0x24, 0xC9, 0x24, 0xCA, 0x24, - 0xCB, 0x24, 0xCC, 0x24, 0xCD, 0x24, 0xCE, 0x24, - 0xCF, 0x24, 0xFF, 0xFF, 0x46, 0x07, 0x00, 0x2C, - 0x01, 0x2C, 0x02, 0x2C, 0x03, 0x2C, 0x04, 0x2C, - 0x05, 0x2C, 0x06, 0x2C, 0x07, 0x2C, 0x08, 0x2C, - 0x09, 0x2C, 0x0A, 0x2C, 0x0B, 0x2C, 0x0C, 0x2C, - 0x0D, 0x2C, 0x0E, 0x2C, 0x0F, 0x2C, 0x10, 0x2C, - 0x11, 0x2C, 0x12, 0x2C, 0x13, 0x2C, 0x14, 0x2C, - 0x15, 0x2C, 0x16, 0x2C, 0x17, 0x2C, 0x18, 0x2C, - 0x19, 0x2C, 0x1A, 0x2C, 0x1B, 0x2C, 0x1C, 0x2C, - 0x1D, 0x2C, 0x1E, 0x2C, 0x1F, 0x2C, 0x20, 0x2C, - 0x21, 0x2C, 0x22, 0x2C, 0x23, 0x2C, 0x24, 0x2C, - 0x25, 0x2C, 0x26, 0x2C, 0x27, 0x2C, 0x28, 0x2C, - 0x29, 0x2C, 0x2A, 0x2C, 0x2B, 0x2C, 0x2C, 0x2C, - 0x2D, 0x2C, 0x2E, 0x2C, 0x5F, 0x2C, 0x60, 0x2C, - 0x60, 0x2C, 0x62, 0x2C, 0x63, 0x2C, 0x64, 0x2C, - 0x65, 0x2C, 0x66, 0x2C, 0x67, 0x2C, 0x67, 0x2C, - 0x69, 0x2C, 0x69, 0x2C, 0x6B, 0x2C, 0x6B, 0x2C, - 0x6D, 0x2C, 0x6E, 0x2C, 0x6F, 0x2C, 0x70, 0x2C, - 0x71, 0x2C, 0x72, 0x2C, 0x73, 0x2C, 0x74, 0x2C, - 0x75, 0x2C, 0x75, 0x2C, 0x77, 0x2C, 0x78, 0x2C, - 0x79, 0x2C, 0x7A, 0x2C, 0x7B, 0x2C, 0x7C, 0x2C, - 0x7D, 0x2C, 0x7E, 0x2C, 0x7F, 0x2C, 0x80, 0x2C, - 0x80, 0x2C, 0x82, 0x2C, 0x82, 0x2C, 0x84, 0x2C, - 0x84, 0x2C, 0x86, 0x2C, 0x86, 0x2C, 0x88, 0x2C, - 0x88, 0x2C, 0x8A, 0x2C, 0x8A, 0x2C, 0x8C, 0x2C, - 0x8C, 0x2C, 0x8E, 0x2C, 0x8E, 0x2C, 0x90, 0x2C, - 0x90, 0x2C, 0x92, 0x2C, 0x92, 0x2C, 0x94, 0x2C, - 0x94, 0x2C, 0x96, 0x2C, 0x96, 0x2C, 0x98, 0x2C, - 0x98, 0x2C, 0x9A, 0x2C, 0x9A, 0x2C, 0x9C, 0x2C, - 0x9C, 0x2C, 0x9E, 0x2C, 0x9E, 0x2C, 0xA0, 0x2C, - 0xA0, 0x2C, 0xA2, 0x2C, 0xA2, 0x2C, 0xA4, 0x2C, - 0xA4, 0x2C, 0xA6, 0x2C, 0xA6, 0x2C, 0xA8, 0x2C, - 0xA8, 0x2C, 0xAA, 0x2C, 0xAA, 0x2C, 0xAC, 0x2C, - 0xAC, 0x2C, 0xAE, 0x2C, 0xAE, 0x2C, 0xB0, 0x2C, - 0xB0, 0x2C, 0xB2, 0x2C, 0xB2, 0x2C, 0xB4, 0x2C, - 0xB4, 0x2C, 0xB6, 0x2C, 0xB6, 0x2C, 0xB8, 0x2C, - 0xB8, 0x2C, 0xBA, 0x2C, 0xBA, 0x2C, 0xBC, 0x2C, - 0xBC, 0x2C, 0xBE, 0x2C, 0xBE, 0x2C, 0xC0, 0x2C, - 0xC0, 0x2C, 0xC2, 0x2C, 0xC2, 0x2C, 0xC4, 0x2C, - 0xC4, 0x2C, 0xC6, 0x2C, 0xC6, 0x2C, 0xC8, 0x2C, - 0xC8, 0x2C, 0xCA, 0x2C, 0xCA, 0x2C, 0xCC, 0x2C, - 0xCC, 0x2C, 0xCE, 0x2C, 0xCE, 0x2C, 0xD0, 0x2C, - 0xD0, 0x2C, 0xD2, 0x2C, 0xD2, 0x2C, 0xD4, 0x2C, - 0xD4, 0x2C, 0xD6, 0x2C, 0xD6, 0x2C, 0xD8, 0x2C, - 0xD8, 0x2C, 0xDA, 0x2C, 0xDA, 0x2C, 0xDC, 0x2C, - 0xDC, 0x2C, 0xDE, 0x2C, 0xDE, 0x2C, 0xE0, 0x2C, - 0xE0, 0x2C, 0xE2, 0x2C, 0xE2, 0x2C, 0xE4, 0x2C, - 0xE5, 0x2C, 0xE6, 0x2C, 0xE7, 0x2C, 0xE8, 0x2C, - 0xE9, 0x2C, 0xEA, 0x2C, 0xEB, 0x2C, 0xEC, 0x2C, - 0xED, 0x2C, 0xEE, 0x2C, 0xEF, 0x2C, 0xF0, 0x2C, - 0xF1, 0x2C, 0xF2, 0x2C, 0xF3, 0x2C, 0xF4, 0x2C, - 0xF5, 0x2C, 0xF6, 0x2C, 0xF7, 0x2C, 0xF8, 0x2C, - 0xF9, 0x2C, 0xFA, 0x2C, 0xFB, 0x2C, 0xFC, 0x2C, - 0xFD, 0x2C, 0xFE, 0x2C, 0xFF, 0x2C, 0xA0, 0x10, - 0xA1, 0x10, 0xA2, 0x10, 0xA3, 0x10, 0xA4, 0x10, - 0xA5, 0x10, 0xA6, 0x10, 0xA7, 0x10, 0xA8, 0x10, - 0xA9, 0x10, 0xAA, 0x10, 0xAB, 0x10, 0xAC, 0x10, - 0xAD, 0x10, 0xAE, 0x10, 0xAF, 0x10, 0xB0, 0x10, - 0xB1, 0x10, 0xB2, 0x10, 0xB3, 0x10, 0xB4, 0x10, - 0xB5, 0x10, 0xB6, 0x10, 0xB7, 0x10, 0xB8, 0x10, - 0xB9, 0x10, 0xBA, 0x10, 0xBB, 0x10, 0xBC, 0x10, - 0xBD, 0x10, 0xBE, 0x10, 0xBF, 0x10, 0xC0, 0x10, - 0xC1, 0x10, 0xC2, 0x10, 0xC3, 0x10, 0xC4, 0x10, - 0xC5, 0x10, 0xFF, 0xFF, 0x1B, 0xD2, 0x21, 0xFF, - 0x22, 0xFF, 0x23, 0xFF, 0x24, 0xFF, 0x25, 0xFF, - 0x26, 0xFF, 0x27, 0xFF, 0x28, 0xFF, 0x29, 0xFF, - 0x2A, 0xFF, 0x2B, 0xFF, 0x2C, 0xFF, 0x2D, 0xFF, - 0x2E, 0xFF, 0x2F, 0xFF, 0x30, 0xFF, 0x31, 0xFF, - 0x32, 0xFF, 0x33, 0xFF, 0x34, 0xFF, 0x35, 0xFF, - 0x36, 0xFF, 0x37, 0xFF, 0x38, 0xFF, 0x39, 0xFF, - 0x3A, 0xFF, 0x5B, 0xFF, 0x5C, 0xFF, 0x5D, 0xFF, - 0x5E, 0xFF, 0x5F, 0xFF, 0x60, 0xFF, 0x61, 0xFF, - 0x62, 0xFF, 0x63, 0xFF, 0x64, 0xFF, 0x65, 0xFF, - 0x66, 0xFF, 0x67, 0xFF, 0x68, 0xFF, 0x69, 0xFF, - 0x6A, 0xFF, 0x6B, 0xFF, 0x6C, 0xFF, 0x6D, 0xFF, - 0x6E, 0xFF, 0x6F, 0xFF, 0x70, 0xFF, 0x71, 0xFF, - 0x72, 0xFF, 0x73, 0xFF, 0x74, 0xFF, 0x75, 0xFF, - 0x76, 0xFF, 0x77, 0xFF, 0x78, 0xFF, 0x79, 0xFF, - 0x7A, 0xFF, 0x7B, 0xFF, 0x7C, 0xFF, 0x7D, 0xFF, - 0x7E, 0xFF, 0x7F, 0xFF, 0x80, 0xFF, 0x81, 0xFF, - 0x82, 0xFF, 0x83, 0xFF, 0x84, 0xFF, 0x85, 0xFF, - 0x86, 0xFF, 0x87, 0xFF, 0x88, 0xFF, 0x89, 0xFF, - 0x8A, 0xFF, 0x8B, 0xFF, 0x8C, 0xFF, 0x8D, 0xFF, - 0x8E, 0xFF, 0x8F, 0xFF, 0x90, 0xFF, 0x91, 0xFF, - 0x92, 0xFF, 0x93, 0xFF, 0x94, 0xFF, 0x95, 0xFF, - 0x96, 0xFF, 0x97, 0xFF, 0x98, 0xFF, 0x99, 0xFF, - 0x9A, 0xFF, 0x9B, 0xFF, 0x9C, 0xFF, 0x9D, 0xFF, - 0x9E, 0xFF, 0x9F, 0xFF, 0xA0, 0xFF, 0xA1, 0xFF, - 0xA2, 0xFF, 0xA3, 0xFF, 0xA4, 0xFF, 0xA5, 0xFF, - 0xA6, 0xFF, 0xA7, 0xFF, 0xA8, 0xFF, 0xA9, 0xFF, - 0xAA, 0xFF, 0xAB, 0xFF, 0xAC, 0xFF, 0xAD, 0xFF, - 0xAE, 0xFF, 0xAF, 0xFF, 0xB0, 0xFF, 0xB1, 0xFF, - 0xB2, 0xFF, 0xB3, 0xFF, 0xB4, 0xFF, 0xB5, 0xFF, - 0xB6, 0xFF, 0xB7, 0xFF, 0xB8, 0xFF, 0xB9, 0xFF, - 0xBA, 0xFF, 0xBB, 0xFF, 0xBC, 0xFF, 0xBD, 0xFF, - 0xBE, 0xFF, 0xBF, 0xFF, 0xC0, 0xFF, 0xC1, 0xFF, - 0xC2, 0xFF, 0xC3, 0xFF, 0xC4, 0xFF, 0xC5, 0xFF, - 0xC6, 0xFF, 0xC7, 0xFF, 0xC8, 0xFF, 0xC9, 0xFF, - 0xCA, 0xFF, 0xCB, 0xFF, 0xCC, 0xFF, 0xCD, 0xFF, - 0xCE, 0xFF, 0xCF, 0xFF, 0xD0, 0xFF, 0xD1, 0xFF, - 0xD2, 0xFF, 0xD3, 0xFF, 0xD4, 0xFF, 0xD5, 0xFF, - 0xD6, 0xFF, 0xD7, 0xFF, 0xD8, 0xFF, 0xD9, 0xFF, - 0xDA, 0xFF, 0xDB, 0xFF, 0xDC, 0xFF, 0xDD, 0xFF, - 0xDE, 0xFF, 0xDF, 0xFF, 0xE0, 0xFF, 0xE1, 0xFF, - 0xE2, 0xFF, 0xE3, 0xFF, 0xE4, 0xFF, 0xE5, 0xFF, - 0xE6, 0xFF, 0xE7, 0xFF, 0xE8, 0xFF, 0xE9, 0xFF, - 0xEA, 0xFF, 0xEB, 0xFF, 0xEC, 0xFF, 0xED, 0xFF, - 0xEE, 0xFF, 0xEF, 0xFF, 0xF0, 0xFF, 0xF1, 0xFF, - 0xF2, 0xFF, 0xF3, 0xFF, 0xF4, 0xFF, 0xF5, 0xFF, - 0xF6, 0xFF, 0xF7, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, - 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD, 0xFF, - 0xFE, 0xFF, 0xFF, 0xFF -}; diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index d3e098b41b1a..4f362dad4436 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -1186,7 +1186,9 @@ static struct fbtft_platform_data *fbtft_properties_read(struct device *dev) if (device_property_present(dev, "led-gpios")) pdata->display.backlight = 1; if (device_property_present(dev, "init")) - pdata->display.fbtftops.init_display = fbtft_init_display_from_property; + pdata->display.fbtftops.init_display = + fbtft_init_display_from_property; + pdata->display.fbtftops.request_gpios = fbtft_request_gpios; return pdata; diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c index 2a5c630dab87..26e52cc2de64 100644 --- a/drivers/staging/fbtft/fbtft-sysfs.c +++ b/drivers/staging/fbtft/fbtft-sysfs.c @@ -25,6 +25,7 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves, unsigned long val = 0; int ret = 0; int curve_counter, value_counter; + int _count; fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__); @@ -68,7 +69,10 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves, ret = get_next_ulong(&curve_p, &val, " ", 16); if (ret) goto out; - curves[curve_counter * par->gamma.num_values + value_counter] = val; + + _count = curve_counter * par->gamma.num_values + + value_counter; + curves[_count] = val; value_counter++; } if (value_counter != par->gamma.num_values) { diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 5f782da51959..76f8c090a837 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -348,9 +348,17 @@ module_exit(fbtft_driver_module_exit); /* shorthand debug levels */ #define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS -#define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS | DEBUG_TIME_FIRST_UPDATE) -#define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY | DEBUG_BLANK | DEBUG_REQUEST_GPIOS | DEBUG_FREE_GPIOS | DEBUG_VERIFY_GPIOS | DEBUG_BACKLIGHT | DEBUG_SYSFS) -#define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE | DEBUG_FB_FILLRECT | DEBUG_FB_COPYAREA | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK) +#define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS \ + | DEBUG_TIME_FIRST_UPDATE) +#define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY \ + | DEBUG_BLANK | DEBUG_REQUEST_GPIOS \ + | DEBUG_FREE_GPIOS \ + | DEBUG_VERIFY_GPIOS \ + | DEBUG_BACKLIGHT | DEBUG_SYSFS) +#define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE \ + | DEBUG_FB_FILLRECT \ + | DEBUG_FB_COPYAREA \ + | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK) #define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY) #define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5) #define DEBUG_LEVEL_7 0xFFFFFFFF @@ -398,8 +406,8 @@ do { \ #define fbtft_par_dbg(level, par, format, arg...) \ do { \ - if (unlikely(par->debug & level)) \ - dev_info(par->info->device, format, ##arg); \ + if (unlikely((par)->debug & (level))) \ + dev_info((par)->info->device, format, ##arg); \ } while (0) #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \ diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c index 39c0fe347188..676d1ad1b50d 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c @@ -1492,7 +1492,8 @@ static void ethsw_unregister_notifier(struct device *dev) err = unregister_switchdev_blocking_notifier(nb); if (err) dev_err(dev, - "Failed to unregister switchdev blocking notifier (%d)\n", err); + "Failed to unregister switchdev blocking notifier (%d)\n", + err); err = unregister_switchdev_notifier(ðsw->port_switchdev_nb); if (err) diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c index be6b50f454b4..cd181a64f737 100644 --- a/drivers/staging/gasket/gasket_core.c +++ b/drivers/staging/gasket/gasket_core.c @@ -692,8 +692,7 @@ static bool gasket_mmap_has_permissions(struct gasket_dev *gasket_dev, (vma->vm_flags & (VM_WRITE | VM_READ | VM_EXEC)); if (requested_permissions & ~(bar_permissions)) { dev_dbg(gasket_dev->dev, - "Attempting to map a region with requested permissions " - "0x%x, but region has permissions 0x%x.\n", + "Attempting to map a region with requested permissions 0x%x, but region has permissions 0x%x.\n", requested_permissions, bar_permissions); return false; } @@ -1180,8 +1179,7 @@ static int gasket_open(struct inode *inode, struct file *filp) inode->i_size = 0; dev_dbg(gasket_dev->dev, - "Attempting to open with tgid %u (%s) (f_mode: 0%03o, " - "fmode_write: %d is_root: %u)\n", + "Attempting to open with tgid %u (%s) (f_mode: 0%03o, fmode_write: %d is_root: %u)\n", current->tgid, task_name, filp->f_mode, (filp->f_mode & FMODE_WRITE), is_root); @@ -1258,8 +1256,7 @@ static int gasket_release(struct inode *inode, struct file *file) mutex_lock(&gasket_dev->mutex); dev_dbg(gasket_dev->dev, - "Releasing device node. Call origin: tgid %u (%s) " - "(f_mode: 0%03o, fmode_write: %d, is_root: %u)\n", + "Releasing device node. Call origin: tgid %u (%s) (f_mode: 0%03o, fmode_write: %d, is_root: %u)\n", current->tgid, task_name, file->f_mode, (file->f_mode & FMODE_WRITE), is_root); dev_dbg(gasket_dev->dev, "Current open count (owning tgid %u): %d\n", diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c index db11498f6fc7..354727f0a1fc 100644 --- a/drivers/staging/gdm724x/gdm_lte.c +++ b/drivers/staging/gdm724x/gdm_lte.c @@ -513,7 +513,7 @@ static int gdm_lte_event_send(struct net_device *dev, char *buf, int len) length = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), hci->len) + HCI_HEADER_SIZE; - return netlink_send(lte_event.sock, idx, 0, buf, length); + return netlink_send(lte_event.sock, idx, 0, buf, length, dev); } static void gdm_lte_event_rcv(struct net_device *dev, u16 type, diff --git a/drivers/staging/gdm724x/gdm_mux.h b/drivers/staging/gdm724x/gdm_mux.h index 51c22e3d8aeb..87b8d921fdc8 100644 --- a/drivers/staging/gdm724x/gdm_mux.h +++ b/drivers/staging/gdm724x/gdm_mux.h @@ -29,7 +29,7 @@ struct mux_pkt_header { __le32 seq_num; __le32 payload_size; __le16 packet_type; - unsigned char data[0]; + unsigned char data[]; }; struct mux_tx { diff --git a/drivers/staging/gdm724x/hci_packet.h b/drivers/staging/gdm724x/hci_packet.h index 6dea3694afdd..faecdfbc664f 100644 --- a/drivers/staging/gdm724x/hci_packet.h +++ b/drivers/staging/gdm724x/hci_packet.h @@ -28,7 +28,7 @@ struct hci_packet { __dev16 cmd_evt; __dev16 len; - u8 data[0]; + u8 data[]; } __packed; struct tlv { @@ -51,7 +51,7 @@ struct sdu { __dev32 dft_eps_ID; __dev32 bearer_ID; __dev32 nic_type; - u8 data[0]; + u8 data[]; } __packed; struct multi_sdu { @@ -59,7 +59,7 @@ struct multi_sdu { __dev16 len; __dev16 num_packet; __dev16 reserved; - u8 data[0]; + u8 data[]; } __packed; struct hci_pdn_table_ind { diff --git a/drivers/staging/gdm724x/netlink_k.c b/drivers/staging/gdm724x/netlink_k.c index 92440c3f055b..7902e52a699b 100644 --- a/drivers/staging/gdm724x/netlink_k.c +++ b/drivers/staging/gdm724x/netlink_k.c @@ -89,7 +89,8 @@ struct sock *netlink_init(int unit, return sock; } -int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len) +int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len, + struct net_device *dev) { static u32 seq; struct sk_buff *skb = NULL; @@ -118,8 +119,8 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len) return len; if (ret != -ESRCH) - pr_err("nl broadcast g=%d, t=%d, l=%d, r=%d\n", - group, type, len, ret); + netdev_err(dev, "nl broadcast g=%d, t=%d, l=%d, r=%d\n", + group, type, len, ret); else if (netlink_has_listeners(sock, group + 1)) return -EAGAIN; diff --git a/drivers/staging/gdm724x/netlink_k.h b/drivers/staging/gdm724x/netlink_k.h index c9e1d3b2d54f..d42eea9bea3e 100644 --- a/drivers/staging/gdm724x/netlink_k.h +++ b/drivers/staging/gdm724x/netlink_k.h @@ -10,6 +10,7 @@ struct sock *netlink_init(int unit, void (*cb)(struct net_device *dev, u16 type, void *msg, int len)); -int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len); +int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len, + struct net_device *dev); #endif /* _NETLINK_K_H_ */ diff --git a/drivers/staging/greybus/audio_apbridgea.h b/drivers/staging/greybus/audio_apbridgea.h index 3f1f4dd2c61a..efec0f815efd 100644 --- a/drivers/staging/greybus/audio_apbridgea.h +++ b/drivers/staging/greybus/audio_apbridgea.h @@ -65,7 +65,7 @@ struct audio_apbridgea_hdr { __u8 type; __le16 i2s_port; - __u8 data[0]; + __u8 data[]; } __packed; struct audio_apbridgea_set_config_request { diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c index 1ff34abd5692..36d99f9e419e 100644 --- a/drivers/staging/greybus/gpio.c +++ b/drivers/staging/greybus/gpio.c @@ -364,8 +364,7 @@ static int gb_gpio_request_handler(struct gb_operation *op) struct gb_message *request; struct gb_gpio_irq_event_request *event; u8 type = op->type; - int irq; - struct irq_desc *desc; + int irq, ret; if (type != GB_GPIO_TYPE_IRQ_EVENT) { dev_err(dev, "unsupported unsolicited request: %u\n", type); @@ -391,17 +390,15 @@ static int gb_gpio_request_handler(struct gb_operation *op) dev_err(dev, "failed to find IRQ\n"); return -EINVAL; } - desc = irq_to_desc(irq); - if (!desc) { - dev_err(dev, "failed to look up irq\n"); - return -EINVAL; - } local_irq_disable(); - generic_handle_irq_desc(desc); + ret = generic_handle_irq(irq); local_irq_enable(); - return 0; + if (ret) + dev_err(dev, "failed to invoke irq handler\n"); + + return ret; } static int gb_gpio_request(struct gpio_chip *chip, unsigned int offset) diff --git a/drivers/staging/greybus/i2c.c b/drivers/staging/greybus/i2c.c index ab06fc3b9e7e..de2f6516da09 100644 --- a/drivers/staging/greybus/i2c.c +++ b/drivers/staging/greybus/i2c.c @@ -215,20 +215,6 @@ static int gb_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, return gb_i2c_transfer_operation(gb_i2c_dev, msgs, msg_count); } -#if 0 -/* Later */ -static int gb_i2c_smbus_xfer(struct i2c_adapter *adap, - u16 addr, unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data *data) -{ - struct gb_i2c_device *gb_i2c_dev; - - gb_i2c_dev = i2c_get_adapdata(adap); - - return 0; -} -#endif - static u32 gb_i2c_functionality(struct i2c_adapter *adap) { struct gb_i2c_device *gb_i2c_dev = i2c_get_adapdata(adap); @@ -238,7 +224,6 @@ static u32 gb_i2c_functionality(struct i2c_adapter *adap) static const struct i2c_algorithm gb_i2c_algorithm = { .master_xfer = gb_i2c_master_xfer, - /* .smbus_xfer = gb_i2c_smbus_xfer, */ .functionality = gb_i2c_functionality, }; @@ -281,7 +266,6 @@ static int gb_i2c_probe(struct gbphy_device *gbphy_dev, adapter->owner = THIS_MODULE; adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; adapter->algo = &gb_i2c_algorithm; - /* adapter->algo_data = what? */ adapter->dev.parent = &gbphy_dev->dev; snprintf(adapter->name, sizeof(adapter->name), "Greybus i2c adapter"); diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c index 64a17dfe3b6e..2a375f407d38 100644 --- a/drivers/staging/greybus/raw.c +++ b/drivers/staging/greybus/raw.c @@ -29,7 +29,7 @@ struct gb_raw { struct raw_data { struct list_head entry; u32 len; - u8 data[0]; + u8 data[]; }; static struct class *raw_class; diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c index 69c6dce9be31..867bf289df2e 100644 --- a/drivers/staging/greybus/tools/loopback_test.c +++ b/drivers/staging/greybus/tools/loopback_test.c @@ -802,8 +802,9 @@ static void prepare_devices(struct loopback_test *t) write_sysfs_val(t->devices[i].sysfs_entry, "outstanding_operations_max", t->async_outstanding_operations); - } else + } else { write_sysfs_val(t->devices[i].sysfs_entry, "async", 0); + } } } diff --git a/drivers/staging/hp/Kconfig b/drivers/staging/hp/Kconfig deleted file mode 100644 index f20ab21a6b2a..000000000000 --- a/drivers/staging/hp/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# -# HP network device configuration -# - -config NET_VENDOR_HP - bool "HP devices" - default y - depends on ETHERNET - depends on ISA || EISA || PCI - ---help--- - If you have a network (Ethernet) card belonging to this class, say Y. - - Note that the answer to this question doesn't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about HP cards. If you say Y, you will be asked for - your specific card in the following questions. - -if NET_VENDOR_HP - -config HP100 - tristate "HP 10/100VG PCLAN (ISA, EISA, PCI) support" - depends on (ISA || EISA || PCI) - ---help--- - If you have a network (Ethernet) card of this type, say Y here. - - To compile this driver as a module, choose M here. The module - will be called hp100. - -endif # NET_VENDOR_HP diff --git a/drivers/staging/hp/Makefile b/drivers/staging/hp/Makefile deleted file mode 100644 index 5ed723bb11e2..000000000000 --- a/drivers/staging/hp/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# -# Makefile for the HP network device drivers. -# - -obj-$(CONFIG_HP100) += hp100.o diff --git a/drivers/staging/hp/hp100.c b/drivers/staging/hp/hp100.c deleted file mode 100644 index e2f0b58e5dfd..000000000000 --- a/drivers/staging/hp/hp100.c +++ /dev/null @@ -1,3034 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -** hp100.c -** HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters -** -** $Id: hp100.c,v 1.58 2001/09/24 18:03:01 perex Exp perex $ -** -** Based on the HP100 driver written by Jaroslav Kysela <perex@jcu.cz> -** Extended for new busmaster capable chipsets by -** Siegfried "Frieder" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de> -** -** Maintained by: Jaroslav Kysela <perex@perex.cz> -** -** This driver has only been tested with -** -- HP J2585B 10/100 Mbit/s PCI Busmaster -** -- HP J2585A 10/100 Mbit/s PCI -** -- HP J2970A 10 Mbit/s PCI Combo 10base-T/BNC -** -- HP J2973A 10 Mbit/s PCI 10base-T -** -- HP J2573 10/100 ISA -** -- Compex ReadyLink ENET100-VG4 10/100 Mbit/s PCI / EISA -** -- Compex FreedomLine 100/VG 10/100 Mbit/s ISA / EISA / PCI -** -** but it should also work with the other CASCADE based adapters. -** -** TODO: -** - J2573 seems to hang sometimes when in shared memory mode. -** - Mode for Priority TX -** - Check PCI registers, performance might be improved? -** - To reduce interrupt load in busmaster, one could switch off -** the interrupts that are used to refill the queues whenever the -** queues are filled up to more than a certain threshold. -** - some updates for EISA version of card -** -** -** -** 1.57c -> 1.58 -** - used indent to change coding-style -** - added KTI DP-200 EISA ID -** - ioremap is also used for low (<1MB) memory (multi-architecture support) -** -** 1.57b -> 1.57c - Arnaldo Carvalho de Melo <acme@conectiva.com.br> -** - release resources on failure in init_module -** -** 1.57 -> 1.57b - Jean II -** - fix spinlocks, SMP is now working ! -** -** 1.56 -> 1.57 -** - updates for new PCI interface for 2.1 kernels -** -** 1.55 -> 1.56 -** - removed printk in misc. interrupt and update statistics to allow -** monitoring of card status -** - timing changes in xmit routines, relogin to 100VG hub added when -** driver does reset -** - included fix for Compex FreedomLine PCI adapter -** -** 1.54 -> 1.55 -** - fixed bad initialization in init_module -** - added Compex FreedomLine adapter -** - some fixes in card initialization -** -** 1.53 -> 1.54 -** - added hardware multicast filter support (doesn't work) -** - little changes in hp100_sense_lan routine -** - added support for Coax and AUI (J2970) -** - fix for multiple cards and hp100_mode parameter (insmod) -** - fix for shared IRQ -** -** 1.52 -> 1.53 -** - fixed bug in multicast support -** -*/ - -#define HP100_DEFAULT_PRIORITY_TX 0 - -#undef HP100_DEBUG -#undef HP100_DEBUG_B /* Trace */ -#undef HP100_DEBUG_BM /* Debug busmaster code (PDL stuff) */ - -#undef HP100_DEBUG_TRAINING /* Debug login-to-hub procedure */ -#undef HP100_DEBUG_TX -#undef HP100_DEBUG_IRQ -#undef HP100_DEBUG_RX - -#undef HP100_MULTICAST_FILTER /* Need to be debugged... */ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/string.h> -#include <linux/errno.h> -#include <linux/ioport.h> -#include <linux/interrupt.h> -#include <linux/eisa.h> -#include <linux/pci.h> -#include <linux/dma-mapping.h> -#include <linux/spinlock.h> -#include <linux/netdevice.h> -#include <linux/etherdevice.h> -#include <linux/skbuff.h> -#include <linux/types.h> -#include <linux/delay.h> -#include <linux/init.h> -#include <linux/bitops.h> -#include <linux/jiffies.h> - -#include <asm/io.h> - -#include "hp100.h" - -/* - * defines - */ - -#define HP100_BUS_ISA 0 -#define HP100_BUS_EISA 1 -#define HP100_BUS_PCI 2 - -#define HP100_REGION_SIZE 0x20 /* for ioports */ -#define HP100_SIG_LEN 8 /* same as EISA_SIG_LEN */ - -#define HP100_MAX_PACKET_SIZE (1536+4) -#define HP100_MIN_PACKET_SIZE 60 - -#ifndef HP100_DEFAULT_RX_RATIO -/* default - 75% onboard memory on the card are used for RX packets */ -#define HP100_DEFAULT_RX_RATIO 75 -#endif - -#ifndef HP100_DEFAULT_PRIORITY_TX -/* default - don't enable transmit outgoing packets as priority */ -#define HP100_DEFAULT_PRIORITY_TX 0 -#endif - -/* - * structures - */ - -struct hp100_private { - spinlock_t lock; - char id[HP100_SIG_LEN]; - u_short chip; - u_short soft_model; - u_int memory_size; - u_int virt_memory_size; - u_short rx_ratio; /* 1 - 99 */ - u_short priority_tx; /* != 0 - priority tx */ - u_short mode; /* PIO, Shared Mem or Busmaster */ - u_char bus; - struct pci_dev *pci_dev; - short mem_mapped; /* memory mapped access */ - void __iomem *mem_ptr_virt; /* virtual memory mapped area, maybe NULL */ - unsigned long mem_ptr_phys; /* physical memory mapped area */ - short lan_type; /* 10Mb/s, 100Mb/s or -1 (error) */ - int hub_status; /* was login to hub successful? */ - u_char mac1_mode; - u_char mac2_mode; - u_char hash_bytes[8]; - - /* Rings for busmaster mode: */ - hp100_ring_t *rxrhead; /* Head (oldest) index into rxring */ - hp100_ring_t *rxrtail; /* Tail (newest) index into rxring */ - hp100_ring_t *txrhead; /* Head (oldest) index into txring */ - hp100_ring_t *txrtail; /* Tail (newest) index into txring */ - - hp100_ring_t rxring[MAX_RX_PDL]; - hp100_ring_t txring[MAX_TX_PDL]; - - u_int *page_vaddr_algn; /* Aligned virtual address of allocated page */ - u_long whatever_offset; /* Offset to bus/phys/dma address */ - int rxrcommit; /* # Rx PDLs committed to adapter */ - int txrcommit; /* # Tx PDLs committed to adapter */ -}; - -/* - * variables - */ -#ifdef CONFIG_ISA -static const char *hp100_isa_tbl[] = { - "HWPF150", /* HP J2573 rev A */ - "HWP1950", /* HP J2573 */ -}; -#endif - -static const struct eisa_device_id hp100_eisa_tbl[] = { - { "HWPF180" }, /* HP J2577 rev A */ - { "HWP1920" }, /* HP 27248B */ - { "HWP1940" }, /* HP J2577 */ - { "HWP1990" }, /* HP J2577 */ - { "CPX0301" }, /* ReadyLink ENET100-VG4 */ - { "CPX0401" }, /* FreedomLine 100/VG */ - { "" } /* Mandatory final entry ! */ -}; -MODULE_DEVICE_TABLE(eisa, hp100_eisa_tbl); - -static const struct pci_device_id hp100_pci_tbl[] = { - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585A, PCI_ANY_ID, PCI_ANY_ID,}, - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2585B, PCI_ANY_ID, PCI_ANY_ID,}, - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2970A, PCI_ANY_ID, PCI_ANY_ID,}, - {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_J2973A, PCI_ANY_ID, PCI_ANY_ID,}, - {PCI_VENDOR_ID_COMPEX, PCI_DEVICE_ID_COMPEX_ENET100VG4, PCI_ANY_ID, PCI_ANY_ID,}, - {PCI_VENDOR_ID_COMPEX2, PCI_DEVICE_ID_COMPEX2_100VG, PCI_ANY_ID, PCI_ANY_ID,}, -/* {PCI_VENDOR_ID_KTI, PCI_DEVICE_ID_KTI_DP200, PCI_ANY_ID, PCI_ANY_ID }, */ - {} /* Terminating entry */ -}; -MODULE_DEVICE_TABLE(pci, hp100_pci_tbl); - -static int hp100_rx_ratio = HP100_DEFAULT_RX_RATIO; -static int hp100_priority_tx = HP100_DEFAULT_PRIORITY_TX; -static int hp100_mode = 1; - -module_param(hp100_rx_ratio, int, 0); -module_param(hp100_priority_tx, int, 0); -module_param(hp100_mode, int, 0); - -/* - * prototypes - */ - -static int hp100_probe1(struct net_device *dev, int ioaddr, u_char bus, - struct pci_dev *pci_dev); - - -static int hp100_open(struct net_device *dev); -static int hp100_close(struct net_device *dev); -static netdev_tx_t hp100_start_xmit(struct sk_buff *skb, - struct net_device *dev); -static netdev_tx_t hp100_start_xmit_bm(struct sk_buff *skb, - struct net_device *dev); -static void hp100_rx(struct net_device *dev); -static struct net_device_stats *hp100_get_stats(struct net_device *dev); -static void hp100_misc_interrupt(struct net_device *dev); -static void hp100_update_stats(struct net_device *dev); -static void hp100_clear_stats(struct hp100_private *lp, int ioaddr); -static void hp100_set_multicast_list(struct net_device *dev); -static irqreturn_t hp100_interrupt(int irq, void *dev_id); -static void hp100_start_interface(struct net_device *dev); -static void hp100_stop_interface(struct net_device *dev); -static void hp100_load_eeprom(struct net_device *dev, u_short ioaddr); -static int hp100_sense_lan(struct net_device *dev); -static int hp100_login_to_vg_hub(struct net_device *dev, - u_short force_relogin); -static int hp100_down_vg_link(struct net_device *dev); -static void hp100_cascade_reset(struct net_device *dev, u_short enable); -static void hp100_BM_shutdown(struct net_device *dev); -static void hp100_mmuinit(struct net_device *dev); -static void hp100_init_pdls(struct net_device *dev); -static int hp100_init_rxpdl(struct net_device *dev, - register hp100_ring_t * ringptr, - register u_int * pdlptr); -static int hp100_init_txpdl(struct net_device *dev, - register hp100_ring_t * ringptr, - register u_int * pdlptr); -static void hp100_rxfill(struct net_device *dev); -static void hp100_hwinit(struct net_device *dev); -static void hp100_clean_txring(struct net_device *dev); -#ifdef HP100_DEBUG -static void hp100_RegisterDump(struct net_device *dev); -#endif - -/* Conversion to new PCI API : - * Convert an address in a kernel buffer to a bus/phys/dma address. - * This work *only* for memory fragments part of lp->page_vaddr, - * because it was properly DMA allocated via pci_alloc_consistent(), - * so we just need to "retrieve" the original mapping to bus/phys/dma - * address - Jean II */ -static inline dma_addr_t virt_to_whatever(struct net_device *dev, u32 * ptr) -{ - struct hp100_private *lp = netdev_priv(dev); - return ((u_long) ptr) + lp->whatever_offset; -} - -static inline u_int pdl_map_data(struct hp100_private *lp, void *data) -{ - return pci_map_single(lp->pci_dev, data, - MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE); -} - -/* TODO: This function should not really be needed in a good design... */ -static void wait(void) -{ - mdelay(1); -} - -/* - * probe functions - * These functions should - if possible - avoid doing write operations - * since this could cause problems when the card is not installed. - */ - -/* - * Read board id and convert to string. - * Effectively same code as decode_eisa_sig - */ -static const char *hp100_read_id(int ioaddr) -{ - int i; - static char str[HP100_SIG_LEN]; - unsigned char sig[4], sum; - unsigned short rev; - - hp100_page(ID_MAC_ADDR); - sum = 0; - for (i = 0; i < 4; i++) { - sig[i] = hp100_inb(BOARD_ID + i); - sum += sig[i]; - } - - sum += hp100_inb(BOARD_ID + i); - if (sum != 0xff) - return NULL; /* bad checksum */ - - str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1); - str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1); - str[2] = (sig[1] & 0x1f) + ('A' - 1); - rev = (sig[2] << 8) | sig[3]; - sprintf(str + 3, "%04X", rev); - - return str; -} - -#ifdef CONFIG_ISA -static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr) -{ - const char *sig; - int i; - - if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100")) - goto err; - - if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) { - release_region(ioaddr, HP100_REGION_SIZE); - goto err; - } - - sig = hp100_read_id(ioaddr); - release_region(ioaddr, HP100_REGION_SIZE); - - if (sig == NULL) - goto err; - - i = match_string(hp100_isa_tbl, ARRAY_SIZE(hp100_isa_tbl), sig); - if (i < 0) - goto err; - - return hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL); - err: - return -ENODEV; - -} -/* - * Probe for ISA board. - * EISA and PCI are handled by device infrastructure. - */ - -static int __init hp100_isa_probe(struct net_device *dev, int addr) -{ - int err = -ENODEV; - - /* Probe for a specific ISA address */ - if (addr > 0xff && addr < 0x400) - err = hp100_isa_probe1(dev, addr); - - else if (addr != 0) - err = -ENXIO; - - else { - /* Probe all ISA possible port regions */ - for (addr = 0x100; addr < 0x400; addr += 0x20) { - err = hp100_isa_probe1(dev, addr); - if (!err) - break; - } - } - return err; -} -#endif /* CONFIG_ISA */ - -#if !defined(MODULE) && defined(CONFIG_ISA) -struct net_device * __init hp100_probe(int unit) -{ - struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private)); - int err; - - if (!dev) - return ERR_PTR(-ENODEV); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4200, TRACE); - printk("hp100: %s: probe\n", dev->name); -#endif - - if (unit >= 0) { - sprintf(dev->name, "eth%d", unit); - netdev_boot_setup_check(dev); - } - - err = hp100_isa_probe(dev, dev->base_addr); - if (err) - goto out; - - return dev; - out: - free_netdev(dev); - return ERR_PTR(err); -} -#endif /* !MODULE && CONFIG_ISA */ - -static const struct net_device_ops hp100_bm_netdev_ops = { - .ndo_open = hp100_open, - .ndo_stop = hp100_close, - .ndo_start_xmit = hp100_start_xmit_bm, - .ndo_get_stats = hp100_get_stats, - .ndo_set_rx_mode = hp100_set_multicast_list, - .ndo_set_mac_address = eth_mac_addr, - .ndo_validate_addr = eth_validate_addr, -}; - -static const struct net_device_ops hp100_netdev_ops = { - .ndo_open = hp100_open, - .ndo_stop = hp100_close, - .ndo_start_xmit = hp100_start_xmit, - .ndo_get_stats = hp100_get_stats, - .ndo_set_rx_mode = hp100_set_multicast_list, - .ndo_set_mac_address = eth_mac_addr, - .ndo_validate_addr = eth_validate_addr, -}; - -static int hp100_probe1(struct net_device *dev, int ioaddr, u_char bus, - struct pci_dev *pci_dev) -{ - int i; - int err = -ENODEV; - const char *eid; - u_int chip; - u_char uc; - u_int memory_size = 0, virt_memory_size = 0; - u_short local_mode, lsw; - short mem_mapped; - unsigned long mem_ptr_phys; - void __iomem *mem_ptr_virt; - struct hp100_private *lp; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4201, TRACE); - printk("hp100: %s: probe1\n", dev->name); -#endif - - /* memory region for programmed i/o */ - if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100")) - goto out1; - - if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) - goto out2; - - chip = hp100_inw(PAGING) & HP100_CHIPID_MASK; -#ifdef HP100_DEBUG - if (chip == HP100_CHIPID_SHASTA) - printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name); - else if (chip == HP100_CHIPID_RAINIER) - printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name); - else if (chip == HP100_CHIPID_LASSEN) - printk("hp100: %s: Lassen Chip detected.\n", dev->name); - else - printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n", dev->name, chip); -#endif - - dev->base_addr = ioaddr; - - eid = hp100_read_id(ioaddr); - if (eid == NULL) { /* bad checksum? */ - printk(KERN_WARNING "%s: bad ID checksum at base port 0x%x\n", - __func__, ioaddr); - goto out2; - } - - hp100_page(ID_MAC_ADDR); - for (i = uc = 0; i < 7; i++) - uc += hp100_inb(LAN_ADDR + i); - if (uc != 0xff) { - printk(KERN_WARNING - "%s: bad lan address checksum at port 0x%x)\n", - __func__, ioaddr); - err = -EIO; - goto out2; - } - - /* Make sure, that all registers are correctly updated... */ - - hp100_load_eeprom(dev, ioaddr); - wait(); - - /* - * Determine driver operation mode - * - * Use the variable "hp100_mode" upon insmod or as kernel parameter to - * force driver modes: - * hp100_mode=1 -> default, use busmaster mode if configured. - * hp100_mode=2 -> enable shared memory mode - * hp100_mode=3 -> force use of i/o mapped mode. - * hp100_mode=4 -> same as 1, but re-set the enable bit on the card. - */ - - /* - * LSW values: - * 0x2278 -> J2585B, PnP shared memory mode - * 0x2270 -> J2585B, shared memory mode, 0xdc000 - * 0xa23c -> J2585B, I/O mapped mode - * 0x2240 -> EISA COMPEX, BusMaster (Shasta Chip) - * 0x2220 -> EISA HP, I/O (Shasta Chip) - * 0x2260 -> EISA HP, BusMaster (Shasta Chip) - */ - -#if 0 - local_mode = 0x2270; - hp100_outw(0xfefe, OPTION_LSW); - hp100_outw(local_mode | HP100_SET_LB | HP100_SET_HB, OPTION_LSW); -#endif - - /* hp100_mode value maybe used in future by another card */ - local_mode = hp100_mode; - if (local_mode < 1 || local_mode > 4) - local_mode = 1; /* default */ -#ifdef HP100_DEBUG - printk("hp100: %s: original LSW = 0x%x\n", dev->name, - hp100_inw(OPTION_LSW)); -#endif - - if (local_mode == 3) { - hp100_outw(HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW); - hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); - hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); - printk("hp100: IO mapped mode forced.\n"); - } else if (local_mode == 2) { - hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); - hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); - hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); - printk("hp100: Shared memory mode requested.\n"); - } else if (local_mode == 4) { - if (chip == HP100_CHIPID_LASSEN) { - hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_SET_HB, OPTION_LSW); - hp100_outw(HP100_IO_EN | HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW); - printk("hp100: Busmaster mode requested.\n"); - } - local_mode = 1; - } - - if (local_mode == 1) { /* default behaviour */ - lsw = hp100_inw(OPTION_LSW); - - if ((lsw & HP100_IO_EN) && (~lsw & HP100_MEM_EN) && - (~lsw & (HP100_BM_WRITE | HP100_BM_READ))) { -#ifdef HP100_DEBUG - printk("hp100: %s: IO_EN bit is set on card.\n", dev->name); -#endif - local_mode = 3; - } else if (chip == HP100_CHIPID_LASSEN && - (lsw & (HP100_BM_WRITE | HP100_BM_READ)) == (HP100_BM_WRITE | HP100_BM_READ)) { - /* Conversion to new PCI API : - * I don't have the doc, but I assume that the card - * can map the full 32bit address space. - * Also, we can have EISA Busmaster cards (not tested), - * so beware !!! - Jean II */ - if((bus == HP100_BUS_PCI) && - (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32)))) { - /* Gracefully fallback to shared memory */ - goto busmasterfail; - } - printk("hp100: Busmaster mode enabled.\n"); - hp100_outw(HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW); - } else { - busmasterfail: -#ifdef HP100_DEBUG - printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name); - printk("hp100: %s: Trying shared memory mode.\n", dev->name); -#endif - /* In this case, try shared memory mode */ - local_mode = 2; - hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); - /* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */ - } - } -#ifdef HP100_DEBUG - printk("hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW)); -#endif - - /* Check for shared memory on the card, eventually remap it */ - hp100_page(HW_MAP); - mem_mapped = ((hp100_inw(OPTION_LSW) & (HP100_MEM_EN)) != 0); - mem_ptr_phys = 0UL; - mem_ptr_virt = NULL; - memory_size = (8192 << ((hp100_inb(SRAM) >> 5) & 0x07)); - virt_memory_size = 0; - - /* For memory mapped or busmaster mode, we want the memory address */ - if (mem_mapped || (local_mode == 1)) { - mem_ptr_phys = (hp100_inw(MEM_MAP_LSW) | (hp100_inw(MEM_MAP_MSW) << 16)); - mem_ptr_phys &= ~0x1fff; /* 8k alignment */ - - if (bus == HP100_BUS_ISA && (mem_ptr_phys & ~0xfffff) != 0) { - printk("hp100: Can only use programmed i/o mode.\n"); - mem_ptr_phys = 0; - mem_mapped = 0; - local_mode = 3; /* Use programmed i/o */ - } - - /* We do not need access to shared memory in busmaster mode */ - /* However in slave mode we need to remap high (>1GB) card memory */ - if (local_mode != 1) { /* = not busmaster */ - /* We try with smaller memory sizes, if ioremap fails */ - for (virt_memory_size = memory_size; virt_memory_size > 16383; virt_memory_size >>= 1) { - if ((mem_ptr_virt = ioremap((u_long) mem_ptr_phys, virt_memory_size)) == NULL) { -#ifdef HP100_DEBUG - printk("hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, mem_ptr_phys); -#endif - } else { -#ifdef HP100_DEBUG - printk("hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to %p.\n", dev->name, virt_memory_size, mem_ptr_phys, mem_ptr_virt); -#endif - break; - } - } - - if (mem_ptr_virt == NULL) { /* all ioremap tries failed */ - printk("hp100: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n"); - local_mode = 3; - virt_memory_size = 0; - } - } - } - - if (local_mode == 3) { /* io mapped forced */ - mem_mapped = 0; - mem_ptr_phys = 0; - mem_ptr_virt = NULL; - printk("hp100: Using (slow) programmed i/o mode.\n"); - } - - /* Initialise the "private" data structure for this card. */ - lp = netdev_priv(dev); - - spin_lock_init(&lp->lock); - strlcpy(lp->id, eid, HP100_SIG_LEN); - lp->chip = chip; - lp->mode = local_mode; - lp->bus = bus; - lp->pci_dev = pci_dev; - lp->priority_tx = hp100_priority_tx; - lp->rx_ratio = hp100_rx_ratio; - lp->mem_ptr_phys = mem_ptr_phys; - lp->mem_ptr_virt = mem_ptr_virt; - hp100_page(ID_MAC_ADDR); - lp->soft_model = hp100_inb(SOFT_MODEL); - lp->mac1_mode = HP100_MAC1MODE3; - lp->mac2_mode = HP100_MAC2MODE3; - memset(&lp->hash_bytes, 0x00, 8); - - dev->base_addr = ioaddr; - - lp->memory_size = memory_size; - lp->virt_memory_size = virt_memory_size; - lp->rx_ratio = hp100_rx_ratio; /* can be conf'd with insmod */ - - if (lp->mode == 1) /* busmaster */ - dev->netdev_ops = &hp100_bm_netdev_ops; - else - dev->netdev_ops = &hp100_netdev_ops; - - /* Ask the card for which IRQ line it is configured */ - if (bus == HP100_BUS_PCI) { - dev->irq = pci_dev->irq; - } else { - hp100_page(HW_MAP); - dev->irq = hp100_inb(IRQ_CHANNEL) & HP100_IRQMASK; - if (dev->irq == 2) - dev->irq = 9; - } - - if (lp->mode == 1) /* busmaster */ - dev->dma = 4; - - /* Ask the card for its MAC address and store it for later use. */ - hp100_page(ID_MAC_ADDR); - for (i = uc = 0; i < 6; i++) - dev->dev_addr[i] = hp100_inb(LAN_ADDR + i); - - /* Reset statistics (counters) */ - hp100_clear_stats(lp, ioaddr); - - /* If busmaster mode is wanted, a dma-capable memory area is needed for - * the rx and tx PDLs - * PCI cards can access the whole PC memory. Therefore GFP_DMA is not - * needed for the allocation of the memory area. - */ - - /* TODO: We do not need this with old cards, where PDLs are stored - * in the cards shared memory area. But currently, busmaster has been - * implemented/tested only with the lassen chip anyway... */ - if (lp->mode == 1) { /* busmaster */ - dma_addr_t page_baddr; - /* Get physically continuous memory for TX & RX PDLs */ - /* Conversion to new PCI API : - * Pages are always aligned and zeroed, no need to it ourself. - * Doc says should be OK for EISA bus as well - Jean II */ - lp->page_vaddr_algn = pci_alloc_consistent(lp->pci_dev, MAX_RINGSIZE, &page_baddr); - if (!lp->page_vaddr_algn) { - err = -ENOMEM; - goto out_mem_ptr; - } - lp->whatever_offset = ((u_long) page_baddr) - ((u_long) lp->page_vaddr_algn); - -#ifdef HP100_DEBUG_BM - printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n", dev->name, (u_int) lp->page_vaddr_algn, (u_int) lp->page_vaddr_algn + MAX_RINGSIZE); -#endif - lp->rxrcommit = lp->txrcommit = 0; - lp->rxrhead = lp->rxrtail = &(lp->rxring[0]); - lp->txrhead = lp->txrtail = &(lp->txring[0]); - } - - /* Initialise the card. */ - /* (I'm not really sure if it's a good idea to do this during probing, but - * like this it's assured that the lan connection type can be sensed - * correctly) - */ - hp100_hwinit(dev); - - /* Try to find out which kind of LAN the card is connected to. */ - lp->lan_type = hp100_sense_lan(dev); - - /* Print out a message what about what we think we have probed. */ - printk("hp100: at 0x%x, IRQ %d, ", ioaddr, dev->irq); - switch (bus) { - case HP100_BUS_EISA: - printk("EISA"); - break; - case HP100_BUS_PCI: - printk("PCI"); - break; - default: - printk("ISA"); - break; - } - printk(" bus, %dk SRAM (rx/tx %d%%).\n", lp->memory_size >> 10, lp->rx_ratio); - - if (lp->mode == 2) { /* memory mapped */ - printk("hp100: Memory area at 0x%lx-0x%lx", mem_ptr_phys, - (mem_ptr_phys + (mem_ptr_phys > 0x100000 ? (u_long) lp->memory_size : 16 * 1024)) - 1); - if (mem_ptr_virt) - printk(" (virtual base %p)", mem_ptr_virt); - printk(".\n"); - - /* Set for info when doing ifconfig */ - dev->mem_start = mem_ptr_phys; - dev->mem_end = mem_ptr_phys + lp->memory_size; - } - - printk("hp100: "); - if (lp->lan_type != HP100_LAN_ERR) - printk("Adapter is attached to "); - switch (lp->lan_type) { - case HP100_LAN_100: - printk("100Mb/s Voice Grade AnyLAN network.\n"); - break; - case HP100_LAN_10: - printk("10Mb/s network (10baseT).\n"); - break; - case HP100_LAN_COAX: - printk("10Mb/s network (coax).\n"); - break; - default: - printk("Warning! Link down.\n"); - } - - err = register_netdev(dev); - if (err) - goto out3; - - return 0; -out3: - if (local_mode == 1) - pci_free_consistent(lp->pci_dev, MAX_RINGSIZE + 0x0f, - lp->page_vaddr_algn, - virt_to_whatever(dev, lp->page_vaddr_algn)); -out_mem_ptr: - if (mem_ptr_virt) - iounmap(mem_ptr_virt); -out2: - release_region(ioaddr, HP100_REGION_SIZE); -out1: - return err; -} - -/* This procedure puts the card into a stable init state */ -static void hp100_hwinit(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4202, TRACE); - printk("hp100: %s: hwinit\n", dev->name); -#endif - - /* Initialise the card. -------------------------------------------- */ - - /* Clear all pending Ints and disable Ints */ - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* clear all pending ints */ - - hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); - hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW); - - if (lp->mode == 1) { - hp100_BM_shutdown(dev); /* disables BM, puts cascade in reset */ - wait(); - } else { - hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); - hp100_cascade_reset(dev, 1); - hp100_page(MAC_CTRL); - hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); - } - - /* Initiate EEPROM reload */ - hp100_load_eeprom(dev, 0); - - wait(); - - /* Go into reset again. */ - hp100_cascade_reset(dev, 1); - - /* Set Option Registers to a safe state */ - hp100_outw(HP100_DEBUG_EN | - HP100_RX_HDR | - HP100_EE_EN | - HP100_BM_WRITE | - HP100_BM_READ | HP100_RESET_HB | - HP100_FAKE_INT | - HP100_INT_EN | - HP100_MEM_EN | - HP100_IO_EN | HP100_RESET_LB, OPTION_LSW); - - hp100_outw(HP100_TRI_INT | - HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW); - - hp100_outb(HP100_PRIORITY_TX | - HP100_ADV_NXT_PKT | - HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW); - - /* TODO: Configure MMU for Ram Test. */ - /* TODO: Ram Test. */ - - /* Re-check if adapter is still at same i/o location */ - /* (If the base i/o in eeprom has been changed but the */ - /* registers had not been changed, a reload of the eeprom */ - /* would move the adapter to the address stored in eeprom */ - - /* TODO: Code to implement. */ - - /* Until here it was code from HWdiscover procedure. */ - /* Next comes code from mmuinit procedure of SCO BM driver which is - * called from HWconfigure in the SCO driver. */ - - /* Initialise MMU, eventually switch on Busmaster Mode, initialise - * multicast filter... - */ - hp100_mmuinit(dev); - - /* We don't turn the interrupts on here - this is done by start_interface. */ - wait(); /* TODO: Do we really need this? */ - - /* Enable Hardware (e.g. unreset) */ - hp100_cascade_reset(dev, 0); - - /* ------- initialisation complete ----------- */ - - /* Finally try to log in the Hub if there may be a VG connection. */ - if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR)) - hp100_login_to_vg_hub(dev, 0); /* relogin */ - -} - - -/* - * mmuinit - Reinitialise Cascade MMU and MAC settings. - * Note: Must already be in reset and leaves card in reset. - */ -static void hp100_mmuinit(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - int i; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4203, TRACE); - printk("hp100: %s: mmuinit\n", dev->name); -#endif - -#ifdef HP100_DEBUG - if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) { - printk("hp100: %s: Not in reset when entering mmuinit. Fix me.\n", dev->name); - return; - } -#endif - - /* Make sure IRQs are masked off and ack'ed. */ - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ - - /* - * Enable Hardware - * - Clear Debug En, Rx Hdr Pipe, EE En, I/O En, Fake Int and Intr En - * - Set Tri-State Int, Bus Master Rd/Wr, and Mem Map Disable - * - Clear Priority, Advance Pkt and Xmit Cmd - */ - - hp100_outw(HP100_DEBUG_EN | - HP100_RX_HDR | - HP100_EE_EN | HP100_RESET_HB | - HP100_IO_EN | - HP100_FAKE_INT | - HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); - - hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW); - - if (lp->mode == 1) { /* busmaster */ - hp100_outw(HP100_BM_WRITE | - HP100_BM_READ | - HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW); - } else if (lp->mode == 2) { /* memory mapped */ - hp100_outw(HP100_BM_WRITE | - HP100_BM_READ | HP100_RESET_HB, OPTION_LSW); - hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW); - hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW); - hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW); - } else if (lp->mode == 3) { /* i/o mapped mode */ - hp100_outw(HP100_MMAP_DIS | HP100_SET_HB | - HP100_IO_EN | HP100_SET_LB, OPTION_LSW); - } - - hp100_page(HW_MAP); - hp100_outb(0, EARLYRXCFG); - hp100_outw(0, EARLYTXCFG); - - /* - * Enable Bus Master mode - */ - if (lp->mode == 1) { /* busmaster */ - /* Experimental: Set some PCI configuration bits */ - hp100_page(HW_MAP); - hp100_andb(~HP100_PDL_USE3, MODECTRL1); /* BM engine read maximum */ - hp100_andb(~HP100_TX_DUALQ, MODECTRL1); /* No Queue for Priority TX */ - - /* PCI Bus failures should result in a Misc. Interrupt */ - hp100_orb(HP100_EN_BUS_FAIL, MODECTRL2); - - hp100_outw(HP100_BM_READ | HP100_BM_WRITE | HP100_SET_HB, OPTION_LSW); - hp100_page(HW_MAP); - /* Use Burst Mode and switch on PAGE_CK */ - hp100_orb(HP100_BM_BURST_RD | HP100_BM_BURST_WR, BM); - if ((lp->chip == HP100_CHIPID_RAINIER) || (lp->chip == HP100_CHIPID_SHASTA)) - hp100_orb(HP100_BM_PAGE_CK, BM); - hp100_orb(HP100_BM_MASTER, BM); - } else { /* not busmaster */ - - hp100_page(HW_MAP); - hp100_andb(~HP100_BM_MASTER, BM); - } - - /* - * Divide card memory into regions for Rx, Tx and, if non-ETR chip, PDLs - */ - hp100_page(MMU_CFG); - if (lp->mode == 1) { /* only needed for Busmaster */ - int xmit_stop, recv_stop; - - if ((lp->chip == HP100_CHIPID_RAINIER) || - (lp->chip == HP100_CHIPID_SHASTA)) { - int pdl_stop; - - /* - * Each pdl is 508 bytes long. (63 frags * 4 bytes for address and - * 4 bytes for header). We will leave NUM_RXPDLS * 508 (rounded - * to the next higher 1k boundary) bytes for the rx-pdl's - * Note: For non-etr chips the transmit stop register must be - * programmed on a 1k boundary, i.e. bits 9:0 must be zero. - */ - pdl_stop = lp->memory_size; - xmit_stop = (pdl_stop - 508 * (MAX_RX_PDL) - 16) & ~(0x03ff); - recv_stop = (xmit_stop * (lp->rx_ratio) / 100) & ~(0x03ff); - hp100_outw((pdl_stop >> 4) - 1, PDL_MEM_STOP); -#ifdef HP100_DEBUG_BM - printk("hp100: %s: PDL_STOP = 0x%x\n", dev->name, pdl_stop); -#endif - } else { - /* ETR chip (Lassen) in busmaster mode */ - xmit_stop = (lp->memory_size) - 1; - recv_stop = ((lp->memory_size * lp->rx_ratio) / 100) & ~(0x03ff); - } - - hp100_outw(xmit_stop >> 4, TX_MEM_STOP); - hp100_outw(recv_stop >> 4, RX_MEM_STOP); -#ifdef HP100_DEBUG_BM - printk("hp100: %s: TX_STOP = 0x%x\n", dev->name, xmit_stop >> 4); - printk("hp100: %s: RX_STOP = 0x%x\n", dev->name, recv_stop >> 4); -#endif - } else { - /* Slave modes (memory mapped and programmed io) */ - hp100_outw((((lp->memory_size * lp->rx_ratio) / 100) >> 4), RX_MEM_STOP); - hp100_outw(((lp->memory_size - 1) >> 4), TX_MEM_STOP); -#ifdef HP100_DEBUG - printk("hp100: %s: TX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(TX_MEM_STOP)); - printk("hp100: %s: RX_MEM_STOP: 0x%x\n", dev->name, hp100_inw(RX_MEM_STOP)); -#endif - } - - /* Write MAC address into page 1 */ - hp100_page(MAC_ADDRESS); - for (i = 0; i < 6; i++) - hp100_outb(dev->dev_addr[i], MAC_ADDR + i); - - /* Zero the multicast hash registers */ - for (i = 0; i < 8; i++) - hp100_outb(0x0, HASH_BYTE0 + i); - - /* Set up MAC defaults */ - hp100_page(MAC_CTRL); - - /* Go to LAN Page and zero all filter bits */ - /* Zero accept error, accept multicast, accept broadcast and accept */ - /* all directed packet bits */ - hp100_andb(~(HP100_RX_EN | - HP100_TX_EN | - HP100_ACC_ERRORED | - HP100_ACC_MC | - HP100_ACC_BC | HP100_ACC_PHY), MAC_CFG_1); - - hp100_outb(0x00, MAC_CFG_2); - - /* Zero the frame format bit. This works around a training bug in the */ - /* new hubs. */ - hp100_outb(0x00, VG_LAN_CFG_2); /* (use 802.3) */ - - if (lp->priority_tx) - hp100_outb(HP100_PRIORITY_TX | HP100_SET_LB, OPTION_MSW); - else - hp100_outb(HP100_PRIORITY_TX | HP100_RESET_LB, OPTION_MSW); - - hp100_outb(HP100_ADV_NXT_PKT | - HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW); - - /* If busmaster, initialize the PDLs */ - if (lp->mode == 1) - hp100_init_pdls(dev); - - /* Go to performance page and initialize isr and imr registers */ - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ -} - -/* - * open/close functions - */ - -static int hp100_open(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); -#ifdef HP100_DEBUG_B - int ioaddr = dev->base_addr; -#endif - -#ifdef HP100_DEBUG_B - hp100_outw(0x4204, TRACE); - printk("hp100: %s: open\n", dev->name); -#endif - - /* New: if bus is PCI or EISA, interrupts might be shared interrupts */ - if (request_irq(dev->irq, hp100_interrupt, - lp->bus == HP100_BUS_PCI || lp->bus == - HP100_BUS_EISA ? IRQF_SHARED : 0, - dev->name, dev)) { - printk("hp100: %s: unable to get IRQ %d\n", dev->name, dev->irq); - return -EAGAIN; - } - - netif_trans_update(dev); /* prevent tx timeout */ - netif_start_queue(dev); - - lp->lan_type = hp100_sense_lan(dev); - lp->mac1_mode = HP100_MAC1MODE3; - lp->mac2_mode = HP100_MAC2MODE3; - memset(&lp->hash_bytes, 0x00, 8); - - hp100_stop_interface(dev); - - hp100_hwinit(dev); - - hp100_start_interface(dev); /* sets mac modes, enables interrupts */ - - return 0; -} - -/* The close function is called when the interface is to be brought down */ -static int hp100_close(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4205, TRACE); - printk("hp100: %s: close\n", dev->name); -#endif - - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all IRQs */ - - hp100_stop_interface(dev); - - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - - netif_stop_queue(dev); - - free_irq(dev->irq, dev); - -#ifdef HP100_DEBUG - printk("hp100: %s: close LSW = 0x%x\n", dev->name, - hp100_inw(OPTION_LSW)); -#endif - - return 0; -} - - -/* - * Configure the PDL Rx rings and LAN - */ -static void hp100_init_pdls(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); - hp100_ring_t *ringptr; - u_int *pageptr; /* Warning : increment by 4 - Jean II */ - int i; - -#ifdef HP100_DEBUG_B - int ioaddr = dev->base_addr; -#endif - -#ifdef HP100_DEBUG_B - hp100_outw(0x4206, TRACE); - printk("hp100: %s: init pdls\n", dev->name); -#endif - - if (!lp->page_vaddr_algn) - printk("hp100: %s: Warning: lp->page_vaddr_algn not initialised!\n", dev->name); - else { - /* pageptr shall point into the DMA accessible memory region */ - /* we use this pointer to status the upper limit of allocated */ - /* memory in the allocated page. */ - /* note: align the pointers to the pci cache line size */ - memset(lp->page_vaddr_algn, 0, MAX_RINGSIZE); /* Zero Rx/Tx ring page */ - pageptr = lp->page_vaddr_algn; - - lp->rxrcommit = 0; - ringptr = lp->rxrhead = lp->rxrtail = &(lp->rxring[0]); - - /* Initialise Rx Ring */ - for (i = MAX_RX_PDL - 1; i >= 0; i--) { - lp->rxring[i].next = ringptr; - ringptr = &(lp->rxring[i]); - pageptr += hp100_init_rxpdl(dev, ringptr, pageptr); - } - - /* Initialise Tx Ring */ - lp->txrcommit = 0; - ringptr = lp->txrhead = lp->txrtail = &(lp->txring[0]); - for (i = MAX_TX_PDL - 1; i >= 0; i--) { - lp->txring[i].next = ringptr; - ringptr = &(lp->txring[i]); - pageptr += hp100_init_txpdl(dev, ringptr, pageptr); - } - } -} - - -/* These functions "format" the entries in the pdl structure */ -/* They return how much memory the fragments need. */ -static int hp100_init_rxpdl(struct net_device *dev, - register hp100_ring_t * ringptr, - register u32 * pdlptr) -{ - /* pdlptr is starting address for this pdl */ - - if (0 != (((unsigned long) pdlptr) & 0xf)) - printk("hp100: %s: Init rxpdl: Unaligned pdlptr 0x%lx.\n", - dev->name, (unsigned long) pdlptr); - - ringptr->pdl = pdlptr + 1; - ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr + 1); - ringptr->skb = NULL; - - /* - * Write address and length of first PDL Fragment (which is used for - * storing the RX-Header - * We use the 4 bytes _before_ the PDH in the pdl memory area to - * store this information. (PDH is at offset 0x04) - */ - /* Note that pdlptr+1 and not pdlptr is the pointer to the PDH */ - - *(pdlptr + 2) = (u_int) virt_to_whatever(dev, pdlptr); /* Address Frag 1 */ - *(pdlptr + 3) = 4; /* Length Frag 1 */ - - return roundup(MAX_RX_FRAG * 2 + 2, 4); -} - - -static int hp100_init_txpdl(struct net_device *dev, - register hp100_ring_t * ringptr, - register u32 * pdlptr) -{ - if (0 != (((unsigned long) pdlptr) & 0xf)) - printk("hp100: %s: Init txpdl: Unaligned pdlptr 0x%lx.\n", dev->name, (unsigned long) pdlptr); - - ringptr->pdl = pdlptr; /* +1; */ - ringptr->pdl_paddr = virt_to_whatever(dev, pdlptr); /* +1 */ - ringptr->skb = NULL; - - return roundup(MAX_TX_FRAG * 2 + 2, 4); -} - -/* - * hp100_build_rx_pdl allocates an skb_buff of maximum size plus two bytes - * for possible odd word alignment rounding up to next dword and set PDL - * address for fragment#2 - * Returns: 0 if unable to allocate skb_buff - * 1 if successful - */ -static int hp100_build_rx_pdl(hp100_ring_t * ringptr, - struct net_device *dev) -{ -#ifdef HP100_DEBUG_B - int ioaddr = dev->base_addr; -#endif -#ifdef HP100_DEBUG_BM - u_int *p; -#endif - -#ifdef HP100_DEBUG_B - hp100_outw(0x4207, TRACE); - printk("hp100: %s: build rx pdl\n", dev->name); -#endif - - /* Allocate skb buffer of maximum size */ - /* Note: This depends on the alloc_skb functions allocating more - * space than requested, i.e. aligning to 16bytes */ - - ringptr->skb = netdev_alloc_skb(dev, roundup(MAX_ETHER_SIZE + 2, 4)); - - if (NULL != ringptr->skb) { - /* - * Reserve 2 bytes at the head of the buffer to land the IP header - * on a long word boundary (According to the Network Driver section - * in the Linux KHG, this should help to increase performance.) - */ - skb_reserve(ringptr->skb, 2); - - ringptr->skb->data = skb_put(ringptr->skb, MAX_ETHER_SIZE); - - /* ringptr->pdl points to the beginning of the PDL, i.e. the PDH */ - /* Note: 1st Fragment is used for the 4 byte packet status - * (receive header). Its PDL entries are set up by init_rxpdl. So - * here we only have to set up the PDL fragment entries for the data - * part. Those 4 bytes will be stored in the DMA memory region - * directly before the PDL. - */ -#ifdef HP100_DEBUG_BM - printk("hp100: %s: build_rx_pdl: PDH@0x%x, skb->data (len %d) at 0x%x\n", - dev->name, (u_int) ringptr->pdl, - roundup(MAX_ETHER_SIZE + 2, 4), - (unsigned int) ringptr->skb->data); -#endif - - /* Conversion to new PCI API : map skbuf data to PCI bus. - * Doc says it's OK for EISA as well - Jean II */ - ringptr->pdl[0] = 0x00020000; /* Write PDH */ - ringptr->pdl[3] = pdl_map_data(netdev_priv(dev), - ringptr->skb->data); - ringptr->pdl[4] = MAX_ETHER_SIZE; /* Length of Data */ - -#ifdef HP100_DEBUG_BM - for (p = (ringptr->pdl); p < (ringptr->pdl + 5); p++) - printk("hp100: %s: Adr 0x%.8x = 0x%.8x\n", dev->name, (u_int) p, (u_int) * p); -#endif - return 1; - } - /* else: */ - /* alloc_skb failed (no memory) -> still can receive the header - * fragment into PDL memory. make PDL safe by clearing msgptr and - * making the PDL only 1 fragment (i.e. the 4 byte packet status) - */ -#ifdef HP100_DEBUG_BM - printk("hp100: %s: build_rx_pdl: PDH@0x%x, No space for skb.\n", dev->name, (u_int) ringptr->pdl); -#endif - - ringptr->pdl[0] = 0x00010000; /* PDH: Count=1 Fragment */ - - return 0; -} - -/* - * hp100_rxfill - attempt to fill the Rx Ring will empty skb's - * - * Makes assumption that skb's are always contiguous memory areas and - * therefore PDLs contain only 2 physical fragments. - * - While the number of Rx PDLs with buffers is less than maximum - * a. Get a maximum packet size skb - * b. Put the physical address of the buffer into the PDL. - * c. Output physical address of PDL to adapter. - */ -static void hp100_rxfill(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - - struct hp100_private *lp = netdev_priv(dev); - hp100_ring_t *ringptr; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4208, TRACE); - printk("hp100: %s: rxfill\n", dev->name); -#endif - - hp100_page(PERFORMANCE); - - while (lp->rxrcommit < MAX_RX_PDL) { - /* - ** Attempt to get a buffer and build a Rx PDL. - */ - ringptr = lp->rxrtail; - if (0 == hp100_build_rx_pdl(ringptr, dev)) { - return; /* None available, return */ - } - - /* Hand this PDL over to the card */ - /* Note: This needs performance page selected! */ -#ifdef HP100_DEBUG_BM - printk("hp100: %s: rxfill: Hand to card: pdl #%d @0x%x phys:0x%x, buffer: 0x%x\n", - dev->name, lp->rxrcommit, (u_int) ringptr->pdl, - (u_int) ringptr->pdl_paddr, (u_int) ringptr->pdl[3]); -#endif - - hp100_outl((u32) ringptr->pdl_paddr, RX_PDA); - - lp->rxrcommit += 1; - lp->rxrtail = ringptr->next; - } -} - -/* - * BM_shutdown - shutdown bus mastering and leave chip in reset state - */ - -static void hp100_BM_shutdown(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - unsigned long time; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4209, TRACE); - printk("hp100: %s: bm shutdown\n", dev->name); -#endif - - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* Ack all ints */ - - /* Ensure Interrupts are off */ - hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW); - - /* Disable all MAC activity */ - hp100_page(MAC_CTRL); - hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */ - - /* If cascade MMU is not already in reset */ - if (0 != (hp100_inw(OPTION_LSW) & HP100_HW_RST)) { - /* Wait 1.3ms (10Mb max packet time) to ensure MAC is idle so - * MMU pointers will not be reset out from underneath - */ - hp100_page(MAC_CTRL); - for (time = 0; time < 5000; time++) { - if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) - break; - } - - /* Shutdown algorithm depends on the generation of Cascade */ - if (lp->chip == HP100_CHIPID_LASSEN) { /* ETR shutdown/reset */ - /* Disable Busmaster mode and wait for bit to go to zero. */ - hp100_page(HW_MAP); - hp100_andb(~HP100_BM_MASTER, BM); - /* 100 ms timeout */ - for (time = 0; time < 32000; time++) { - if (0 == (hp100_inb(BM) & HP100_BM_MASTER)) - break; - } - } else { /* Shasta or Rainier Shutdown/Reset */ - /* To ensure all bus master inloading activity has ceased, - * wait for no Rx PDAs or no Rx packets on card. - */ - hp100_page(PERFORMANCE); - /* 100 ms timeout */ - for (time = 0; time < 10000; time++) { - /* RX_PDL: PDLs not executed. */ - /* RX_PKT_CNT: RX'd packets on card. */ - if ((hp100_inb(RX_PDL) == 0) && (hp100_inb(RX_PKT_CNT) == 0)) - break; - } - - if (time >= 10000) - printk("hp100: %s: BM shutdown error.\n", dev->name); - - /* To ensure all bus master outloading activity has ceased, - * wait until the Tx PDA count goes to zero or no more Tx space - * available in the Tx region of the card. - */ - /* 100 ms timeout */ - for (time = 0; time < 10000; time++) { - if ((0 == hp100_inb(TX_PKT_CNT)) && - (0 != (hp100_inb(TX_MEM_FREE) & HP100_AUTO_COMPARE))) - break; - } - - /* Disable Busmaster mode */ - hp100_page(HW_MAP); - hp100_andb(~HP100_BM_MASTER, BM); - } /* end of shutdown procedure for non-etr parts */ - - hp100_cascade_reset(dev, 1); - } - hp100_page(PERFORMANCE); - /* hp100_outw( HP100_BM_READ | HP100_BM_WRITE | HP100_RESET_HB, OPTION_LSW ); */ - /* Busmaster mode should be shut down now. */ -} - -static int hp100_check_lan(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); - - if (lp->lan_type < 0) { /* no LAN type detected yet? */ - hp100_stop_interface(dev); - if ((lp->lan_type = hp100_sense_lan(dev)) < 0) { - printk("hp100: %s: no connection found - check wire\n", dev->name); - hp100_start_interface(dev); /* 10Mb/s RX packets maybe handled */ - return -EIO; - } - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); /* relogin */ - hp100_start_interface(dev); - } - return 0; -} - -/* - * transmit functions - */ - -/* tx function for busmaster mode */ -static netdev_tx_t hp100_start_xmit_bm(struct sk_buff *skb, - struct net_device *dev) -{ - unsigned long flags; - int i, ok_flag; - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - hp100_ring_t *ringptr; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4210, TRACE); - printk("hp100: %s: start_xmit_bm\n", dev->name); -#endif - if (skb->len <= 0) - goto drop; - - if (lp->chip == HP100_CHIPID_SHASTA && skb_padto(skb, ETH_ZLEN)) - return NETDEV_TX_OK; - - /* Get Tx ring tail pointer */ - if (lp->txrtail->next == lp->txrhead) { - /* No memory. */ -#ifdef HP100_DEBUG - printk("hp100: %s: start_xmit_bm: No TX PDL available.\n", dev->name); -#endif - /* not waited long enough since last tx? */ - if (time_before(jiffies, dev_trans_start(dev) + HZ)) - goto drop; - - if (hp100_check_lan(dev)) - goto drop; - - if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) { - /* we have a 100Mb/s adapter but it isn't connected to hub */ - printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name); - hp100_stop_interface(dev); - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - } else { - spin_lock_irqsave(&lp->lock, flags); - hp100_ints_off(); /* Useful ? Jean II */ - i = hp100_sense_lan(dev); - hp100_ints_on(); - spin_unlock_irqrestore(&lp->lock, flags); - if (i == HP100_LAN_ERR) - printk("hp100: %s: link down detected\n", dev->name); - else if (lp->lan_type != i) { /* cable change! */ - /* it's very hard - all network settings must be changed!!! */ - printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name); - lp->lan_type = i; - hp100_stop_interface(dev); - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - } else { - printk("hp100: %s: interface reset\n", dev->name); - hp100_stop_interface(dev); - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - } - } - - goto drop; - } - - /* - * we have to turn int's off before modifying this, otherwise - * a tx_pdl_cleanup could occur at the same time - */ - spin_lock_irqsave(&lp->lock, flags); - ringptr = lp->txrtail; - lp->txrtail = ringptr->next; - - /* Check whether packet has minimal packet size */ - ok_flag = skb->len >= HP100_MIN_PACKET_SIZE; - i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE; - - ringptr->skb = skb; - ringptr->pdl[0] = ((1 << 16) | i); /* PDH: 1 Fragment & length */ - if (lp->chip == HP100_CHIPID_SHASTA) { - /* TODO:Could someone who has the EISA card please check if this works? */ - ringptr->pdl[2] = i; - } else { /* Lassen */ - /* In the PDL, don't use the padded size but the real packet size: */ - ringptr->pdl[2] = skb->len; /* 1st Frag: Length of frag */ - } - /* Conversion to new PCI API : map skbuf data to PCI bus. - * Doc says it's OK for EISA as well - Jean II */ - ringptr->pdl[1] = ((u32) pci_map_single(lp->pci_dev, skb->data, ringptr->pdl[2], PCI_DMA_TODEVICE)); /* 1st Frag: Adr. of data */ - - /* Hand this PDL to the card. */ - hp100_outl(ringptr->pdl_paddr, TX_PDA_L); /* Low Prio. Queue */ - - lp->txrcommit++; - - dev->stats.tx_packets++; - dev->stats.tx_bytes += skb->len; - - spin_unlock_irqrestore(&lp->lock, flags); - - return NETDEV_TX_OK; - -drop: - dev_kfree_skb(skb); - return NETDEV_TX_OK; -} - - -/* clean_txring checks if packets have been sent by the card by reading - * the TX_PDL register from the performance page and comparing it to the - * number of committed packets. It then frees the skb's of the packets that - * obviously have been sent to the network. - * - * Needs the PERFORMANCE page selected. - */ -static void hp100_clean_txring(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); - int ioaddr = dev->base_addr; - int donecount; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4211, TRACE); - printk("hp100: %s: clean txring\n", dev->name); -#endif - - /* How many PDLs have been transmitted? */ - donecount = (lp->txrcommit) - hp100_inb(TX_PDL); - -#ifdef HP100_DEBUG - if (donecount > MAX_TX_PDL) - printk("hp100: %s: Warning: More PDLs transmitted than committed to card???\n", dev->name); -#endif - - for (; 0 != donecount; donecount--) { -#ifdef HP100_DEBUG_BM - printk("hp100: %s: Free skb: data @0x%.8x txrcommit=0x%x TXPDL=0x%x, done=0x%x\n", - dev->name, (u_int) lp->txrhead->skb->data, - lp->txrcommit, hp100_inb(TX_PDL), donecount); -#endif - /* Conversion to new PCI API : NOP */ - pci_unmap_single(lp->pci_dev, (dma_addr_t) lp->txrhead->pdl[1], lp->txrhead->pdl[2], PCI_DMA_TODEVICE); - dev_consume_skb_any(lp->txrhead->skb); - lp->txrhead->skb = NULL; - lp->txrhead = lp->txrhead->next; - lp->txrcommit--; - } -} - -/* tx function for slave modes */ -static netdev_tx_t hp100_start_xmit(struct sk_buff *skb, - struct net_device *dev) -{ - unsigned long flags; - int i, ok_flag; - int ioaddr = dev->base_addr; - u_short val; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4212, TRACE); - printk("hp100: %s: start_xmit\n", dev->name); -#endif - if (skb->len <= 0) - goto drop; - - if (hp100_check_lan(dev)) - goto drop; - - /* If there is not enough free memory on the card... */ - i = hp100_inl(TX_MEM_FREE) & 0x7fffffff; - if (!(((i / 2) - 539) > (skb->len + 16) && (hp100_inb(TX_PKT_CNT) < 255))) { -#ifdef HP100_DEBUG - printk("hp100: %s: start_xmit: tx free mem = 0x%x\n", dev->name, i); -#endif - /* not waited long enough since last failed tx try? */ - if (time_before(jiffies, dev_trans_start(dev) + HZ)) { -#ifdef HP100_DEBUG - printk("hp100: %s: trans_start timing problem\n", - dev->name); -#endif - goto drop; - } - if (lp->lan_type == HP100_LAN_100 && lp->hub_status < 0) { - /* we have a 100Mb/s adapter but it isn't connected to hub */ - printk("hp100: %s: login to 100Mb/s hub retry\n", dev->name); - hp100_stop_interface(dev); - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - } else { - spin_lock_irqsave(&lp->lock, flags); - hp100_ints_off(); /* Useful ? Jean II */ - i = hp100_sense_lan(dev); - hp100_ints_on(); - spin_unlock_irqrestore(&lp->lock, flags); - if (i == HP100_LAN_ERR) - printk("hp100: %s: link down detected\n", dev->name); - else if (lp->lan_type != i) { /* cable change! */ - /* it's very hard - all network setting must be changed!!! */ - printk("hp100: %s: cable change 10Mb/s <-> 100Mb/s detected\n", dev->name); - lp->lan_type = i; - hp100_stop_interface(dev); - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - } else { - printk("hp100: %s: interface reset\n", dev->name); - hp100_stop_interface(dev); - if (lp->lan_type == HP100_LAN_100) - lp->hub_status = hp100_login_to_vg_hub(dev, 0); - hp100_start_interface(dev); - mdelay(1); - } - } - goto drop; - } - - for (i = 0; i < 6000 && (hp100_inb(OPTION_MSW) & HP100_TX_CMD); i++) { -#ifdef HP100_DEBUG_TX - printk("hp100: %s: start_xmit: busy\n", dev->name); -#endif - } - - spin_lock_irqsave(&lp->lock, flags); - hp100_ints_off(); - val = hp100_inw(IRQ_STATUS); - /* Ack / clear the interrupt TX_COMPLETE interrupt - this interrupt is set - * when the current packet being transmitted on the wire is completed. */ - hp100_outw(HP100_TX_COMPLETE, IRQ_STATUS); -#ifdef HP100_DEBUG_TX - printk("hp100: %s: start_xmit: irq_status=0x%.4x, irqmask=0x%.4x, len=%d\n", - dev->name, val, hp100_inw(IRQ_MASK), (int) skb->len); -#endif - - ok_flag = skb->len >= HP100_MIN_PACKET_SIZE; - i = ok_flag ? skb->len : HP100_MIN_PACKET_SIZE; - - hp100_outw(i, DATA32); /* tell card the total packet length */ - hp100_outw(i, FRAGMENT_LEN); /* and first/only fragment length */ - - if (lp->mode == 2) { /* memory mapped */ - /* Note: The J2585B needs alignment to 32bits here! */ - memcpy_toio(lp->mem_ptr_virt, skb->data, (skb->len + 3) & ~3); - if (!ok_flag) - memset_io(lp->mem_ptr_virt, 0, HP100_MIN_PACKET_SIZE - skb->len); - } else { /* programmed i/o */ - outsl(ioaddr + HP100_REG_DATA32, skb->data, - (skb->len + 3) >> 2); - if (!ok_flag) - for (i = (skb->len + 3) & ~3; i < HP100_MIN_PACKET_SIZE; i += 4) - hp100_outl(0, DATA32); - } - - hp100_outb(HP100_TX_CMD | HP100_SET_LB, OPTION_MSW); /* send packet */ - - dev->stats.tx_packets++; - dev->stats.tx_bytes += skb->len; - hp100_ints_on(); - spin_unlock_irqrestore(&lp->lock, flags); - - dev_consume_skb_any(skb); - -#ifdef HP100_DEBUG_TX - printk("hp100: %s: start_xmit: end\n", dev->name); -#endif - - return NETDEV_TX_OK; - -drop: - dev_kfree_skb(skb); - return NETDEV_TX_OK; - -} - - -/* - * Receive Function (Non-Busmaster mode) - * Called when an "Receive Packet" interrupt occurs, i.e. the receive - * packet counter is non-zero. - * For non-busmaster, this function does the whole work of transferring - * the packet to the host memory and then up to higher layers via skb - * and netif_rx. - */ - -static void hp100_rx(struct net_device *dev) -{ - int packets, pkt_len; - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - u_int header; - struct sk_buff *skb; - -#ifdef DEBUG_B - hp100_outw(0x4213, TRACE); - printk("hp100: %s: rx\n", dev->name); -#endif - - /* First get indication of received lan packet */ - /* RX_PKT_CND indicates the number of packets which have been fully */ - /* received onto the card but have not been fully transferred of the card */ - packets = hp100_inb(RX_PKT_CNT); -#ifdef HP100_DEBUG_RX - if (packets > 1) - printk("hp100: %s: rx: waiting packets = %d\n", dev->name, packets); -#endif - - while (packets-- > 0) { - /* If ADV_NXT_PKT is still set, we have to wait until the card has */ - /* really advanced to the next packet. */ - for (pkt_len = 0; pkt_len < 6000 && (hp100_inb(OPTION_MSW) & HP100_ADV_NXT_PKT); pkt_len++) { -#ifdef HP100_DEBUG_RX - printk ("hp100: %s: rx: busy, remaining packets = %d\n", dev->name, packets); -#endif - } - - /* First we get the header, which contains information about the */ - /* actual length of the received packet. */ - if (lp->mode == 2) { /* memory mapped mode */ - header = readl(lp->mem_ptr_virt); - } else /* programmed i/o */ - header = hp100_inl(DATA32); - - pkt_len = ((header & HP100_PKT_LEN_MASK) + 3) & ~3; - -#ifdef HP100_DEBUG_RX - printk("hp100: %s: rx: new packet - length=%d, errors=0x%x, dest=0x%x\n", - dev->name, header & HP100_PKT_LEN_MASK, - (header >> 16) & 0xfff8, (header >> 16) & 7); -#endif - - /* Now we allocate the skb and transfer the data into it. */ - skb = netdev_alloc_skb(dev, pkt_len + 2); - if (skb == NULL) { /* Not enough memory->drop packet */ -#ifdef HP100_DEBUG - printk("hp100: %s: rx: couldn't allocate a sk_buff of size %d\n", - dev->name, pkt_len); -#endif - dev->stats.rx_dropped++; - } else { /* skb successfully allocated */ - - u_char *ptr; - - skb_reserve(skb,2); - - /* ptr to start of the sk_buff data area */ - skb_put(skb, pkt_len); - ptr = skb->data; - - /* Now transfer the data from the card into that area */ - if (lp->mode == 2) - memcpy_fromio(ptr, lp->mem_ptr_virt,pkt_len); - else /* io mapped */ - insl(ioaddr + HP100_REG_DATA32, ptr, pkt_len >> 2); - - skb->protocol = eth_type_trans(skb, dev); - -#ifdef HP100_DEBUG_RX - printk("hp100: %s: rx: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", - dev->name, ptr[0], ptr[1], ptr[2], ptr[3], - ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], - ptr[9], ptr[10], ptr[11]); -#endif - netif_rx(skb); - dev->stats.rx_packets++; - dev->stats.rx_bytes += pkt_len; - } - - /* Indicate the card that we have got the packet */ - hp100_outb(HP100_ADV_NXT_PKT | HP100_SET_LB, OPTION_MSW); - - switch (header & 0x00070000) { - case (HP100_MULTI_ADDR_HASH << 16): - case (HP100_MULTI_ADDR_NO_HASH << 16): - dev->stats.multicast++; - break; - } - } /* end of while(there are packets) loop */ -#ifdef HP100_DEBUG_RX - printk("hp100_rx: %s: end\n", dev->name); -#endif -} - -/* - * Receive Function for Busmaster Mode - */ -static void hp100_rx_bm(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - hp100_ring_t *ptr; - u_int header; - int pkt_len; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4214, TRACE); - printk("hp100: %s: rx_bm\n", dev->name); -#endif - -#ifdef HP100_DEBUG - if (0 == lp->rxrcommit) { - printk("hp100: %s: rx_bm called although no PDLs were committed to adapter?\n", dev->name); - return; - } else - /* RX_PKT_CNT states how many PDLs are currently formatted and available to - * the cards BM engine */ - if ((hp100_inw(RX_PKT_CNT) & 0x00ff) >= lp->rxrcommit) { - printk("hp100: %s: More packets received than committed? RX_PKT_CNT=0x%x, commit=0x%x\n", - dev->name, hp100_inw(RX_PKT_CNT) & 0x00ff, - lp->rxrcommit); - return; - } -#endif - - while ((lp->rxrcommit > hp100_inb(RX_PDL))) { - /* - * The packet was received into the pdl pointed to by lp->rxrhead ( - * the oldest pdl in the ring - */ - - /* First we get the header, which contains information about the */ - /* actual length of the received packet. */ - - ptr = lp->rxrhead; - - header = *(ptr->pdl - 1); - pkt_len = (header & HP100_PKT_LEN_MASK); - - /* Conversion to new PCI API : NOP */ - pci_unmap_single(lp->pci_dev, (dma_addr_t) ptr->pdl[3], MAX_ETHER_SIZE, PCI_DMA_FROMDEVICE); - -#ifdef HP100_DEBUG_BM - printk("hp100: %s: rx_bm: header@0x%x=0x%x length=%d, errors=0x%x, dest=0x%x\n", - dev->name, (u_int) (ptr->pdl - 1), (u_int) header, - pkt_len, (header >> 16) & 0xfff8, (header >> 16) & 7); - printk("hp100: %s: RX_PDL_COUNT:0x%x TX_PDL_COUNT:0x%x, RX_PKT_CNT=0x%x PDH=0x%x, Data@0x%x len=0x%x\n", - dev->name, hp100_inb(RX_PDL), hp100_inb(TX_PDL), - hp100_inb(RX_PKT_CNT), (u_int) * (ptr->pdl), - (u_int) * (ptr->pdl + 3), (u_int) * (ptr->pdl + 4)); -#endif - - if ((pkt_len >= MIN_ETHER_SIZE) && - (pkt_len <= MAX_ETHER_SIZE)) { - if (ptr->skb == NULL) { - printk("hp100: %s: rx_bm: skb null\n", dev->name); - /* can happen if we only allocated room for the pdh due to memory shortage. */ - dev->stats.rx_dropped++; - } else { - skb_trim(ptr->skb, pkt_len); /* Shorten it */ - ptr->skb->protocol = - eth_type_trans(ptr->skb, dev); - - netif_rx(ptr->skb); /* Up and away... */ - - dev->stats.rx_packets++; - dev->stats.rx_bytes += pkt_len; - } - - switch (header & 0x00070000) { - case (HP100_MULTI_ADDR_HASH << 16): - case (HP100_MULTI_ADDR_NO_HASH << 16): - dev->stats.multicast++; - break; - } - } else { -#ifdef HP100_DEBUG - printk("hp100: %s: rx_bm: Received bad packet (length=%d)\n", dev->name, pkt_len); -#endif - if (ptr->skb != NULL) - dev_kfree_skb_any(ptr->skb); - dev->stats.rx_errors++; - } - - lp->rxrhead = lp->rxrhead->next; - - /* Allocate a new rx PDL (so lp->rxrcommit stays the same) */ - if (0 == hp100_build_rx_pdl(lp->rxrtail, dev)) { - /* No space for skb, header can still be received. */ -#ifdef HP100_DEBUG - printk("hp100: %s: rx_bm: No space for new PDL.\n", dev->name); -#endif - return; - } else { /* successfully allocated new PDL - put it in ringlist at tail. */ - hp100_outl((u32) lp->rxrtail->pdl_paddr, RX_PDA); - lp->rxrtail = lp->rxrtail->next; - } - - } -} - -/* - * statistics - */ -static struct net_device_stats *hp100_get_stats(struct net_device *dev) -{ - unsigned long flags; - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4215, TRACE); -#endif - - spin_lock_irqsave(&lp->lock, flags); - hp100_ints_off(); /* Useful ? Jean II */ - hp100_update_stats(dev); - hp100_ints_on(); - spin_unlock_irqrestore(&lp->lock, flags); - return &(dev->stats); -} - -static void hp100_update_stats(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - u_short val; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4216, TRACE); - printk("hp100: %s: update-stats\n", dev->name); -#endif - - /* Note: Statistics counters clear when read. */ - hp100_page(MAC_CTRL); - val = hp100_inw(DROPPED) & 0x0fff; - dev->stats.rx_errors += val; - dev->stats.rx_over_errors += val; - val = hp100_inb(CRC); - dev->stats.rx_errors += val; - dev->stats.rx_crc_errors += val; - val = hp100_inb(ABORT); - dev->stats.tx_errors += val; - dev->stats.tx_aborted_errors += val; - hp100_page(PERFORMANCE); -} - -static void hp100_misc_interrupt(struct net_device *dev) -{ -#ifdef HP100_DEBUG_B - int ioaddr = dev->base_addr; -#endif - -#ifdef HP100_DEBUG_B - int ioaddr = dev->base_addr; - hp100_outw(0x4216, TRACE); - printk("hp100: %s: misc_interrupt\n", dev->name); -#endif - - /* Note: Statistics counters clear when read. */ - dev->stats.rx_errors++; - dev->stats.tx_errors++; -} - -static void hp100_clear_stats(struct hp100_private *lp, int ioaddr) -{ - unsigned long flags; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4217, TRACE); - printk("hp100: %s: clear_stats\n", dev->name); -#endif - - spin_lock_irqsave(&lp->lock, flags); - hp100_page(MAC_CTRL); /* get all statistics bytes */ - hp100_inw(DROPPED); - hp100_inb(CRC); - hp100_inb(ABORT); - hp100_page(PERFORMANCE); - spin_unlock_irqrestore(&lp->lock, flags); -} - - -/* - * multicast setup - */ - -/* - * Set or clear the multicast filter for this adapter. - */ - -static void hp100_set_multicast_list(struct net_device *dev) -{ - unsigned long flags; - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4218, TRACE); - printk("hp100: %s: set_mc_list\n", dev->name); -#endif - - spin_lock_irqsave(&lp->lock, flags); - hp100_ints_off(); - hp100_page(MAC_CTRL); - hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); /* stop rx/tx */ - - if (dev->flags & IFF_PROMISC) { - lp->mac2_mode = HP100_MAC2MODE6; /* promiscuous mode = get all good */ - lp->mac1_mode = HP100_MAC1MODE6; /* packets on the net */ - memset(&lp->hash_bytes, 0xff, 8); - } else if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI)) { - lp->mac2_mode = HP100_MAC2MODE5; /* multicast mode = get packets for */ - lp->mac1_mode = HP100_MAC1MODE5; /* me, broadcasts and all multicasts */ -#ifdef HP100_MULTICAST_FILTER /* doesn't work!!! */ - if (dev->flags & IFF_ALLMULTI) { - /* set hash filter to receive all multicast packets */ - memset(&lp->hash_bytes, 0xff, 8); - } else { - int i, idx; - u_char *addrs; - struct netdev_hw_addr *ha; - - memset(&lp->hash_bytes, 0x00, 8); -#ifdef HP100_DEBUG - printk("hp100: %s: computing hash filter - mc_count = %i\n", - dev->name, netdev_mc_count(dev)); -#endif - netdev_for_each_mc_addr(ha, dev) { - addrs = ha->addr; -#ifdef HP100_DEBUG - printk("hp100: %s: multicast = %pM, ", - dev->name, addrs); -#endif - for (i = idx = 0; i < 6; i++) { - idx ^= *addrs++ & 0x3f; - printk(":%02x:", idx); - } -#ifdef HP100_DEBUG - printk("idx = %i\n", idx); -#endif - lp->hash_bytes[idx >> 3] |= (1 << (idx & 7)); - } - } -#else - memset(&lp->hash_bytes, 0xff, 8); -#endif - } else { - lp->mac2_mode = HP100_MAC2MODE3; /* normal mode = get packets for me */ - lp->mac1_mode = HP100_MAC1MODE3; /* and broadcasts */ - memset(&lp->hash_bytes, 0x00, 8); - } - - if (((hp100_inb(MAC_CFG_1) & 0x0f) != lp->mac1_mode) || - (hp100_inb(MAC_CFG_2) != lp->mac2_mode)) { - int i; - - hp100_outb(lp->mac2_mode, MAC_CFG_2); - hp100_andb(HP100_MAC1MODEMASK, MAC_CFG_1); /* clear mac1 mode bits */ - hp100_orb(lp->mac1_mode, MAC_CFG_1); /* and set the new mode */ - - hp100_page(MAC_ADDRESS); - for (i = 0; i < 8; i++) - hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i); -#ifdef HP100_DEBUG - printk("hp100: %s: mac1 = 0x%x, mac2 = 0x%x, multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - dev->name, lp->mac1_mode, lp->mac2_mode, - lp->hash_bytes[0], lp->hash_bytes[1], - lp->hash_bytes[2], lp->hash_bytes[3], - lp->hash_bytes[4], lp->hash_bytes[5], - lp->hash_bytes[6], lp->hash_bytes[7]); -#endif - - if (lp->lan_type == HP100_LAN_100) { -#ifdef HP100_DEBUG - printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name); -#endif - lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */ - } - } else { - int i; - u_char old_hash_bytes[8]; - - hp100_page(MAC_ADDRESS); - for (i = 0; i < 8; i++) - old_hash_bytes[i] = hp100_inb(HASH_BYTE0 + i); - if (memcmp(old_hash_bytes, &lp->hash_bytes, 8)) { - for (i = 0; i < 8; i++) - hp100_outb(lp->hash_bytes[i], HASH_BYTE0 + i); -#ifdef HP100_DEBUG - printk("hp100: %s: multicast hash = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - dev->name, lp->hash_bytes[0], - lp->hash_bytes[1], lp->hash_bytes[2], - lp->hash_bytes[3], lp->hash_bytes[4], - lp->hash_bytes[5], lp->hash_bytes[6], - lp->hash_bytes[7]); -#endif - - if (lp->lan_type == HP100_LAN_100) { -#ifdef HP100_DEBUG - printk("hp100: %s: 100VG MAC settings have changed - relogin.\n", dev->name); -#endif - lp->hub_status = hp100_login_to_vg_hub(dev, 1); /* force a relogin to the hub */ - } - } - } - - hp100_page(MAC_CTRL); - hp100_orb(HP100_RX_EN | HP100_RX_IDLE | /* enable rx */ - HP100_TX_EN | HP100_TX_IDLE, MAC_CFG_1); /* enable tx */ - - hp100_page(PERFORMANCE); - hp100_ints_on(); - spin_unlock_irqrestore(&lp->lock, flags); -} - -/* - * hardware interrupt handling - */ - -static irqreturn_t hp100_interrupt(int irq, void *dev_id) -{ - struct net_device *dev = (struct net_device *) dev_id; - struct hp100_private *lp = netdev_priv(dev); - - int ioaddr; - u_int val; - - if (dev == NULL) - return IRQ_NONE; - ioaddr = dev->base_addr; - - spin_lock(&lp->lock); - - hp100_ints_off(); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4219, TRACE); -#endif - - /* hp100_page( PERFORMANCE ); */ - val = hp100_inw(IRQ_STATUS); -#ifdef HP100_DEBUG_IRQ - printk("hp100: %s: mode=%x,IRQ_STAT=0x%.4x,RXPKTCNT=0x%.2x RXPDL=0x%.2x TXPKTCNT=0x%.2x TXPDL=0x%.2x\n", - dev->name, lp->mode, (u_int) val, hp100_inb(RX_PKT_CNT), - hp100_inb(RX_PDL), hp100_inb(TX_PKT_CNT), hp100_inb(TX_PDL)); -#endif - - if (val == 0) { /* might be a shared interrupt */ - spin_unlock(&lp->lock); - hp100_ints_on(); - return IRQ_NONE; - } - /* We're only interested in those interrupts we really enabled. */ - /* val &= hp100_inw( IRQ_MASK ); */ - - /* - * RX_PDL_FILL_COMPL is set whenever a RX_PDL has been executed. A RX_PDL - * is considered executed whenever the RX_PDL data structure is no longer - * needed. - */ - if (val & HP100_RX_PDL_FILL_COMPL) { - if (lp->mode == 1) - hp100_rx_bm(dev); - else { - printk("hp100: %s: rx_pdl_fill_compl interrupt although not busmaster?\n", dev->name); - } - } - - /* - * The RX_PACKET interrupt is set, when the receive packet counter is - * non zero. We use this interrupt for receiving in slave mode. In - * busmaster mode, we use it to make sure we did not miss any rx_pdl_fill - * interrupts. If rx_pdl_fill_compl is not set and rx_packet is set, then - * we somehow have missed a rx_pdl_fill_compl interrupt. - */ - - if (val & HP100_RX_PACKET) { /* Receive Packet Counter is non zero */ - if (lp->mode != 1) /* non busmaster */ - hp100_rx(dev); - else if (!(val & HP100_RX_PDL_FILL_COMPL)) { - /* Shouldn't happen - maybe we missed a RX_PDL_FILL Interrupt? */ - hp100_rx_bm(dev); - } - } - - /* - * Ack. that we have noticed the interrupt and thereby allow next one. - * Note that this is now done after the slave rx function, since first - * acknowledging and then setting ADV_NXT_PKT caused an extra interrupt - * on the J2573. - */ - hp100_outw(val, IRQ_STATUS); - - /* - * RX_ERROR is set when a packet is dropped due to no memory resources on - * the card or when a RCV_ERR occurs. - * TX_ERROR is set when a TX_ABORT condition occurs in the MAC->exists - * only in the 802.3 MAC and happens when 16 collisions occur during a TX - */ - if (val & (HP100_TX_ERROR | HP100_RX_ERROR)) { -#ifdef HP100_DEBUG_IRQ - printk("hp100: %s: TX/RX Error IRQ\n", dev->name); -#endif - hp100_update_stats(dev); - if (lp->mode == 1) { - hp100_rxfill(dev); - hp100_clean_txring(dev); - } - } - - /* - * RX_PDA_ZERO is set when the PDA count goes from non-zero to zero. - */ - if ((lp->mode == 1) && (val & (HP100_RX_PDA_ZERO))) - hp100_rxfill(dev); - - /* - * HP100_TX_COMPLETE interrupt occurs when packet transmitted on wire - * is completed - */ - if ((lp->mode == 1) && (val & (HP100_TX_COMPLETE))) - hp100_clean_txring(dev); - - /* - * MISC_ERROR is set when either the LAN link goes down or a detected - * bus error occurs. - */ - if (val & HP100_MISC_ERROR) { /* New for J2585B */ -#ifdef HP100_DEBUG_IRQ - printk - ("hp100: %s: Misc. Error Interrupt - Check cabling.\n", - dev->name); -#endif - if (lp->mode == 1) { - hp100_clean_txring(dev); - hp100_rxfill(dev); - } - hp100_misc_interrupt(dev); - } - - spin_unlock(&lp->lock); - hp100_ints_on(); - return IRQ_HANDLED; -} - -/* - * some misc functions - */ - -static void hp100_start_interface(struct net_device *dev) -{ - unsigned long flags; - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4220, TRACE); - printk("hp100: %s: hp100_start_interface\n", dev->name); -#endif - - spin_lock_irqsave(&lp->lock, flags); - - /* Ensure the adapter does not want to request an interrupt when */ - /* enabling the IRQ line to be active on the bus (i.e. not tri-stated) */ - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* ack all IRQs */ - hp100_outw(HP100_FAKE_INT | HP100_INT_EN | HP100_RESET_LB, - OPTION_LSW); - /* Un Tri-state int. TODO: Check if shared interrupts can be realised? */ - hp100_outw(HP100_TRI_INT | HP100_RESET_HB, OPTION_LSW); - - if (lp->mode == 1) { - /* Make sure BM bit is set... */ - hp100_page(HW_MAP); - hp100_orb(HP100_BM_MASTER, BM); - hp100_rxfill(dev); - } else if (lp->mode == 2) { - /* Enable memory mapping. Note: Don't do this when busmaster. */ - hp100_outw(HP100_MMAP_DIS | HP100_RESET_HB, OPTION_LSW); - } - - hp100_page(PERFORMANCE); - hp100_outw(0xfefe, IRQ_MASK); /* mask off all ints */ - hp100_outw(0xffff, IRQ_STATUS); /* ack IRQ */ - - /* enable a few interrupts: */ - if (lp->mode == 1) { /* busmaster mode */ - hp100_outw(HP100_RX_PDL_FILL_COMPL | - HP100_RX_PDA_ZERO | HP100_RX_ERROR | - /* HP100_RX_PACKET | */ - /* HP100_RX_EARLY_INT | */ HP100_SET_HB | - /* HP100_TX_PDA_ZERO | */ - HP100_TX_COMPLETE | - /* HP100_MISC_ERROR | */ - HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK); - } else { - hp100_outw(HP100_RX_PACKET | - HP100_RX_ERROR | HP100_SET_HB | - HP100_TX_ERROR | HP100_SET_LB, IRQ_MASK); - } - - /* Note : before hp100_set_multicast_list(), because it will play with - * spinlock itself... Jean II */ - spin_unlock_irqrestore(&lp->lock, flags); - - /* Enable MAC Tx and RX, set MAC modes, ... */ - hp100_set_multicast_list(dev); -} - -static void hp100_stop_interface(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); - int ioaddr = dev->base_addr; - u_int val; - -#ifdef HP100_DEBUG_B - printk("hp100: %s: hp100_stop_interface\n", dev->name); - hp100_outw(0x4221, TRACE); -#endif - - if (lp->mode == 1) - hp100_BM_shutdown(dev); - else { - /* Note: MMAP_DIS will be reenabled by start_interface */ - hp100_outw(HP100_INT_EN | HP100_RESET_LB | - HP100_TRI_INT | HP100_MMAP_DIS | HP100_SET_HB, - OPTION_LSW); - val = hp100_inw(OPTION_LSW); - - hp100_page(MAC_CTRL); - hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1); - - if (!(val & HP100_HW_RST)) - return; /* If reset, imm. return ... */ - /* ... else: busy wait until idle */ - for (val = 0; val < 6000; val++) - if ((hp100_inb(MAC_CFG_1) & (HP100_TX_IDLE | HP100_RX_IDLE)) == (HP100_TX_IDLE | HP100_RX_IDLE)) { - hp100_page(PERFORMANCE); - return; - } - printk("hp100: %s: hp100_stop_interface - timeout\n", dev->name); - hp100_page(PERFORMANCE); - } -} - -static void hp100_load_eeprom(struct net_device *dev, u_short probe_ioaddr) -{ - int i; - int ioaddr = probe_ioaddr > 0 ? probe_ioaddr : dev->base_addr; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4222, TRACE); -#endif - - hp100_page(EEPROM_CTRL); - hp100_andw(~HP100_EEPROM_LOAD, EEPROM_CTRL); - hp100_orw(HP100_EEPROM_LOAD, EEPROM_CTRL); - for (i = 0; i < 10000; i++) - if (!(hp100_inb(OPTION_MSW) & HP100_EE_LOAD)) - return; - printk("hp100: %s: hp100_load_eeprom - timeout\n", dev->name); -} - -/* Sense connection status. - * return values: LAN_10 - Connected to 10Mbit/s network - * LAN_100 - Connected to 100Mbit/s network - * LAN_ERR - not connected or 100Mbit/s Hub down - */ -static int hp100_sense_lan(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - u_short val_VG, val_10; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4223, TRACE); -#endif - - hp100_page(MAC_CTRL); - val_10 = hp100_inb(10_LAN_CFG_1); - val_VG = hp100_inb(VG_LAN_CFG_1); - hp100_page(PERFORMANCE); -#ifdef HP100_DEBUG - printk("hp100: %s: sense_lan: val_VG = 0x%04x, val_10 = 0x%04x\n", - dev->name, val_VG, val_10); -#endif - - if (val_10 & HP100_LINK_BEAT_ST) /* 10Mb connection is active */ - return HP100_LAN_10; - - if (val_10 & HP100_AUI_ST) { /* have we BNC or AUI onboard? */ - /* - * This can be overriden by dos utility, so if this has no effect, - * perhaps you need to download that utility from HP and set card - * back to "auto detect". - */ - val_10 |= HP100_AUI_SEL | HP100_LOW_TH; - hp100_page(MAC_CTRL); - hp100_outb(val_10, 10_LAN_CFG_1); - hp100_page(PERFORMANCE); - return HP100_LAN_COAX; - } - - /* Those cards don't have a 100 Mbit connector */ - if ( !strcmp(lp->id, "HWP1920") || - (lp->pci_dev && - lp->pci_dev->vendor == PCI_VENDOR_ID && - (lp->pci_dev->device == PCI_DEVICE_ID_HP_J2970A || - lp->pci_dev->device == PCI_DEVICE_ID_HP_J2973A))) - return HP100_LAN_ERR; - - if (val_VG & HP100_LINK_CABLE_ST) /* Can hear the HUBs tone. */ - return HP100_LAN_100; - return HP100_LAN_ERR; -} - -static int hp100_down_vg_link(struct net_device *dev) -{ - struct hp100_private *lp = netdev_priv(dev); - int ioaddr = dev->base_addr; - unsigned long time; - long savelan, newlan; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4224, TRACE); - printk("hp100: %s: down_vg_link\n", dev->name); -#endif - - hp100_page(MAC_CTRL); - time = jiffies + (HZ / 4); - do { - if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - - if (time_after_eq(jiffies, time)) /* no signal->no logout */ - return 0; - - /* Drop the VG Link by clearing the link up cmd and load addr. */ - - hp100_andb(~(HP100_LOAD_ADDR | HP100_LINK_CMD), VG_LAN_CFG_1); - hp100_orb(HP100_VG_SEL, VG_LAN_CFG_1); - - /* Conditionally stall for >250ms on Link-Up Status (to go down) */ - time = jiffies + (HZ / 2); - do { - if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - -#ifdef HP100_DEBUG - if (time_after_eq(jiffies, time)) - printk("hp100: %s: down_vg_link: Link does not go down?\n", dev->name); -#endif - - /* To prevent condition where Rev 1 VG MAC and old hubs do not complete */ - /* logout under traffic (even though all the status bits are cleared), */ - /* do this workaround to get the Rev 1 MAC in its idle state */ - if (lp->chip == HP100_CHIPID_LASSEN) { - /* Reset VG MAC to insure it leaves the logoff state even if */ - /* the Hub is still emitting tones */ - hp100_andb(~HP100_VG_RESET, VG_LAN_CFG_1); - udelay(1500); /* wait for >1ms */ - hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); /* Release Reset */ - udelay(1500); - } - - /* New: For lassen, switch to 10 Mbps mac briefly to clear training ACK */ - /* to get the VG mac to full reset. This is not req.d with later chips */ - /* Note: It will take the between 1 and 2 seconds for the VG mac to be */ - /* selected again! This will be left to the connect hub function to */ - /* perform if desired. */ - if (lp->chip == HP100_CHIPID_LASSEN) { - /* Have to write to 10 and 100VG control registers simultaneously */ - savelan = newlan = hp100_inl(10_LAN_CFG_1); /* read 10+100 LAN_CFG regs */ - newlan &= ~(HP100_VG_SEL << 16); - newlan |= (HP100_DOT3_MAC) << 8; - hp100_andb(~HP100_AUTO_MODE, MAC_CFG_3); /* Autosel off */ - hp100_outl(newlan, 10_LAN_CFG_1); - - /* Conditionally stall for 5sec on VG selected. */ - time = jiffies + (HZ * 5); - do { - if (!(hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - - hp100_orb(HP100_AUTO_MODE, MAC_CFG_3); /* Autosel back on */ - hp100_outl(savelan, 10_LAN_CFG_1); - } - - time = jiffies + (3 * HZ); /* Timeout 3s */ - do { - if ((hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) == 0) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - - if (time_before_eq(time, jiffies)) { -#ifdef HP100_DEBUG - printk("hp100: %s: down_vg_link: timeout\n", dev->name); -#endif - return -EIO; - } - - time = jiffies + (2 * HZ); /* This seems to take a while.... */ - do { - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - - return 0; -} - -static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - u_short val = 0; - unsigned long time; - int startst; - -#ifdef HP100_DEBUG_B - hp100_outw(0x4225, TRACE); - printk("hp100: %s: login_to_vg_hub\n", dev->name); -#endif - - /* Initiate a login sequence iff VG MAC is enabled and either Load Address - * bit is zero or the force relogin flag is set (e.g. due to MAC address or - * promiscuous mode change) - */ - hp100_page(MAC_CTRL); - startst = hp100_inb(VG_LAN_CFG_1); - if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) { -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: Start training\n", dev->name); -#endif - - /* Ensure VG Reset bit is 1 (i.e., do not reset) */ - hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1); - - /* If Lassen AND auto-select-mode AND VG tones were sensed on */ - /* entry then temporarily put them into force 100Mbit mode */ - if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) - hp100_andb(~HP100_DOT3_MAC, 10_LAN_CFG_2); - - /* Drop the VG link by zeroing Link Up Command and Load Address */ - hp100_andb(~(HP100_LINK_CMD /* |HP100_LOAD_ADDR */ ), VG_LAN_CFG_1); - -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: Bring down the link\n", dev->name); -#endif - - /* Wait for link to drop */ - time = jiffies + (HZ / 10); - do { - if (!(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST)) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - - /* Start an addressed training and optionally request promiscuous port */ - if ((dev->flags) & IFF_PROMISC) { - hp100_orb(HP100_PROM_MODE, VG_LAN_CFG_2); - if (lp->chip == HP100_CHIPID_LASSEN) - hp100_orw(HP100_MACRQ_PROMSC, TRAIN_REQUEST); - } else { - hp100_andb(~HP100_PROM_MODE, VG_LAN_CFG_2); - /* For ETR parts we need to reset the prom. bit in the training - * register, otherwise promiscious mode won't be disabled. - */ - if (lp->chip == HP100_CHIPID_LASSEN) { - hp100_andw(~HP100_MACRQ_PROMSC, TRAIN_REQUEST); - } - } - - /* With ETR parts, frame format request bits can be set. */ - if (lp->chip == HP100_CHIPID_LASSEN) - hp100_orb(HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST); - - hp100_orb(HP100_LINK_CMD | HP100_LOAD_ADDR | HP100_VG_RESET, VG_LAN_CFG_1); - - /* Note: Next wait could be omitted for Hood and earlier chips under */ - /* certain circumstances */ - /* TODO: check if hood/earlier and skip wait. */ - - /* Wait for either short timeout for VG tones or long for login */ - /* Wait for the card hardware to signalise link cable status ok... */ - hp100_page(MAC_CTRL); - time = jiffies + (1 * HZ); /* 1 sec timeout for cable st */ - do { - if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST) - break; - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_before(jiffies, time)); - - if (time_after_eq(jiffies, time)) { -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: Link cable status not ok? Training aborted.\n", dev->name); -#endif - } else { -#ifdef HP100_DEBUG_TRAINING - printk - ("hp100: %s: HUB tones detected. Trying to train.\n", - dev->name); -#endif - - time = jiffies + (2 * HZ); /* again a timeout */ - do { - val = hp100_inb(VG_LAN_CFG_1); - if ((val & (HP100_LINK_UP_ST))) { -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: Passed training.\n", dev->name); -#endif - break; - } - if (!in_interrupt()) - schedule_timeout_interruptible(1); - } while (time_after(time, jiffies)); - } - - /* If LINK_UP_ST is set, then we are logged into the hub. */ - if (time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST)) { -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: Successfully logged into the HUB.\n", dev->name); - if (lp->chip == HP100_CHIPID_LASSEN) { - val = hp100_inw(TRAIN_ALLOW); - printk("hp100: %s: Card supports 100VG MAC Version \"%s\" ", - dev->name, (hp100_inw(TRAIN_REQUEST) & HP100_CARD_MACVER) ? "802.12" : "Pre"); - printk("Driver will use MAC Version \"%s\"\n", (val & HP100_HUB_MACVER) ? "802.12" : "Pre"); - printk("hp100: %s: Frame format is %s.\n", dev->name, (val & HP100_MALLOW_FRAMEFMT) ? "802.5" : "802.3"); - } -#endif - } else { - /* If LINK_UP_ST is not set, login was not successful */ - printk("hp100: %s: Problem logging into the HUB.\n", dev->name); - if (lp->chip == HP100_CHIPID_LASSEN) { - /* Check allowed Register to find out why there is a problem. */ - val = hp100_inw(TRAIN_ALLOW); /* won't work on non-ETR card */ -#ifdef HP100_DEBUG_TRAINING - printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val); -#endif - if (val & HP100_MALLOW_ACCDENIED) - printk("hp100: %s: HUB access denied.\n", dev->name); - if (val & HP100_MALLOW_CONFIGURE) - printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name); - if (val & HP100_MALLOW_DUPADDR) - printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name); - } - } - - /* If we have put the chip into forced 100 Mbit mode earlier, go back */ - /* to auto-select mode */ - - if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) { - hp100_page(MAC_CTRL); - hp100_orb(HP100_DOT3_MAC, 10_LAN_CFG_2); - } - - val = hp100_inb(VG_LAN_CFG_1); - - /* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */ - hp100_page(PERFORMANCE); - hp100_outw(HP100_MISC_ERROR, IRQ_STATUS); - - if (val & HP100_LINK_UP_ST) - return 0; /* login was ok */ - else { - printk("hp100: %s: Training failed.\n", dev->name); - hp100_down_vg_link(dev); - return -EIO; - } - } - /* no forced relogin & already link there->no training. */ - return -EIO; -} - -static void hp100_cascade_reset(struct net_device *dev, u_short enable) -{ - int ioaddr = dev->base_addr; - struct hp100_private *lp = netdev_priv(dev); - -#ifdef HP100_DEBUG_B - hp100_outw(0x4226, TRACE); - printk("hp100: %s: cascade_reset\n", dev->name); -#endif - - if (enable) { - hp100_outw(HP100_HW_RST | HP100_RESET_LB, OPTION_LSW); - if (lp->chip == HP100_CHIPID_LASSEN) { - /* Lassen requires a PCI transmit fifo reset */ - hp100_page(HW_MAP); - hp100_andb(~HP100_PCI_RESET, PCICTRL2); - hp100_orb(HP100_PCI_RESET, PCICTRL2); - /* Wait for min. 300 ns */ - /* we can't use jiffies here, because it may be */ - /* that we have disabled the timer... */ - udelay(400); - hp100_andb(~HP100_PCI_RESET, PCICTRL2); - hp100_page(PERFORMANCE); - } - } else { /* bring out of reset */ - hp100_outw(HP100_HW_RST | HP100_SET_LB, OPTION_LSW); - udelay(400); - hp100_page(PERFORMANCE); - } -} - -#ifdef HP100_DEBUG -void hp100_RegisterDump(struct net_device *dev) -{ - int ioaddr = dev->base_addr; - int Page; - int Register; - - /* Dump common registers */ - printk("hp100: %s: Cascade Register Dump\n", dev->name); - printk("hardware id #1: 0x%.2x\n", hp100_inb(HW_ID)); - printk("hardware id #2/paging: 0x%.2x\n", hp100_inb(PAGING)); - printk("option #1: 0x%.4x\n", hp100_inw(OPTION_LSW)); - printk("option #2: 0x%.4x\n", hp100_inw(OPTION_MSW)); - - /* Dump paged registers */ - for (Page = 0; Page < 8; Page++) { - /* Dump registers */ - printk("page: 0x%.2x\n", Page); - outw(Page, ioaddr + 0x02); - for (Register = 0x8; Register < 0x22; Register += 2) { - /* Display Register contents except data port */ - if (((Register != 0x10) && (Register != 0x12)) || (Page > 0)) { - printk("0x%.2x = 0x%.4x\n", Register, inw(ioaddr + Register)); - } - } - } - hp100_page(PERFORMANCE); -} -#endif - - -static void cleanup_dev(struct net_device *d) -{ - struct hp100_private *p = netdev_priv(d); - - unregister_netdev(d); - release_region(d->base_addr, HP100_REGION_SIZE); - - if (p->mode == 1) /* busmaster */ - pci_free_consistent(p->pci_dev, MAX_RINGSIZE + 0x0f, - p->page_vaddr_algn, - virt_to_whatever(d, p->page_vaddr_algn)); - if (p->mem_ptr_virt) - iounmap(p->mem_ptr_virt); - - free_netdev(d); -} - -static int hp100_eisa_probe(struct device *gendev) -{ - struct net_device *dev = alloc_etherdev(sizeof(struct hp100_private)); - struct eisa_device *edev = to_eisa_device(gendev); - int err; - - if (!dev) - return -ENOMEM; - - SET_NETDEV_DEV(dev, &edev->dev); - - err = hp100_probe1(dev, edev->base_addr + 0xC38, HP100_BUS_EISA, NULL); - if (err) - goto out1; - -#ifdef HP100_DEBUG - printk("hp100: %s: EISA adapter found at 0x%x\n", dev->name, - dev->base_addr); -#endif - dev_set_drvdata(gendev, dev); - return 0; - out1: - free_netdev(dev); - return err; -} - -static int hp100_eisa_remove(struct device *gendev) -{ - struct net_device *dev = dev_get_drvdata(gendev); - cleanup_dev(dev); - return 0; -} - -static struct eisa_driver hp100_eisa_driver = { - .id_table = hp100_eisa_tbl, - .driver = { - .name = "hp100", - .probe = hp100_eisa_probe, - .remove = hp100_eisa_remove, - } -}; - -static int hp100_pci_probe(struct pci_dev *pdev, - const struct pci_device_id *ent) -{ - struct net_device *dev; - int ioaddr; - u_short pci_command; - int err; - - if (pci_enable_device(pdev)) - return -ENODEV; - - dev = alloc_etherdev(sizeof(struct hp100_private)); - if (!dev) { - err = -ENOMEM; - goto out0; - } - - SET_NETDEV_DEV(dev, &pdev->dev); - - pci_read_config_word(pdev, PCI_COMMAND, &pci_command); - if (!(pci_command & PCI_COMMAND_IO)) { -#ifdef HP100_DEBUG - printk("hp100: %s: PCI I/O Bit has not been set. Setting...\n", dev->name); -#endif - pci_command |= PCI_COMMAND_IO; - pci_write_config_word(pdev, PCI_COMMAND, pci_command); - } - - if (!(pci_command & PCI_COMMAND_MASTER)) { -#ifdef HP100_DEBUG - printk("hp100: %s: PCI Master Bit has not been set. Setting...\n", dev->name); -#endif - pci_command |= PCI_COMMAND_MASTER; - pci_write_config_word(pdev, PCI_COMMAND, pci_command); - } - - ioaddr = pci_resource_start(pdev, 0); - err = hp100_probe1(dev, ioaddr, HP100_BUS_PCI, pdev); - if (err) - goto out1; - -#ifdef HP100_DEBUG - printk("hp100: %s: PCI adapter found at 0x%x\n", dev->name, ioaddr); -#endif - pci_set_drvdata(pdev, dev); - return 0; - out1: - free_netdev(dev); - out0: - pci_disable_device(pdev); - return err; -} - -static void hp100_pci_remove(struct pci_dev *pdev) -{ - struct net_device *dev = pci_get_drvdata(pdev); - - cleanup_dev(dev); - pci_disable_device(pdev); -} - - -static struct pci_driver hp100_pci_driver = { - .name = "hp100", - .id_table = hp100_pci_tbl, - .probe = hp100_pci_probe, - .remove = hp100_pci_remove, -}; - -/* - * module section - */ - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, " - "Siegfried \"Frieder\" Loeffler (dg1sek) <floeff@mathematik.uni-stuttgart.de>"); -MODULE_DESCRIPTION("HP CASCADE Architecture Driver for 100VG-AnyLan Network Adapters"); - -/* - * Note: to register three isa devices, use: - * option hp100 hp100_port=0,0,0 - * to register one card at io 0x280 as eth239, use: - * option hp100 hp100_port=0x280 - */ -#if defined(MODULE) && defined(CONFIG_ISA) -#define HP100_DEVICES 5 -/* Parameters set by insmod */ -static int hp100_port[HP100_DEVICES] = { 0, [1 ... (HP100_DEVICES-1)] = -1 }; -module_param_hw_array(hp100_port, int, ioport, NULL, 0); - -/* List of devices */ -static struct net_device *hp100_devlist[HP100_DEVICES]; - -static int __init hp100_isa_init(void) -{ - struct net_device *dev; - int i, err, cards = 0; - - /* Don't autoprobe ISA bus */ - if (hp100_port[0] == 0) - return -ENODEV; - - /* Loop on all possible base addresses */ - for (i = 0; i < HP100_DEVICES && hp100_port[i] != -1; ++i) { - dev = alloc_etherdev(sizeof(struct hp100_private)); - if (!dev) { - while (cards > 0) - cleanup_dev(hp100_devlist[--cards]); - - return -ENOMEM; - } - - err = hp100_isa_probe(dev, hp100_port[i]); - if (!err) - hp100_devlist[cards++] = dev; - else - free_netdev(dev); - } - - return cards > 0 ? 0 : -ENODEV; -} - -static void hp100_isa_cleanup(void) -{ - int i; - - for (i = 0; i < HP100_DEVICES; i++) { - struct net_device *dev = hp100_devlist[i]; - if (dev) - cleanup_dev(dev); - } -} -#else -#define hp100_isa_init() (0) -#define hp100_isa_cleanup() do { } while(0) -#endif - -static int __init hp100_module_init(void) -{ - int err; - - err = hp100_isa_init(); - if (err && err != -ENODEV) - goto out; - err = eisa_driver_register(&hp100_eisa_driver); - if (err && err != -ENODEV) - goto out2; - err = pci_register_driver(&hp100_pci_driver); - if (err && err != -ENODEV) - goto out3; - out: - return err; - out3: - eisa_driver_unregister (&hp100_eisa_driver); - out2: - hp100_isa_cleanup(); - goto out; -} - - -static void __exit hp100_module_exit(void) -{ - hp100_isa_cleanup(); - eisa_driver_unregister (&hp100_eisa_driver); - pci_unregister_driver (&hp100_pci_driver); -} - -module_init(hp100_module_init) -module_exit(hp100_module_exit) diff --git a/drivers/staging/hp/hp100.h b/drivers/staging/hp/hp100.h deleted file mode 100644 index 7239b94c9de5..000000000000 --- a/drivers/staging/hp/hp100.h +++ /dev/null @@ -1,611 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * hp100.h: Hewlett Packard HP10/100VG ANY LAN ethernet driver for Linux. - * - * $Id: hp100.h,v 1.51 1997/04/08 14:26:42 floeff Exp floeff $ - * - * Authors: Jaroslav Kysela, <perex@pf.jcu.cz> - * Siegfried Loeffler <floeff@tunix.mathematik.uni-stuttgart.de> - * - * This driver is based on the 'hpfepkt' crynwr packet driver. - */ - -/**************************************************************************** - * Hardware Constants - ****************************************************************************/ - -/* - * Page Identifiers - * (Swap Paging Register, PAGING, bits 3:0, Offset 0x02) - */ - -#define HP100_PAGE_PERFORMANCE 0x0 /* Page 0 */ -#define HP100_PAGE_MAC_ADDRESS 0x1 /* Page 1 */ -#define HP100_PAGE_HW_MAP 0x2 /* Page 2 */ -#define HP100_PAGE_EEPROM_CTRL 0x3 /* Page 3 */ -#define HP100_PAGE_MAC_CTRL 0x4 /* Page 4 */ -#define HP100_PAGE_MMU_CFG 0x5 /* Page 5 */ -#define HP100_PAGE_ID_MAC_ADDR 0x6 /* Page 6 */ -#define HP100_PAGE_MMU_POINTER 0x7 /* Page 7 */ - - -/* Registers that are present on all pages */ - -#define HP100_REG_HW_ID 0x00 /* R: (16) Unique card ID */ -#define HP100_REG_TRACE 0x00 /* W: (16) Used for debug output */ -#define HP100_REG_PAGING 0x02 /* R: (16),15:4 Card ID */ - /* W: (16),3:0 Switch pages */ -#define HP100_REG_OPTION_LSW 0x04 /* RW: (16) Select card functions */ -#define HP100_REG_OPTION_MSW 0x06 /* RW: (16) Select card functions */ - -/* Page 0 - Performance */ - -#define HP100_REG_IRQ_STATUS 0x08 /* RW: (16) Which ints are pending */ -#define HP100_REG_IRQ_MASK 0x0a /* RW: (16) Select ints to allow */ -#define HP100_REG_FRAGMENT_LEN 0x0c /* W: (16)12:0 Current fragment len */ -/* Note: For 32 bit systems, fragment len and offset registers are available */ -/* at offset 0x28 and 0x2c, where they can be written as 32bit values. */ -#define HP100_REG_OFFSET 0x0e /* RW: (16)12:0 Offset to start read */ -#define HP100_REG_DATA32 0x10 /* RW: (32) I/O mode data port */ -#define HP100_REG_DATA16 0x12 /* RW: WORDs must be read from here */ -#define HP100_REG_TX_MEM_FREE 0x14 /* RD: (32) Amount of free Tx mem */ -#define HP100_REG_TX_PDA_L 0x14 /* W: (32) BM: Ptr to PDL, Low Pri */ -#define HP100_REG_TX_PDA_H 0x1c /* W: (32) BM: Ptr to PDL, High Pri */ -#define HP100_REG_RX_PKT_CNT 0x18 /* RD: (8) Rx count of pkts on card */ -#define HP100_REG_TX_PKT_CNT 0x19 /* RD: (8) Tx count of pkts on card */ -#define HP100_REG_RX_PDL 0x1a /* R: (8) BM: # rx pdl not executed */ -#define HP100_REG_TX_PDL 0x1b /* R: (8) BM: # tx pdl not executed */ -#define HP100_REG_RX_PDA 0x18 /* W: (32) BM: Up to 31 addresses */ - /* which point to a PDL */ -#define HP100_REG_SL_EARLY 0x1c /* (32) Enhanced Slave Early Rx */ -#define HP100_REG_STAT_DROPPED 0x20 /* R (12) Dropped Packet Counter */ -#define HP100_REG_STAT_ERRORED 0x22 /* R (8) Errored Packet Counter */ -#define HP100_REG_STAT_ABORT 0x23 /* R (8) Abort Counter/OW Coll. Flag */ -#define HP100_REG_RX_RING 0x24 /* W (32) Slave: RX Ring Pointers */ -#define HP100_REG_32_FRAGMENT_LEN 0x28 /* W (13) Slave: Fragment Length Reg */ -#define HP100_REG_32_OFFSET 0x2c /* W (16) Slave: Offset Register */ - -/* Page 1 - MAC Address/Hash Table */ - -#define HP100_REG_MAC_ADDR 0x08 /* RW: (8) Cards MAC address */ -#define HP100_REG_HASH_BYTE0 0x10 /* RW: (8) Cards multicast filter */ - -/* Page 2 - Hardware Mapping */ - -#define HP100_REG_MEM_MAP_LSW 0x08 /* RW: (16) LSW of cards mem addr */ -#define HP100_REG_MEM_MAP_MSW 0x0a /* RW: (16) MSW of cards mem addr */ -#define HP100_REG_IO_MAP 0x0c /* RW: (8) Cards I/O address */ -#define HP100_REG_IRQ_CHANNEL 0x0d /* RW: (8) IRQ and edge/level int */ -#define HP100_REG_SRAM 0x0e /* RW: (8) How much RAM on card */ -#define HP100_REG_BM 0x0f /* RW: (8) Controls BM functions */ - -/* New on Page 2 for ETR chips: */ -#define HP100_REG_MODECTRL1 0x10 /* RW: (8) Mode Control 1 */ -#define HP100_REG_MODECTRL2 0x11 /* RW: (8) Mode Control 2 */ -#define HP100_REG_PCICTRL1 0x12 /* RW: (8) PCI Cfg 1 */ -#define HP100_REG_PCICTRL2 0x13 /* RW: (8) PCI Cfg 2 */ -#define HP100_REG_PCIBUSMLAT 0x15 /* RW: (8) PCI Bus Master Latency */ -#define HP100_REG_EARLYTXCFG 0x16 /* RW: (16) Early TX Cfg/Cntrl Reg */ -#define HP100_REG_EARLYRXCFG 0x18 /* RW: (8) Early RX Cfg/Cntrl Reg */ -#define HP100_REG_ISAPNPCFG1 0x1a /* RW: (8) ISA PnP Cfg/Cntrl Reg 1 */ -#define HP100_REG_ISAPNPCFG2 0x1b /* RW: (8) ISA PnP Cfg/Cntrl Reg 2 */ - -/* Page 3 - EEPROM/Boot ROM */ - -#define HP100_REG_EEPROM_CTRL 0x08 /* RW: (16) Used to load EEPROM */ -#define HP100_REG_BOOTROM_CTRL 0x0a - -/* Page 4 - LAN Configuration (MAC_CTRL) */ - -#define HP100_REG_10_LAN_CFG_1 0x08 /* RW: (8) Set 10M XCVR functions */ -#define HP100_REG_10_LAN_CFG_2 0x09 /* RW: (8) 10M XCVR functions */ -#define HP100_REG_VG_LAN_CFG_1 0x0a /* RW: (8) Set 100M XCVR functions */ -#define HP100_REG_VG_LAN_CFG_2 0x0b /* RW: (8) 100M LAN Training cfgregs */ -#define HP100_REG_MAC_CFG_1 0x0c /* RW: (8) Types of pkts to accept */ -#define HP100_REG_MAC_CFG_2 0x0d /* RW: (8) Misc MAC functions */ -#define HP100_REG_MAC_CFG_3 0x0e /* RW: (8) Misc MAC functions */ -#define HP100_REG_MAC_CFG_4 0x0f /* R: (8) Misc MAC states */ -#define HP100_REG_DROPPED 0x10 /* R: (16),11:0 Pkts can't fit in mem */ -#define HP100_REG_CRC 0x12 /* R: (8) Pkts with CRC */ -#define HP100_REG_ABORT 0x13 /* R: (8) Aborted Tx pkts */ -#define HP100_REG_TRAIN_REQUEST 0x14 /* RW: (16) Endnode MAC register. */ -#define HP100_REG_TRAIN_ALLOW 0x16 /* R: (16) Hub allowed register */ - -/* Page 5 - MMU */ - -#define HP100_REG_RX_MEM_STOP 0x0c /* RW: (16) End of Rx ring addr */ -#define HP100_REG_TX_MEM_STOP 0x0e /* RW: (16) End of Tx ring addr */ -#define HP100_REG_PDL_MEM_STOP 0x10 /* Not used by 802.12 devices */ -#define HP100_REG_ECB_MEM_STOP 0x14 /* I've no idea what this is */ - -/* Page 6 - Card ID/Physical LAN Address */ - -#define HP100_REG_BOARD_ID 0x08 /* R: (8) EISA/ISA card ID */ -#define HP100_REG_BOARD_IO_CHCK 0x0c /* R: (8) Added to ID to get FFh */ -#define HP100_REG_SOFT_MODEL 0x0d /* R: (8) Config program defined */ -#define HP100_REG_LAN_ADDR 0x10 /* R: (8) MAC addr of card */ -#define HP100_REG_LAN_ADDR_CHCK 0x16 /* R: (8) Added to addr to get FFh */ - -/* Page 7 - MMU Current Pointers */ - -#define HP100_REG_PTR_RXSTART 0x08 /* R: (16) Current begin of Rx ring */ -#define HP100_REG_PTR_RXEND 0x0a /* R: (16) Current end of Rx ring */ -#define HP100_REG_PTR_TXSTART 0x0c /* R: (16) Current begin of Tx ring */ -#define HP100_REG_PTR_TXEND 0x0e /* R: (16) Current end of Rx ring */ -#define HP100_REG_PTR_RPDLSTART 0x10 -#define HP100_REG_PTR_RPDLEND 0x12 -#define HP100_REG_PTR_RINGPTRS 0x14 -#define HP100_REG_PTR_MEMDEBUG 0x1a -/* ------------------------------------------------------------------------ */ - - -/* - * Hardware ID Register I (Always available, HW_ID, Offset 0x00) - */ -#define HP100_HW_ID_CASCADE 0x4850 /* Identifies Cascade Chip */ - -/* - * Hardware ID Register 2 & Paging Register - * (Always available, PAGING, Offset 0x02) - * Bits 15:4 are for the Chip ID - */ -#define HP100_CHIPID_MASK 0xFFF0 -#define HP100_CHIPID_SHASTA 0x5350 /* Not 802.12 compliant */ - /* EISA BM/SL, MCA16/32 SL, ISA SL */ -#define HP100_CHIPID_RAINIER 0x5360 /* Not 802.12 compliant EISA BM, */ - /* PCI SL, MCA16/32 SL, ISA SL */ -#define HP100_CHIPID_LASSEN 0x5370 /* 802.12 compliant PCI BM, PCI SL */ - /* LRF supported */ - -/* - * Option Registers I and II - * (Always available, OPTION_LSW, Offset 0x04-0x05) - */ -#define HP100_DEBUG_EN 0x8000 /* 0:Dis., 1:Enable Debug Dump Ptr. */ -#define HP100_RX_HDR 0x4000 /* 0:Dis., 1:Enable putting pkt into */ - /* system mem. before Rx interrupt */ -#define HP100_MMAP_DIS 0x2000 /* 0:Enable, 1:Disable mem.mapping. */ - /* MMAP_DIS must be 0 and MEM_EN */ - /* must be 1 for memory-mapped */ - /* mode to be enabled */ -#define HP100_EE_EN 0x1000 /* 0:Disable,1:Enable EEPROM writing */ -#define HP100_BM_WRITE 0x0800 /* 0:Slave, 1:Bus Master for Tx data */ -#define HP100_BM_READ 0x0400 /* 0:Slave, 1:Bus Master for Rx data */ -#define HP100_TRI_INT 0x0200 /* 0:Don't, 1:Do tri-state the int */ -#define HP100_MEM_EN 0x0040 /* Config program set this to */ - /* 0:Disable, 1:Enable mem map. */ - /* See MMAP_DIS. */ -#define HP100_IO_EN 0x0020 /* 1:Enable I/O transfers */ -#define HP100_BOOT_EN 0x0010 /* 1:Enable boot ROM access */ -#define HP100_FAKE_INT 0x0008 /* 1:int */ -#define HP100_INT_EN 0x0004 /* 1:Enable ints from card */ -#define HP100_HW_RST 0x0002 /* 0:Reset, 1:Out of reset */ - /* NIC reset on 0 to 1 transition */ - -/* - * Option Register III - * (Always available, OPTION_MSW, Offset 0x06) - */ -#define HP100_PRIORITY_TX 0x0080 /* 1:Do all Tx pkts as priority */ -#define HP100_EE_LOAD 0x0040 /* 1:EEPROM loading, 0 when done */ -#define HP100_ADV_NXT_PKT 0x0004 /* 1:Advance to next pkt in Rx queue */ - /* h/w will set to 0 when done */ -#define HP100_TX_CMD 0x0002 /* 1:Tell h/w download done, h/w */ - /* will set to 0 when done */ - -/* - * Interrupt Status Registers I and II - * (Page PERFORMANCE, IRQ_STATUS, Offset 0x08-0x09) - * Note: With old chips, these Registers will clear when 1 is written to them - * with new chips this depends on setting of CLR_ISMODE - */ -#define HP100_RX_EARLY_INT 0x2000 -#define HP100_RX_PDA_ZERO 0x1000 -#define HP100_RX_PDL_FILL_COMPL 0x0800 -#define HP100_RX_PACKET 0x0400 /* 0:No, 1:Yes pkt has been Rx */ -#define HP100_RX_ERROR 0x0200 /* 0:No, 1:Yes Rx pkt had error */ -#define HP100_TX_PDA_ZERO 0x0020 /* 1 when PDA count goes to zero */ -#define HP100_TX_SPACE_AVAIL 0x0010 /* 0:<8192, 1:>=8192 Tx free bytes */ -#define HP100_TX_COMPLETE 0x0008 /* 0:No, 1:Yes a Tx has completed */ -#define HP100_MISC_ERROR 0x0004 /* 0:No, 1:Lan Link down or bus error */ -#define HP100_TX_ERROR 0x0002 /* 0:No, 1:Yes Tx pkt had error */ - -/* - * Xmit Memory Free Count - * (Page PERFORMANCE, TX_MEM_FREE, Offset 0x14) (Read only, 32bit) - */ -#define HP100_AUTO_COMPARE 0x80000000 /* Tx Space avail & pkts<255 */ -#define HP100_FREE_SPACE 0x7fffffe0 /* Tx free memory */ - -/* - * IRQ Channel - * (Page HW_MAP, IRQ_CHANNEL, Offset 0x0d) - */ -#define HP100_ZERO_WAIT_EN 0x80 /* 0:No, 1:Yes asserts NOWS signal */ -#define HP100_IRQ_SCRAMBLE 0x40 -#define HP100_BOND_HP 0x20 -#define HP100_LEVEL_IRQ 0x10 /* 0:Edge, 1:Level type interrupts. */ - /* (Only valid on EISA cards) */ -#define HP100_IRQMASK 0x0F /* Isolate the IRQ bits */ - -/* - * SRAM Parameters - * (Page HW_MAP, SRAM, Offset 0x0e) - */ -#define HP100_RAM_SIZE_MASK 0xe0 /* AND to get SRAM size index */ -#define HP100_RAM_SIZE_SHIFT 0x05 /* Shift count(put index in lwr bits) */ - -/* - * Bus Master Register - * (Page HW_MAP, BM, Offset 0x0f) - */ -#define HP100_BM_BURST_RD 0x01 /* EISA only: 1=Use burst trans. fm system */ - /* memory to chip (tx) */ -#define HP100_BM_BURST_WR 0x02 /* EISA only: 1=Use burst trans. fm system */ - /* memory to chip (rx) */ -#define HP100_BM_MASTER 0x04 /* 0:Slave, 1:BM mode */ -#define HP100_BM_PAGE_CK 0x08 /* This bit should be set whenever in */ - /* an EISA system */ -#define HP100_BM_PCI_8CLK 0x40 /* ... cycles 8 clocks apart */ - - -/* - * Mode Control Register I - * (Page HW_MAP, MODECTRL1, Offset0x10) - */ -#define HP100_TX_DUALQ 0x10 - /* If set and BM -> dual tx pda queues */ -#define HP100_ISR_CLRMODE 0x02 /* If set ISR will clear all pending */ - /* interrupts on read (etr only?) */ -#define HP100_EE_NOLOAD 0x04 /* Status whether res will be loaded */ - /* from the eeprom */ -#define HP100_TX_CNT_FLG 0x08 /* Controls Early TX Reg Cnt Field */ -#define HP100_PDL_USE3 0x10 /* If set BM engine will read only */ - /* first three data elements of a PDL */ - /* on the first access. */ -#define HP100_BUSTYPE_MASK 0xe0 /* Three bit bus type info */ - -/* - * Mode Control Register II - * (Page HW_MAP, MODECTRL2, Offset0x11) - */ -#define HP100_EE_MASK 0x0f /* Tell EEPROM circuit not to load */ - /* certain resources */ -#define HP100_DIS_CANCEL 0x20 /* For tx dualq mode operation */ -#define HP100_EN_PDL_WB 0x40 /* 1: Status of PDL completion may be */ - /* written back to system mem */ -#define HP100_EN_BUS_FAIL 0x80 /* Enables bus-fail portion of misc */ - /* interrupt */ - -/* - * PCI Configuration and Control Register I - * (Page HW_MAP, PCICTRL1, Offset 0x12) - */ -#define HP100_LO_MEM 0x01 /* 1: Mapped Mem requested below 1MB */ -#define HP100_NO_MEM 0x02 /* 1: Disables Req for sysmem to PCI */ - /* bios */ -#define HP100_USE_ISA 0x04 /* 1: isa type decodes will occur */ - /* simultaneously with PCI decodes */ -#define HP100_IRQ_HI_MASK 0xf0 /* pgmed by pci bios */ -#define HP100_PCI_IRQ_HI_MASK 0x78 /* Isolate 4 bits for PCI IRQ */ - -/* - * PCI Configuration and Control Register II - * (Page HW_MAP, PCICTRL2, Offset 0x13) - */ -#define HP100_RD_LINE_PDL 0x01 /* 1: PCI command Memory Read Line en */ -#define HP100_RD_TX_DATA_MASK 0x06 /* choose PCI memread cmds for TX */ -#define HP100_MWI 0x08 /* 1: en. PCI memory write invalidate */ -#define HP100_ARB_MODE 0x10 /* Select PCI arbitor type */ -#define HP100_STOP_EN 0x20 /* Enables PCI state machine to issue */ - /* pci stop if cascade not ready */ -#define HP100_IGNORE_PAR 0x40 /* 1: PCI state machine ignores parity */ -#define HP100_PCI_RESET 0x80 /* 0->1: Reset PCI block */ - -/* - * Early TX Configuration and Control Register - * (Page HW_MAP, EARLYTXCFG, Offset 0x16) - */ -#define HP100_EN_EARLY_TX 0x8000 /* 1=Enable Early TX */ -#define HP100_EN_ADAPTIVE 0x4000 /* 1=Enable adaptive mode */ -#define HP100_EN_TX_UR_IRQ 0x2000 /* reserved, must be 0 */ -#define HP100_EN_LOW_TX 0x1000 /* reserved, must be 0 */ -#define HP100_ET_CNT_MASK 0x0fff /* bits 11..0: ET counters */ - -/* - * Early RX Configuration and Control Register - * (Page HW_MAP, EARLYRXCFG, Offset 0x18) - */ -#define HP100_EN_EARLY_RX 0x80 /* 1=Enable Early RX */ -#define HP100_EN_LOW_RX 0x40 /* reserved, must be 0 */ -#define HP100_RX_TRIP_MASK 0x1f /* bits 4..0: threshold at which the - * early rx circuit will start the - * dma of received packet into system - * memory for BM */ - -/* - * Serial Devices Control Register - * (Page EEPROM_CTRL, EEPROM_CTRL, Offset 0x08) - */ -#define HP100_EEPROM_LOAD 0x0001 /* 0->1 loads EEPROM into registers. */ - /* When it goes back to 0, load is */ - /* complete. This should take ~600us. */ - -/* - * 10MB LAN Control and Configuration Register I - * (Page MAC_CTRL, 10_LAN_CFG_1, Offset 0x08) - */ -#define HP100_MAC10_SEL 0xc0 /* Get bits to indicate MAC */ -#define HP100_AUI_SEL 0x20 /* Status of AUI selection */ -#define HP100_LOW_TH 0x10 /* 0:No, 1:Yes allow better cabling */ -#define HP100_LINK_BEAT_DIS 0x08 /* 0:Enable, 1:Disable link beat */ -#define HP100_LINK_BEAT_ST 0x04 /* 0:No, 1:Yes link beat being Rx */ -#define HP100_R_ROL_ST 0x02 /* 0:No, 1:Yes Rx twisted pair has */ - /* been reversed */ -#define HP100_AUI_ST 0x01 /* 0:No, 1:Yes use AUI on TP card */ - -/* - * 10 MB LAN Control and Configuration Register II - * (Page MAC_CTRL, 10_LAN_CFG_2, Offset 0x09) - */ -#define HP100_SQU_ST 0x01 /* 0:No, 1:Yes collision signal sent */ - /* after Tx.Only used for AUI. */ -#define HP100_FULLDUP 0x02 /* 1: LXT901 XCVR fullduplx enabled */ -#define HP100_DOT3_MAC 0x04 /* 1: DOT 3 Mac sel. unless Autosel */ - -/* - * MAC Selection, use with MAC10_SEL bits - */ -#define HP100_AUTO_SEL_10 0x0 /* Auto select */ -#define HP100_XCVR_LXT901_10 0x1 /* LXT901 10BaseT transceiver */ -#define HP100_XCVR_7213 0x2 /* 7213 transceiver */ -#define HP100_XCVR_82503 0x3 /* 82503 transceiver */ - -/* - * 100MB LAN Training Register - * (Page MAC_CTRL, VG_LAN_CFG_2, Offset 0x0b) (old, pre 802.12) - */ -#define HP100_FRAME_FORMAT 0x08 /* 0:802.3, 1:802.5 frames */ -#define HP100_BRIDGE 0x04 /* 0:No, 1:Yes tell hub i am a bridge */ -#define HP100_PROM_MODE 0x02 /* 0:No, 1:Yes tell hub card is */ - /* promiscuous */ -#define HP100_REPEATER 0x01 /* 0:No, 1:Yes tell hub MAC wants to */ - /* be a cascaded repeater */ - -/* - * 100MB LAN Control and Configuration Register - * (Page MAC_CTRL, VG_LAN_CFG_1, Offset 0x0a) - */ -#define HP100_VG_SEL 0x80 /* 0:No, 1:Yes use 100 Mbit MAC */ -#define HP100_LINK_UP_ST 0x40 /* 0:No, 1:Yes endnode logged in */ -#define HP100_LINK_CABLE_ST 0x20 /* 0:No, 1:Yes cable can hear tones */ - /* from hub */ -#define HP100_LOAD_ADDR 0x10 /* 0->1 card addr will be sent */ - /* 100ms later the link status */ - /* bits are valid */ -#define HP100_LINK_CMD 0x08 /* 0->1 link will attempt to log in. */ - /* 100ms later the link status */ - /* bits are valid */ -#define HP100_TRN_DONE 0x04 /* NEW ETR-Chips only: Will be reset */ - /* after LinkUp Cmd is given and set */ - /* when training has completed. */ -#define HP100_LINK_GOOD_ST 0x02 /* 0:No, 1:Yes cable passed training */ -#define HP100_VG_RESET 0x01 /* 0:Yes, 1:No reset the 100VG MAC */ - - -/* - * MAC Configuration Register I - * (Page MAC_CTRL, MAC_CFG_1, Offset 0x0c) - */ -#define HP100_RX_IDLE 0x80 /* 0:Yes, 1:No currently receiving pkts */ -#define HP100_TX_IDLE 0x40 /* 0:Yes, 1:No currently Txing pkts */ -#define HP100_RX_EN 0x20 /* 1: allow receiving of pkts */ -#define HP100_TX_EN 0x10 /* 1: allow transmitting of pkts */ -#define HP100_ACC_ERRORED 0x08 /* 0:No, 1:Yes allow Rx of errored pkts */ -#define HP100_ACC_MC 0x04 /* 0:No, 1:Yes allow Rx of multicast pkts */ -#define HP100_ACC_BC 0x02 /* 0:No, 1:Yes allow Rx of broadcast pkts */ -#define HP100_ACC_PHY 0x01 /* 0:No, 1:Yes allow Rx of ALL phys. pkts */ -#define HP100_MAC1MODEMASK 0xf0 /* Hide ACC bits */ -#define HP100_MAC1MODE1 0x00 /* Receive nothing, must also disable RX */ -#define HP100_MAC1MODE2 0x00 -#define HP100_MAC1MODE3 HP100_MAC1MODE2 | HP100_ACC_BC -#define HP100_MAC1MODE4 HP100_MAC1MODE3 | HP100_ACC_MC -#define HP100_MAC1MODE5 HP100_MAC1MODE4 /* set mc hash to all ones also */ -#define HP100_MAC1MODE6 HP100_MAC1MODE5 | HP100_ACC_PHY /* Promiscuous */ -/* Note MODE6 will receive all GOOD packets on the LAN. This really needs - a mode 7 defined to be LAN Analyzer mode, which will receive errored and - runt packets, and keep the CRC bytes. */ -#define HP100_MAC1MODE7 HP100_MAC1MODE6 | HP100_ACC_ERRORED - -/* - * MAC Configuration Register II - * (Page MAC_CTRL, MAC_CFG_2, Offset 0x0d) - */ -#define HP100_TR_MODE 0x80 /* 0:No, 1:Yes support Token Ring formats */ -#define HP100_TX_SAME 0x40 /* 0:No, 1:Yes Tx same packet continuous */ -#define HP100_LBK_XCVR 0x20 /* 0:No, 1:Yes loopback through MAC & */ - /* transceiver */ -#define HP100_LBK_MAC 0x10 /* 0:No, 1:Yes loopback through MAC */ -#define HP100_CRC_I 0x08 /* 0:No, 1:Yes inhibit CRC on Tx packets */ -#define HP100_ACCNA 0x04 /* 1: For 802.5: Accept only token ring - * group addr that maches NA mask */ -#define HP100_KEEP_CRC 0x02 /* 0:No, 1:Yes keep CRC on Rx packets. */ - /* The length will reflect this. */ -#define HP100_ACCFA 0x01 /* 1: For 802.5: Accept only functional - * addrs that match FA mask (page1) */ -#define HP100_MAC2MODEMASK 0x02 -#define HP100_MAC2MODE1 0x00 -#define HP100_MAC2MODE2 0x00 -#define HP100_MAC2MODE3 0x00 -#define HP100_MAC2MODE4 0x00 -#define HP100_MAC2MODE5 0x00 -#define HP100_MAC2MODE6 0x00 -#define HP100_MAC2MODE7 KEEP_CRC - -/* - * MAC Configuration Register III - * (Page MAC_CTRL, MAC_CFG_3, Offset 0x0e) - */ -#define HP100_PACKET_PACE 0x03 /* Packet Pacing: - * 00: No packet pacing - * 01: 8 to 16 uS delay - * 10: 16 to 32 uS delay - * 11: 32 to 64 uS delay - */ -#define HP100_LRF_EN 0x04 /* 1: External LAN Rcv Filter and - * TCP/IP Checksumming enabled. */ -#define HP100_AUTO_MODE 0x10 /* 1: AutoSelect between 10/100 */ - -/* - * MAC Configuration Register IV - * (Page MAC_CTRL, MAC_CFG_4, Offset 0x0f) - */ -#define HP100_MAC_SEL_ST 0x01 /* (R): Status of external VGSEL - * Signal, 1=100VG, 0=10Mbit sel. */ -#define HP100_LINK_FAIL_ST 0x02 /* (R): Status of Link Fail portion - * of the Misc. Interrupt */ - -/* - * 100 MB LAN Training Request/Allowed Registers - * (Page MAC_CTRL, TRAIN_REQUEST and TRAIN_ALLOW, Offset 0x14-0x16)(ETR parts only) - */ -#define HP100_MACRQ_REPEATER 0x0001 /* 1: MAC tells HUB it wants to be - * a cascaded repeater - * 0: ... wants to be a DTE */ -#define HP100_MACRQ_PROMSC 0x0006 /* 2 bits: Promiscious mode - * 00: Rcv only unicast packets - * specifically addr to this - * endnode - * 10: Rcv all pckts fwded by - * the local repeater */ -#define HP100_MACRQ_FRAMEFMT_EITHER 0x0018 /* 11: either format allowed */ -#define HP100_MACRQ_FRAMEFMT_802_3 0x0000 /* 00: 802.3 is requested */ -#define HP100_MACRQ_FRAMEFMT_802_5 0x0010 /* 10: 802.5 format is requested */ -#define HP100_CARD_MACVER 0xe000 /* R: 3 bit Cards 100VG MAC version */ -#define HP100_MALLOW_REPEATER 0x0001 /* If reset, requested access as an - * end node is allowed */ -#define HP100_MALLOW_PROMSC 0x0004 /* 2 bits: Promiscious mode - * 00: Rcv only unicast packets - * specifically addr to this - * endnode - * 10: Rcv all pckts fwded by - * the local repeater */ -#define HP100_MALLOW_FRAMEFMT 0x00e0 /* 2 bits: Frame Format - * 00: 802.3 format will be used - * 10: 802.5 format will be used */ -#define HP100_MALLOW_ACCDENIED 0x0400 /* N bit */ -#define HP100_MALLOW_CONFIGURE 0x0f00 /* C bit */ -#define HP100_MALLOW_DUPADDR 0x1000 /* D bit */ -#define HP100_HUB_MACVER 0xe000 /* R: 3 bit 802.12 MAC/RMAC training */ - /* protocol of repeater */ - -/* ****************************************************************************** */ - -/* - * Set/Reset bits - */ -#define HP100_SET_HB 0x0100 /* 0:Set fields to 0 whose mask is 1 */ -#define HP100_SET_LB 0x0001 /* HB sets upper byte, LB sets lower byte */ -#define HP100_RESET_HB 0x0000 /* For readability when resetting bits */ -#define HP100_RESET_LB 0x0000 /* For readability when resetting bits */ - -/* - * Misc. Constants - */ -#define HP100_LAN_100 100 /* lan_type value for VG */ -#define HP100_LAN_10 10 /* lan_type value for 10BaseT */ -#define HP100_LAN_COAX 9 /* lan_type value for Coax */ -#define HP100_LAN_ERR (-1) /* lan_type value for link down */ - -/* - * Bus Master Data Structures ---------------------------------------------- - */ - -#define MAX_RX_PDL 30 /* Card limit = 31 */ -#define MAX_RX_FRAG 2 /* Don't need more... */ -#define MAX_TX_PDL 29 -#define MAX_TX_FRAG 2 /* Limit = 31 */ - -/* Define total PDL area size in bytes (should be 4096) */ -/* This is the size of kernel (dma) memory that will be allocated. */ -#define MAX_RINGSIZE ((MAX_RX_FRAG*8+4+4)*MAX_RX_PDL+(MAX_TX_FRAG*8+4+4)*MAX_TX_PDL)+16 - -/* Ethernet Packet Sizes */ -#define MIN_ETHER_SIZE 60 -#define MAX_ETHER_SIZE 1514 /* Needed for preallocation of */ - /* skb buffer when busmastering */ - -/* Tx or Rx Ring Entry */ -typedef struct hp100_ring { - u_int *pdl; /* Address of PDLs PDH, dword before - * this address is used for rx hdr */ - u_int pdl_paddr; /* Physical address of PDL */ - struct sk_buff *skb; - struct hp100_ring *next; -} hp100_ring_t; - - - -/* Mask for Header Descriptor */ -#define HP100_PKT_LEN_MASK 0x1FFF /* AND with RxLength to get length */ - - -/* Receive Packet Status. Note, the error bits are only valid if ACC_ERRORED - bit in the MAC Configuration Register 1 is set. */ -#define HP100_RX_PRI 0x8000 /* 0:No, 1:Yes packet is priority */ -#define HP100_SDF_ERR 0x4000 /* 0:No, 1:Yes start of frame error */ -#define HP100_SKEW_ERR 0x2000 /* 0:No, 1:Yes skew out of range */ -#define HP100_BAD_SYMBOL_ERR 0x1000 /* 0:No, 1:Yes invalid symbol received */ -#define HP100_RCV_IPM_ERR 0x0800 /* 0:No, 1:Yes pkt had an invalid packet */ - /* marker */ -#define HP100_SYMBOL_BAL_ERR 0x0400 /* 0:No, 1:Yes symbol balance error */ -#define HP100_VG_ALN_ERR 0x0200 /* 0:No, 1:Yes non-octet received */ -#define HP100_TRUNC_ERR 0x0100 /* 0:No, 1:Yes the packet was truncated */ -#define HP100_RUNT_ERR 0x0040 /* 0:No, 1:Yes pkt length < Min Pkt */ - /* Length Reg. */ -#define HP100_ALN_ERR 0x0010 /* 0:No, 1:Yes align error. */ -#define HP100_CRC_ERR 0x0008 /* 0:No, 1:Yes CRC occurred. */ - -/* The last three bits indicate the type of destination address */ - -#define HP100_MULTI_ADDR_HASH 0x0006 /* 110: Addr multicast, matched hash */ -#define HP100_BROADCAST_ADDR 0x0003 /* x11: Addr broadcast */ -#define HP100_MULTI_ADDR_NO_HASH 0x0002 /* 010: Addr multicast, didn't match hash */ -#define HP100_PHYS_ADDR_MATCH 0x0001 /* x01: Addr was physical and mine */ -#define HP100_PHYS_ADDR_NO_MATCH 0x0000 /* x00: Addr was physical but not mine */ - -/* - * macros - */ - -#define hp100_inb( reg ) \ - inb( ioaddr + HP100_REG_##reg ) -#define hp100_inw( reg ) \ - inw( ioaddr + HP100_REG_##reg ) -#define hp100_inl( reg ) \ - inl( ioaddr + HP100_REG_##reg ) -#define hp100_outb( data, reg ) \ - outb( data, ioaddr + HP100_REG_##reg ) -#define hp100_outw( data, reg ) \ - outw( data, ioaddr + HP100_REG_##reg ) -#define hp100_outl( data, reg ) \ - outl( data, ioaddr + HP100_REG_##reg ) -#define hp100_orb( data, reg ) \ - outb( inb( ioaddr + HP100_REG_##reg ) | (data), ioaddr + HP100_REG_##reg ) -#define hp100_orw( data, reg ) \ - outw( inw( ioaddr + HP100_REG_##reg ) | (data), ioaddr + HP100_REG_##reg ) -#define hp100_andb( data, reg ) \ - outb( inb( ioaddr + HP100_REG_##reg ) & (data), ioaddr + HP100_REG_##reg ) -#define hp100_andw( data, reg ) \ - outw( inw( ioaddr + HP100_REG_##reg ) & (data), ioaddr + HP100_REG_##reg ) - -#define hp100_page( page ) \ - outw( HP100_PAGE_##page, ioaddr + HP100_REG_PAGING ) -#define hp100_ints_off() \ - outw( HP100_INT_EN | HP100_RESET_LB, ioaddr + HP100_REG_OPTION_LSW ) -#define hp100_ints_on() \ - outw( HP100_INT_EN | HP100_SET_LB, ioaddr + HP100_REG_OPTION_LSW ) -#define hp100_mem_map_enable() \ - outw( HP100_MMAP_DIS | HP100_RESET_HB, ioaddr + HP100_REG_OPTION_LSW ) -#define hp100_mem_map_disable() \ - outw( HP100_MMAP_DIS | HP100_SET_HB, ioaddr + HP100_REG_OPTION_LSW ) diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192 b/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192 deleted file mode 100644 index 1c35c507cc05..000000000000 --- a/drivers/staging/iio/Documentation/sysfs-bus-iio-ad7192 +++ /dev/null @@ -1,20 +0,0 @@ -What: /sys/.../iio:deviceX/ac_excitation_en -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - This attribute, if available, is used to enable the AC - excitation mode found on some converters. In ac excitation mode, - the polarity of the excitation voltage is reversed on - alternate cycles, to eliminate DC errors. - -What: /sys/.../iio:deviceX/bridge_switch_en -KernelVersion: 3.1.0 -Contact: linux-iio@vger.kernel.org -Description: - This attribute, if available, is used to close or open the - bridge power down switch found on some converters. - In bridge applications, such as strain gauges and load cells, - the bridge itself consumes the majority of the current in the - system. To minimize the current consumption of the system, - the bridge can be disconnected (when it is not being used - using the bridge_switch_en attribute. diff --git a/drivers/staging/iio/TODO b/drivers/staging/iio/TODO index 1b8ebf2c1b69..4d469016a13a 100644 --- a/drivers/staging/iio/TODO +++ b/drivers/staging/iio/TODO @@ -1,10 +1,4 @@ -2018-04-15 - -All affected drivers: -Convert all uses of the old GPIO API from <linux/gpio.h> to the -GPIO descriptor API in <linux/gpio/consumer.h> and look up GPIO -lines from device tree, ACPI or board files, board files should -use <linux/gpio/machine.h>. +2020-02-25 ADI Drivers: diff --git a/drivers/staging/iio/accel/adis16203.c b/drivers/staging/iio/accel/adis16203.c index 39dfe3f7f254..fef52d9b5346 100644 --- a/drivers/staging/iio/accel/adis16203.c +++ b/drivers/staging/iio/accel/adis16203.c @@ -250,6 +250,7 @@ static const struct adis_data adis16203_data = { .diag_stat_reg = ADIS16203_DIAG_STAT, .self_test_mask = ADIS16203_MSC_CTRL_SELF_TEST_EN, + .self_test_reg = ADIS16203_MSC_CTRL, .self_test_no_autoclear = true, .timeouts = &adis16203_timeouts, diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c index 39eb8364aa95..8bd35c6c56a1 100644 --- a/drivers/staging/iio/accel/adis16240.c +++ b/drivers/staging/iio/accel/adis16240.c @@ -373,6 +373,7 @@ static const struct adis_data adis16240_data = { .diag_stat_reg = ADIS16240_DIAG_STAT, .self_test_mask = ADIS16240_MSC_CTRL_SELF_TEST_EN, + .self_test_reg = ADIS16240_MSC_CTRL, .self_test_no_autoclear = true, .timeouts = &adis16240_timeouts, diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index 31cd9a12f40f..b25f41053fac 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -15,18 +15,6 @@ config AD7816 To compile this driver as a module, choose M here: the module will be called ad7816. -config AD7192 - tristate "Analog Devices AD7190 AD7192 AD7193 AD7195 ADC driver" - depends on SPI - select AD_SIGMA_DELTA - help - Say yes here to build support for Analog Devices AD7190, - AD7192, AD7193 or AD7195 SPI analog to digital converters (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7192. - config AD7280 tristate "Analog Devices AD7280A Lithium Ion Battery Monitoring System" depends on SPI diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile index 4b76769b32bc..6436a62b6278 100644 --- a/drivers/staging/iio/adc/Makefile +++ b/drivers/staging/iio/adc/Makefile @@ -4,5 +4,4 @@ # obj-$(CONFIG_AD7816) += ad7816.o -obj-$(CONFIG_AD7192) += ad7192.o obj-$(CONFIG_AD7280) += ad7280a.o diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c deleted file mode 100644 index bf3e2a9cc07f..000000000000 --- a/drivers/staging/iio/adc/ad7192.c +++ /dev/null @@ -1,1022 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * AD7190 AD7192 AD7193 AD7195 SPI ADC driver - * - * Copyright 2011-2015 Analog Devices Inc. - */ - -#include <linux/interrupt.h> -#include <linux/clk.h> -#include <linux/device.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/sysfs.h> -#include <linux/spi/spi.h> -#include <linux/regulator/consumer.h> -#include <linux/err.h> -#include <linux/sched.h> -#include <linux/delay.h> - -#include <linux/iio/iio.h> -#include <linux/iio/sysfs.h> -#include <linux/iio/buffer.h> -#include <linux/iio/trigger.h> -#include <linux/iio/trigger_consumer.h> -#include <linux/iio/triggered_buffer.h> -#include <linux/iio/adc/ad_sigma_delta.h> - -/* Registers */ -#define AD7192_REG_COMM 0 /* Communications Register (WO, 8-bit) */ -#define AD7192_REG_STAT 0 /* Status Register (RO, 8-bit) */ -#define AD7192_REG_MODE 1 /* Mode Register (RW, 24-bit */ -#define AD7192_REG_CONF 2 /* Configuration Register (RW, 24-bit) */ -#define AD7192_REG_DATA 3 /* Data Register (RO, 24/32-bit) */ -#define AD7192_REG_ID 4 /* ID Register (RO, 8-bit) */ -#define AD7192_REG_GPOCON 5 /* GPOCON Register (RO, 8-bit) */ -#define AD7192_REG_OFFSET 6 /* Offset Register (RW, 16-bit */ - /* (AD7792)/24-bit (AD7192)) */ -#define AD7192_REG_FULLSALE 7 /* Full-Scale Register */ - /* (RW, 16-bit (AD7792)/24-bit (AD7192)) */ - -/* Communications Register Bit Designations (AD7192_REG_COMM) */ -#define AD7192_COMM_WEN BIT(7) /* Write Enable */ -#define AD7192_COMM_WRITE 0 /* Write Operation */ -#define AD7192_COMM_READ BIT(6) /* Read Operation */ -#define AD7192_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */ -#define AD7192_COMM_CREAD BIT(2) /* Continuous Read of Data Register */ - -/* Status Register Bit Designations (AD7192_REG_STAT) */ -#define AD7192_STAT_RDY BIT(7) /* Ready */ -#define AD7192_STAT_ERR BIT(6) /* Error (Overrange, Underrange) */ -#define AD7192_STAT_NOREF BIT(5) /* Error no external reference */ -#define AD7192_STAT_PARITY BIT(4) /* Parity */ -#define AD7192_STAT_CH3 BIT(2) /* Channel 3 */ -#define AD7192_STAT_CH2 BIT(1) /* Channel 2 */ -#define AD7192_STAT_CH1 BIT(0) /* Channel 1 */ - -/* Mode Register Bit Designations (AD7192_REG_MODE) */ -#define AD7192_MODE_SEL(x) (((x) & 0x7) << 21) /* Operation Mode Select */ -#define AD7192_MODE_SEL_MASK (0x7 << 21) /* Operation Mode Select Mask */ -#define AD7192_MODE_DAT_STA BIT(20) /* Status Register transmission */ -#define AD7192_MODE_CLKSRC(x) (((x) & 0x3) << 18) /* Clock Source Select */ -#define AD7192_MODE_SINC3 BIT(15) /* SINC3 Filter Select */ -#define AD7192_MODE_ACX BIT(14) /* AC excitation enable(AD7195 only)*/ -#define AD7192_MODE_ENPAR BIT(13) /* Parity Enable */ -#define AD7192_MODE_CLKDIV BIT(12) /* Clock divide by 2 (AD7190/2 only)*/ -#define AD7192_MODE_SCYCLE BIT(11) /* Single cycle conversion */ -#define AD7192_MODE_REJ60 BIT(10) /* 50/60Hz notch filter */ -#define AD7192_MODE_RATE(x) ((x) & 0x3FF) /* Filter Update Rate Select */ - -/* Mode Register: AD7192_MODE_SEL options */ -#define AD7192_MODE_CONT 0 /* Continuous Conversion Mode */ -#define AD7192_MODE_SINGLE 1 /* Single Conversion Mode */ -#define AD7192_MODE_IDLE 2 /* Idle Mode */ -#define AD7192_MODE_PWRDN 3 /* Power-Down Mode */ -#define AD7192_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */ -#define AD7192_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */ -#define AD7192_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */ -#define AD7192_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */ - -/* Mode Register: AD7192_MODE_CLKSRC options */ -#define AD7192_CLK_EXT_MCLK1_2 0 /* External 4.92 MHz Clock connected*/ - /* from MCLK1 to MCLK2 */ -#define AD7192_CLK_EXT_MCLK2 1 /* External Clock applied to MCLK2 */ -#define AD7192_CLK_INT 2 /* Internal 4.92 MHz Clock not */ - /* available at the MCLK2 pin */ -#define AD7192_CLK_INT_CO 3 /* Internal 4.92 MHz Clock available*/ - /* at the MCLK2 pin */ - -/* Configuration Register Bit Designations (AD7192_REG_CONF) */ - -#define AD7192_CONF_CHOP BIT(23) /* CHOP enable */ -#define AD7192_CONF_REFSEL BIT(20) /* REFIN1/REFIN2 Reference Select */ -#define AD7192_CONF_CHAN(x) ((x) << 8) /* Channel select */ -#define AD7192_CONF_CHAN_MASK (0x7FF << 8) /* Channel select mask */ -#define AD7192_CONF_BURN BIT(7) /* Burnout current enable */ -#define AD7192_CONF_REFDET BIT(6) /* Reference detect enable */ -#define AD7192_CONF_BUF BIT(4) /* Buffered Mode Enable */ -#define AD7192_CONF_UNIPOLAR BIT(3) /* Unipolar/Bipolar Enable */ -#define AD7192_CONF_GAIN(x) ((x) & 0x7) /* Gain Select */ - -#define AD7192_CH_AIN1P_AIN2M BIT(0) /* AIN1(+) - AIN2(-) */ -#define AD7192_CH_AIN3P_AIN4M BIT(1) /* AIN3(+) - AIN4(-) */ -#define AD7192_CH_TEMP BIT(2) /* Temp Sensor */ -#define AD7192_CH_AIN2P_AIN2M BIT(3) /* AIN2(+) - AIN2(-) */ -#define AD7192_CH_AIN1 BIT(4) /* AIN1 - AINCOM */ -#define AD7192_CH_AIN2 BIT(5) /* AIN2 - AINCOM */ -#define AD7192_CH_AIN3 BIT(6) /* AIN3 - AINCOM */ -#define AD7192_CH_AIN4 BIT(7) /* AIN4 - AINCOM */ - -#define AD7193_CH_AIN1P_AIN2M 0x001 /* AIN1(+) - AIN2(-) */ -#define AD7193_CH_AIN3P_AIN4M 0x002 /* AIN3(+) - AIN4(-) */ -#define AD7193_CH_AIN5P_AIN6M 0x004 /* AIN5(+) - AIN6(-) */ -#define AD7193_CH_AIN7P_AIN8M 0x008 /* AIN7(+) - AIN8(-) */ -#define AD7193_CH_TEMP 0x100 /* Temp senseor */ -#define AD7193_CH_AIN2P_AIN2M 0x200 /* AIN2(+) - AIN2(-) */ -#define AD7193_CH_AIN1 0x401 /* AIN1 - AINCOM */ -#define AD7193_CH_AIN2 0x402 /* AIN2 - AINCOM */ -#define AD7193_CH_AIN3 0x404 /* AIN3 - AINCOM */ -#define AD7193_CH_AIN4 0x408 /* AIN4 - AINCOM */ -#define AD7193_CH_AIN5 0x410 /* AIN5 - AINCOM */ -#define AD7193_CH_AIN6 0x420 /* AIN6 - AINCOM */ -#define AD7193_CH_AIN7 0x440 /* AIN7 - AINCOM */ -#define AD7193_CH_AIN8 0x480 /* AIN7 - AINCOM */ -#define AD7193_CH_AINCOM 0x600 /* AINCOM - AINCOM */ - -/* ID Register Bit Designations (AD7192_REG_ID) */ -#define ID_AD7190 0x4 -#define ID_AD7192 0x0 -#define ID_AD7193 0x2 -#define ID_AD7195 0x6 -#define AD7192_ID_MASK 0x0F - -/* GPOCON Register Bit Designations (AD7192_REG_GPOCON) */ -#define AD7192_GPOCON_BPDSW BIT(6) /* Bridge power-down switch enable */ -#define AD7192_GPOCON_GP32EN BIT(5) /* Digital Output P3 and P2 enable */ -#define AD7192_GPOCON_GP10EN BIT(4) /* Digital Output P1 and P0 enable */ -#define AD7192_GPOCON_P3DAT BIT(3) /* P3 state */ -#define AD7192_GPOCON_P2DAT BIT(2) /* P2 state */ -#define AD7192_GPOCON_P1DAT BIT(1) /* P1 state */ -#define AD7192_GPOCON_P0DAT BIT(0) /* P0 state */ - -#define AD7192_EXT_FREQ_MHZ_MIN 2457600 -#define AD7192_EXT_FREQ_MHZ_MAX 5120000 -#define AD7192_INT_FREQ_MHZ 4915200 - -#define AD7192_NO_SYNC_FILTER 1 -#define AD7192_SYNC3_FILTER 3 -#define AD7192_SYNC4_FILTER 4 - -/* NOTE: - * The AD7190/2/5 features a dual use data out ready DOUT/RDY output. - * In order to avoid contentions on the SPI bus, it's therefore necessary - * to use spi bus locking. - * - * The DOUT/RDY output must also be wired to an interrupt capable GPIO. - */ - -enum { - AD7192_SYSCALIB_ZERO_SCALE, - AD7192_SYSCALIB_FULL_SCALE, -}; - -struct ad7192_state { - struct regulator *avdd; - struct regulator *dvdd; - struct clk *mclk; - u16 int_vref_mv; - u32 fclk; - u32 f_order; - u32 mode; - u32 conf; - u32 scale_avail[8][2]; - u8 gpocon; - u8 devid; - u8 clock_sel; - struct mutex lock; /* protect sensor state */ - u8 syscalib_mode[8]; - - struct ad_sigma_delta sd; -}; - -static const char * const ad7192_syscalib_modes[] = { - [AD7192_SYSCALIB_ZERO_SCALE] = "zero_scale", - [AD7192_SYSCALIB_FULL_SCALE] = "full_scale", -}; - -static int ad7192_set_syscalib_mode(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, - unsigned int mode) -{ - struct ad7192_state *st = iio_priv(indio_dev); - - st->syscalib_mode[chan->channel] = mode; - - return 0; -} - -static int ad7192_get_syscalib_mode(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan) -{ - struct ad7192_state *st = iio_priv(indio_dev); - - return st->syscalib_mode[chan->channel]; -} - -static ssize_t ad7192_write_syscalib(struct iio_dev *indio_dev, - uintptr_t private, - const struct iio_chan_spec *chan, - const char *buf, size_t len) -{ - struct ad7192_state *st = iio_priv(indio_dev); - bool sys_calib; - int ret, temp; - - ret = strtobool(buf, &sys_calib); - if (ret) - return ret; - - temp = st->syscalib_mode[chan->channel]; - if (sys_calib) { - if (temp == AD7192_SYSCALIB_ZERO_SCALE) - ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_ZERO, - chan->address); - else - ret = ad_sd_calibrate(&st->sd, AD7192_MODE_CAL_SYS_FULL, - chan->address); - } - - return ret ? ret : len; -} - -static const struct iio_enum ad7192_syscalib_mode_enum = { - .items = ad7192_syscalib_modes, - .num_items = ARRAY_SIZE(ad7192_syscalib_modes), - .set = ad7192_set_syscalib_mode, - .get = ad7192_get_syscalib_mode -}; - -static const struct iio_chan_spec_ext_info ad7192_calibsys_ext_info[] = { - { - .name = "sys_calibration", - .write = ad7192_write_syscalib, - .shared = IIO_SEPARATE, - }, - IIO_ENUM("sys_calibration_mode", IIO_SEPARATE, - &ad7192_syscalib_mode_enum), - IIO_ENUM_AVAILABLE("sys_calibration_mode", &ad7192_syscalib_mode_enum), - {} -}; - -static struct ad7192_state *ad_sigma_delta_to_ad7192(struct ad_sigma_delta *sd) -{ - return container_of(sd, struct ad7192_state, sd); -} - -static int ad7192_set_channel(struct ad_sigma_delta *sd, unsigned int channel) -{ - struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd); - - st->conf &= ~AD7192_CONF_CHAN_MASK; - st->conf |= AD7192_CONF_CHAN(channel); - - return ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf); -} - -static int ad7192_set_mode(struct ad_sigma_delta *sd, - enum ad_sigma_delta_mode mode) -{ - struct ad7192_state *st = ad_sigma_delta_to_ad7192(sd); - - st->mode &= ~AD7192_MODE_SEL_MASK; - st->mode |= AD7192_MODE_SEL(mode); - - return ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); -} - -static const struct ad_sigma_delta_info ad7192_sigma_delta_info = { - .set_channel = ad7192_set_channel, - .set_mode = ad7192_set_mode, - .has_registers = true, - .addr_shift = 3, - .read_mask = BIT(6), -}; - -static const struct ad_sd_calib_data ad7192_calib_arr[8] = { - {AD7192_MODE_CAL_INT_ZERO, AD7192_CH_AIN1}, - {AD7192_MODE_CAL_INT_FULL, AD7192_CH_AIN1}, - {AD7192_MODE_CAL_INT_ZERO, AD7192_CH_AIN2}, - {AD7192_MODE_CAL_INT_FULL, AD7192_CH_AIN2}, - {AD7192_MODE_CAL_INT_ZERO, AD7192_CH_AIN3}, - {AD7192_MODE_CAL_INT_FULL, AD7192_CH_AIN3}, - {AD7192_MODE_CAL_INT_ZERO, AD7192_CH_AIN4}, - {AD7192_MODE_CAL_INT_FULL, AD7192_CH_AIN4} -}; - -static int ad7192_calibrate_all(struct ad7192_state *st) -{ - return ad_sd_calibrate_all(&st->sd, ad7192_calib_arr, - ARRAY_SIZE(ad7192_calib_arr)); -} - -static inline bool ad7192_valid_external_frequency(u32 freq) -{ - return (freq >= AD7192_EXT_FREQ_MHZ_MIN && - freq <= AD7192_EXT_FREQ_MHZ_MAX); -} - -static int ad7192_of_clock_select(struct ad7192_state *st) -{ - struct device_node *np = st->sd.spi->dev.of_node; - unsigned int clock_sel; - - clock_sel = AD7192_CLK_INT; - - /* use internal clock */ - if (PTR_ERR(st->mclk) == -ENOENT) { - if (of_property_read_bool(np, "adi,int-clock-output-enable")) - clock_sel = AD7192_CLK_INT_CO; - } else { - if (of_property_read_bool(np, "adi,clock-xtal")) - clock_sel = AD7192_CLK_EXT_MCLK1_2; - else - clock_sel = AD7192_CLK_EXT_MCLK2; - } - - return clock_sel; -} - -static int ad7192_setup(struct ad7192_state *st, struct device_node *np) -{ - struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi); - bool rej60_en, refin2_en; - bool buf_en, bipolar, burnout_curr_en; - unsigned long long scale_uv; - int i, ret, id; - - /* reset the serial interface */ - ret = ad_sd_reset(&st->sd, 48); - if (ret < 0) - return ret; - usleep_range(500, 1000); /* Wait for at least 500us */ - - /* write/read test for device presence */ - ret = ad_sd_read_reg(&st->sd, AD7192_REG_ID, 1, &id); - if (ret) - return ret; - - id &= AD7192_ID_MASK; - - if (id != st->devid) - dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n", - id); - - st->mode = AD7192_MODE_SEL(AD7192_MODE_IDLE) | - AD7192_MODE_CLKSRC(st->clock_sel) | - AD7192_MODE_RATE(480); - - st->conf = AD7192_CONF_GAIN(0); - - rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable"); - if (rej60_en) - st->mode |= AD7192_MODE_REJ60; - - refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable"); - if (refin2_en && st->devid != ID_AD7195) - st->conf |= AD7192_CONF_REFSEL; - - st->conf &= ~AD7192_CONF_CHOP; - st->f_order = AD7192_NO_SYNC_FILTER; - - buf_en = of_property_read_bool(np, "adi,buffer-enable"); - if (buf_en) - st->conf |= AD7192_CONF_BUF; - - bipolar = of_property_read_bool(np, "bipolar"); - if (!bipolar) - st->conf |= AD7192_CONF_UNIPOLAR; - - burnout_curr_en = of_property_read_bool(np, - "adi,burnout-currents-enable"); - if (burnout_curr_en && buf_en) { - st->conf |= AD7192_CONF_BURN; - } else if (burnout_curr_en) { - dev_warn(&st->sd.spi->dev, - "Can't enable burnout currents: see CHOP or buffer\n"); - } - - ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); - if (ret) - return ret; - - ret = ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf); - if (ret) - return ret; - - ret = ad7192_calibrate_all(st); - if (ret) - return ret; - - /* Populate available ADC input ranges */ - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) { - scale_uv = ((u64)st->int_vref_mv * 100000000) - >> (indio_dev->channels[0].scan_type.realbits - - ((st->conf & AD7192_CONF_UNIPOLAR) ? 0 : 1)); - scale_uv >>= i; - - st->scale_avail[i][1] = do_div(scale_uv, 100000000) * 10; - st->scale_avail[i][0] = scale_uv; - } - - return 0; -} - -static ssize_t ad7192_show_ac_excitation(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7192_state *st = iio_priv(indio_dev); - - return sprintf(buf, "%d\n", !!(st->mode & AD7192_MODE_ACX)); -} - -static ssize_t ad7192_show_bridge_switch(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7192_state *st = iio_priv(indio_dev); - - return sprintf(buf, "%d\n", !!(st->gpocon & AD7192_GPOCON_BPDSW)); -} - -static ssize_t ad7192_set(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7192_state *st = iio_priv(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int ret; - bool val; - - ret = strtobool(buf, &val); - if (ret < 0) - return ret; - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - - switch ((u32)this_attr->address) { - case AD7192_REG_GPOCON: - if (val) - st->gpocon |= AD7192_GPOCON_BPDSW; - else - st->gpocon &= ~AD7192_GPOCON_BPDSW; - - ad_sd_write_reg(&st->sd, AD7192_REG_GPOCON, 1, st->gpocon); - break; - case AD7192_REG_MODE: - if (val) - st->mode |= AD7192_MODE_ACX; - else - st->mode &= ~AD7192_MODE_ACX; - - ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); - break; - default: - ret = -EINVAL; - } - - iio_device_release_direct_mode(indio_dev); - - return ret ? ret : len; -} - -static void ad7192_get_available_filter_freq(struct ad7192_state *st, - int *freq) -{ - unsigned int fadc; - - /* Formulas for filter at page 25 of the datasheet */ - fadc = DIV_ROUND_CLOSEST(st->fclk, - AD7192_SYNC4_FILTER * AD7192_MODE_RATE(st->mode)); - freq[0] = DIV_ROUND_CLOSEST(fadc * 240, 1024); - - fadc = DIV_ROUND_CLOSEST(st->fclk, - AD7192_SYNC3_FILTER * AD7192_MODE_RATE(st->mode)); - freq[1] = DIV_ROUND_CLOSEST(fadc * 240, 1024); - - fadc = DIV_ROUND_CLOSEST(st->fclk, AD7192_MODE_RATE(st->mode)); - freq[2] = DIV_ROUND_CLOSEST(fadc * 230, 1024); - freq[3] = DIV_ROUND_CLOSEST(fadc * 272, 1024); -} - -static ssize_t ad7192_show_filter_avail(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_to_iio_dev(dev); - struct ad7192_state *st = iio_priv(indio_dev); - unsigned int freq_avail[4], i; - size_t len = 0; - - ad7192_get_available_filter_freq(st, freq_avail); - - for (i = 0; i < ARRAY_SIZE(freq_avail); i++) - len += scnprintf(buf + len, PAGE_SIZE - len, - "%d.%d ", freq_avail[i] / 1000, - freq_avail[i] % 1000); - - buf[len - 1] = '\n'; - - return len; -} - -static IIO_DEVICE_ATTR(filter_low_pass_3db_frequency_available, - 0444, ad7192_show_filter_avail, NULL, 0); - -static IIO_DEVICE_ATTR(bridge_switch_en, 0644, - ad7192_show_bridge_switch, ad7192_set, - AD7192_REG_GPOCON); - -static IIO_DEVICE_ATTR(ac_excitation_en, 0644, - ad7192_show_ac_excitation, ad7192_set, - AD7192_REG_MODE); - -static struct attribute *ad7192_attributes[] = { - &iio_dev_attr_filter_low_pass_3db_frequency_available.dev_attr.attr, - &iio_dev_attr_bridge_switch_en.dev_attr.attr, - &iio_dev_attr_ac_excitation_en.dev_attr.attr, - NULL -}; - -static const struct attribute_group ad7192_attribute_group = { - .attrs = ad7192_attributes, -}; - -static struct attribute *ad7195_attributes[] = { - &iio_dev_attr_filter_low_pass_3db_frequency_available.dev_attr.attr, - &iio_dev_attr_bridge_switch_en.dev_attr.attr, - NULL -}; - -static const struct attribute_group ad7195_attribute_group = { - .attrs = ad7195_attributes, -}; - -static unsigned int ad7192_get_temp_scale(bool unipolar) -{ - return unipolar ? 2815 * 2 : 2815; -} - -static int ad7192_set_3db_filter_freq(struct ad7192_state *st, - int val, int val2) -{ - int freq_avail[4], i, ret, freq; - unsigned int diff_new, diff_old; - int idx = 0; - - diff_old = U32_MAX; - freq = val * 1000 + val2; - - ad7192_get_available_filter_freq(st, freq_avail); - - for (i = 0; i < ARRAY_SIZE(freq_avail); i++) { - diff_new = abs(freq - freq_avail[i]); - if (diff_new < diff_old) { - diff_old = diff_new; - idx = i; - } - } - - switch (idx) { - case 0: - st->f_order = AD7192_SYNC4_FILTER; - st->mode &= ~AD7192_MODE_SINC3; - - st->conf |= AD7192_CONF_CHOP; - break; - case 1: - st->f_order = AD7192_SYNC3_FILTER; - st->mode |= AD7192_MODE_SINC3; - - st->conf |= AD7192_CONF_CHOP; - break; - case 2: - st->f_order = AD7192_NO_SYNC_FILTER; - st->mode &= ~AD7192_MODE_SINC3; - - st->conf &= ~AD7192_CONF_CHOP; - break; - case 3: - st->f_order = AD7192_NO_SYNC_FILTER; - st->mode |= AD7192_MODE_SINC3; - - st->conf &= ~AD7192_CONF_CHOP; - break; - } - - ret = ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); - if (ret < 0) - return ret; - - return ad_sd_write_reg(&st->sd, AD7192_REG_CONF, 3, st->conf); -} - -static int ad7192_get_3db_filter_freq(struct ad7192_state *st) -{ - unsigned int fadc; - - fadc = DIV_ROUND_CLOSEST(st->fclk, - st->f_order * AD7192_MODE_RATE(st->mode)); - - if (st->conf & AD7192_CONF_CHOP) - return DIV_ROUND_CLOSEST(fadc * 240, 1024); - if (st->mode & AD7192_MODE_SINC3) - return DIV_ROUND_CLOSEST(fadc * 272, 1024); - else - return DIV_ROUND_CLOSEST(fadc * 230, 1024); -} - -static int ad7192_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, - int *val2, - long m) -{ - struct ad7192_state *st = iio_priv(indio_dev); - bool unipolar = !!(st->conf & AD7192_CONF_UNIPOLAR); - - switch (m) { - case IIO_CHAN_INFO_RAW: - return ad_sigma_delta_single_conversion(indio_dev, chan, val); - case IIO_CHAN_INFO_SCALE: - switch (chan->type) { - case IIO_VOLTAGE: - mutex_lock(&st->lock); - *val = st->scale_avail[AD7192_CONF_GAIN(st->conf)][0]; - *val2 = st->scale_avail[AD7192_CONF_GAIN(st->conf)][1]; - mutex_unlock(&st->lock); - return IIO_VAL_INT_PLUS_NANO; - case IIO_TEMP: - *val = 0; - *val2 = 1000000000 / ad7192_get_temp_scale(unipolar); - return IIO_VAL_INT_PLUS_NANO; - default: - return -EINVAL; - } - case IIO_CHAN_INFO_OFFSET: - if (!unipolar) - *val = -(1 << (chan->scan_type.realbits - 1)); - else - *val = 0; - /* Kelvin to Celsius */ - if (chan->type == IIO_TEMP) - *val -= 273 * ad7192_get_temp_scale(unipolar); - return IIO_VAL_INT; - case IIO_CHAN_INFO_SAMP_FREQ: - *val = st->fclk / - (st->f_order * 1024 * AD7192_MODE_RATE(st->mode)); - return IIO_VAL_INT; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - *val = ad7192_get_3db_filter_freq(st); - *val2 = 1000; - return IIO_VAL_FRACTIONAL; - } - - return -EINVAL; -} - -static int ad7192_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, - int val2, - long mask) -{ - struct ad7192_state *st = iio_priv(indio_dev); - int ret, i, div; - unsigned int tmp; - - ret = iio_device_claim_direct_mode(indio_dev); - if (ret) - return ret; - - switch (mask) { - case IIO_CHAN_INFO_SCALE: - ret = -EINVAL; - mutex_lock(&st->lock); - for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) - if (val2 == st->scale_avail[i][1]) { - ret = 0; - tmp = st->conf; - st->conf &= ~AD7192_CONF_GAIN(-1); - st->conf |= AD7192_CONF_GAIN(i); - if (tmp == st->conf) - break; - ad_sd_write_reg(&st->sd, AD7192_REG_CONF, - 3, st->conf); - ad7192_calibrate_all(st); - break; - } - mutex_unlock(&st->lock); - break; - case IIO_CHAN_INFO_SAMP_FREQ: - if (!val) { - ret = -EINVAL; - break; - } - - div = st->fclk / (val * st->f_order * 1024); - if (div < 1 || div > 1023) { - ret = -EINVAL; - break; - } - - st->mode &= ~AD7192_MODE_RATE(-1); - st->mode |= AD7192_MODE_RATE(div); - ad_sd_write_reg(&st->sd, AD7192_REG_MODE, 3, st->mode); - break; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - ret = ad7192_set_3db_filter_freq(st, val, val2 / 1000); - break; - default: - ret = -EINVAL; - } - - iio_device_release_direct_mode(indio_dev); - - return ret; -} - -static int ad7192_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) -{ - switch (mask) { - case IIO_CHAN_INFO_SCALE: - return IIO_VAL_INT_PLUS_NANO; - case IIO_CHAN_INFO_SAMP_FREQ: - return IIO_VAL_INT; - case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: - return IIO_VAL_INT_PLUS_MICRO; - default: - return -EINVAL; - } -} - -static int ad7192_read_avail(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - const int **vals, int *type, int *length, - long mask) -{ - struct ad7192_state *st = iio_priv(indio_dev); - - switch (mask) { - case IIO_CHAN_INFO_SCALE: - *vals = (int *)st->scale_avail; - *type = IIO_VAL_INT_PLUS_NANO; - /* Values are stored in a 2D matrix */ - *length = ARRAY_SIZE(st->scale_avail) * 2; - - return IIO_AVAIL_LIST; - } - - return -EINVAL; -} - -static const struct iio_info ad7192_info = { - .read_raw = ad7192_read_raw, - .write_raw = ad7192_write_raw, - .write_raw_get_fmt = ad7192_write_raw_get_fmt, - .read_avail = ad7192_read_avail, - .attrs = &ad7192_attribute_group, - .validate_trigger = ad_sd_validate_trigger, -}; - -static const struct iio_info ad7195_info = { - .read_raw = ad7192_read_raw, - .write_raw = ad7192_write_raw, - .write_raw_get_fmt = ad7192_write_raw_get_fmt, - .read_avail = ad7192_read_avail, - .attrs = &ad7195_attribute_group, - .validate_trigger = ad_sd_validate_trigger, -}; - -static const struct iio_chan_spec ad7192_channels[] = { - AD_SD_DIFF_CHANNEL(0, 1, 2, AD7192_CH_AIN1P_AIN2M, 24, 32, 0), - AD_SD_DIFF_CHANNEL(1, 3, 4, AD7192_CH_AIN3P_AIN4M, 24, 32, 0), - AD_SD_TEMP_CHANNEL(2, AD7192_CH_TEMP, 24, 32, 0), - AD_SD_SHORTED_CHANNEL(3, 2, AD7192_CH_AIN2P_AIN2M, 24, 32, 0), - AD_SD_CHANNEL(4, 1, AD7192_CH_AIN1, 24, 32, 0), - AD_SD_CHANNEL(5, 2, AD7192_CH_AIN2, 24, 32, 0), - AD_SD_CHANNEL(6, 3, AD7192_CH_AIN3, 24, 32, 0), - AD_SD_CHANNEL(7, 4, AD7192_CH_AIN4, 24, 32, 0), - IIO_CHAN_SOFT_TIMESTAMP(8), -}; - -static const struct iio_chan_spec ad7193_channels[] = { - AD_SD_DIFF_CHANNEL(0, 1, 2, AD7193_CH_AIN1P_AIN2M, 24, 32, 0), - AD_SD_DIFF_CHANNEL(1, 3, 4, AD7193_CH_AIN3P_AIN4M, 24, 32, 0), - AD_SD_DIFF_CHANNEL(2, 5, 6, AD7193_CH_AIN5P_AIN6M, 24, 32, 0), - AD_SD_DIFF_CHANNEL(3, 7, 8, AD7193_CH_AIN7P_AIN8M, 24, 32, 0), - AD_SD_TEMP_CHANNEL(4, AD7193_CH_TEMP, 24, 32, 0), - AD_SD_SHORTED_CHANNEL(5, 2, AD7193_CH_AIN2P_AIN2M, 24, 32, 0), - AD_SD_CHANNEL(6, 1, AD7193_CH_AIN1, 24, 32, 0), - AD_SD_CHANNEL(7, 2, AD7193_CH_AIN2, 24, 32, 0), - AD_SD_CHANNEL(8, 3, AD7193_CH_AIN3, 24, 32, 0), - AD_SD_CHANNEL(9, 4, AD7193_CH_AIN4, 24, 32, 0), - AD_SD_CHANNEL(10, 5, AD7193_CH_AIN5, 24, 32, 0), - AD_SD_CHANNEL(11, 6, AD7193_CH_AIN6, 24, 32, 0), - AD_SD_CHANNEL(12, 7, AD7193_CH_AIN7, 24, 32, 0), - AD_SD_CHANNEL(13, 8, AD7193_CH_AIN8, 24, 32, 0), - IIO_CHAN_SOFT_TIMESTAMP(14), -}; - -static int ad7192_channels_config(struct iio_dev *indio_dev) -{ - struct ad7192_state *st = iio_priv(indio_dev); - const struct iio_chan_spec *channels; - struct iio_chan_spec *chan; - int i; - - switch (st->devid) { - case ID_AD7193: - channels = ad7193_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7193_channels); - break; - default: - channels = ad7192_channels; - indio_dev->num_channels = ARRAY_SIZE(ad7192_channels); - break; - } - - chan = devm_kcalloc(indio_dev->dev.parent, indio_dev->num_channels, - sizeof(*chan), GFP_KERNEL); - if (!chan) - return -ENOMEM; - - indio_dev->channels = chan; - - for (i = 0; i < indio_dev->num_channels; i++) { - *chan = channels[i]; - chan->info_mask_shared_by_all |= - BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY); - if (chan->type != IIO_TEMP) { - chan->info_mask_shared_by_type_available |= - BIT(IIO_CHAN_INFO_SCALE); - chan->ext_info = ad7192_calibsys_ext_info; - } - chan++; - } - - return 0; -} - -static int ad7192_probe(struct spi_device *spi) -{ - struct ad7192_state *st; - struct iio_dev *indio_dev; - int ret, voltage_uv = 0; - - if (!spi->irq) { - dev_err(&spi->dev, "no IRQ?\n"); - return -ENODEV; - } - - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); - if (!indio_dev) - return -ENOMEM; - - st = iio_priv(indio_dev); - - mutex_init(&st->lock); - - st->avdd = devm_regulator_get(&spi->dev, "avdd"); - if (IS_ERR(st->avdd)) - return PTR_ERR(st->avdd); - - ret = regulator_enable(st->avdd); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); - return ret; - } - - st->dvdd = devm_regulator_get(&spi->dev, "dvdd"); - if (IS_ERR(st->dvdd)) { - ret = PTR_ERR(st->dvdd); - goto error_disable_avdd; - } - - ret = regulator_enable(st->dvdd); - if (ret) { - dev_err(&spi->dev, "Failed to enable specified DVdd supply\n"); - goto error_disable_avdd; - } - - voltage_uv = regulator_get_voltage(st->avdd); - - if (voltage_uv) - st->int_vref_mv = voltage_uv / 1000; - else - dev_err(&spi->dev, "Device tree error, reference voltage undefined\n"); - - spi_set_drvdata(spi, indio_dev); - st->devid = spi_get_device_id(spi)->driver_data; - indio_dev->dev.parent = &spi->dev; - indio_dev->name = spi_get_device_id(spi)->name; - indio_dev->modes = INDIO_DIRECT_MODE; - - ret = ad7192_channels_config(indio_dev); - if (ret < 0) - goto error_disable_dvdd; - - if (st->devid == ID_AD7195) - indio_dev->info = &ad7195_info; - else - indio_dev->info = &ad7192_info; - - ad_sd_init(&st->sd, indio_dev, spi, &ad7192_sigma_delta_info); - - ret = ad_sd_setup_buffer_and_trigger(indio_dev); - if (ret) - goto error_disable_dvdd; - - st->fclk = AD7192_INT_FREQ_MHZ; - - st->mclk = devm_clk_get(&st->sd.spi->dev, "mclk"); - if (IS_ERR(st->mclk) && PTR_ERR(st->mclk) != -ENOENT) { - ret = PTR_ERR(st->mclk); - goto error_remove_trigger; - } - - st->clock_sel = ad7192_of_clock_select(st); - - if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 || - st->clock_sel == AD7192_CLK_EXT_MCLK2) { - ret = clk_prepare_enable(st->mclk); - if (ret < 0) - goto error_remove_trigger; - - st->fclk = clk_get_rate(st->mclk); - if (!ad7192_valid_external_frequency(st->fclk)) { - ret = -EINVAL; - dev_err(&spi->dev, - "External clock frequency out of bounds\n"); - goto error_disable_clk; - } - } - - ret = ad7192_setup(st, spi->dev.of_node); - if (ret) - goto error_disable_clk; - - ret = iio_device_register(indio_dev); - if (ret < 0) - goto error_disable_clk; - return 0; - -error_disable_clk: - clk_disable_unprepare(st->mclk); -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_dvdd: - regulator_disable(st->dvdd); -error_disable_avdd: - regulator_disable(st->avdd); - - return ret; -} - -static int ad7192_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7192_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - clk_disable_unprepare(st->mclk); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - regulator_disable(st->dvdd); - regulator_disable(st->avdd); - - return 0; -} - -static const struct spi_device_id ad7192_id[] = { - {"ad7190", ID_AD7190}, - {"ad7192", ID_AD7192}, - {"ad7193", ID_AD7193}, - {"ad7195", ID_AD7195}, - {} -}; - -MODULE_DEVICE_TABLE(spi, ad7192_id); - -static const struct of_device_id ad7192_of_match[] = { - { .compatible = "adi,ad7190" }, - { .compatible = "adi,ad7192" }, - { .compatible = "adi,ad7193" }, - { .compatible = "adi,ad7195" }, - {} -}; - -MODULE_DEVICE_TABLE(of, ad7192_of_match); - -static struct spi_driver ad7192_driver = { - .driver = { - .name = "ad7192", - .of_match_table = ad7192_of_match, - }, - .probe = ad7192_probe, - .remove = ad7192_remove, - .id_table = ad7192_id, -}; -module_spi_driver(ad7192_driver); - -MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>"); -MODULE_DESCRIPTION("Analog Devices AD7190, AD7192, AD7193, AD7195 ADC"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 19a5f244dcae..bef6bd1295ea 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -824,6 +824,10 @@ out: return IRQ_HANDLED; } +/* Note: No need to fix checkpatch warning that reads: + * CHECK: spaces preferred around that '-' (ctx:VxV) + * The function argument is stringified and doesn't need a fix + */ static IIO_DEVICE_ATTR_NAMED(in_thresh_low_value, in_voltage-voltage_thresh_low_value, 0644, diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c index 93cf28febdf6..7b00d7069e21 100644 --- a/drivers/staging/kpc2000/kpc2000/core.c +++ b/drivers/staging/kpc2000/kpc2000/core.c @@ -110,10 +110,10 @@ static ssize_t cpld_reconfigure(struct device *dev, const char *buf, size_t count) { struct kp2000_device *pcard = dev_get_drvdata(dev); - long wr_val; + unsigned long wr_val; int rv; - rv = kstrtol(buf, 0, &wr_val); + rv = kstrtoul(buf, 0, &wr_val); if (rv < 0) return rv; if (wr_val > 7) diff --git a/drivers/staging/kpc2000/kpc2000_spi.c b/drivers/staging/kpc2000/kpc2000_spi.c index 1c360daa703d..44017d523da5 100644 --- a/drivers/staging/kpc2000/kpc2000_spi.c +++ b/drivers/staging/kpc2000/kpc2000_spi.c @@ -386,8 +386,8 @@ kp_spi_transfer_one_message(struct spi_master *master, struct spi_message *m) } } - if (transfer->delay_usecs) - udelay(transfer->delay_usecs); + if (transfer->delay.value) + ndelay(spi_delay_to_ns(&transfer->delay, transfer)); } /* de-assert chip select to end the sequence */ diff --git a/drivers/staging/kpc2000/kpc_dma/dma.c b/drivers/staging/kpc2000/kpc_dma/dma.c index 51a4dd534a0d..452a3f7c835d 100644 --- a/drivers/staging/kpc2000/kpc_dma/dma.c +++ b/drivers/staging/kpc2000/kpc_dma/dma.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +// SPDX-License-Identifier: GPL-2.0+ #include <linux/init.h> #include <linux/module.h> #include <linux/types.h> @@ -97,11 +97,10 @@ int setup_dma_engine(struct kpc_dma_device *eng, u32 desc_cnt) if (WARN(!(caps & ENG_CAP_PRESENT), "%s() called for DMA Engine at %p which isn't present in hardware!\n", __func__, eng)) return -ENXIO; - if (caps & ENG_CAP_DIRECTION) { + if (caps & ENG_CAP_DIRECTION) eng->dir = DMA_FROM_DEVICE; - } else { + else eng->dir = DMA_TO_DEVICE; - } eng->desc_pool_cnt = desc_cnt; eng->desc_pool = dma_pool_create("KPC DMA Descriptors", &eng->pldev->dev, sizeof(struct kpc_dma_descriptor), DMA_DESC_ALIGNMENT, 4096); @@ -236,7 +235,7 @@ int count_descriptors_available(struct kpc_dma_device *eng) struct kpc_dma_descriptor *cur = eng->desc_next; while (cur != eng->desc_completed) { - BUG_ON(cur == NULL); + BUG_ON(!cur); count++; cur = cur->Next; } diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c index 40525540dde6..7caabdd77bbf 100644 --- a/drivers/staging/kpc2000/kpc_dma/fileops.c +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +// SPDX-License-Identifier: GPL-2.0+ #include <linux/module.h> #include <linux/init.h> #include <linux/mm.h> @@ -18,8 +18,8 @@ static inline unsigned int count_pages(unsigned long iov_base, size_t iov_len) { - unsigned long first = (iov_base & PAGE_MASK) >> PAGE_SHIFT; - unsigned long last = ((iov_base+iov_len-1) & PAGE_MASK) >> PAGE_SHIFT; + unsigned long first = (iov_base & PAGE_MASK) >> PAGE_SHIFT; + unsigned long last = ((iov_base + iov_len - 1) & PAGE_MASK) >> PAGE_SHIFT; return last - first + 1; } @@ -66,7 +66,8 @@ static int kpc_dma_transfer(struct dev_private_data *priv, acd->page_count = count_pages(iov_base, iov_len); // Allocate an array of page pointers - acd->user_pages = kzalloc(sizeof(struct page *) * acd->page_count, GFP_KERNEL); + acd->user_pages = kcalloc(acd->page_count, sizeof(struct page *), + GFP_KERNEL); if (!acd->user_pages) { dev_err(&priv->ldev->pldev->dev, "Couldn't kmalloc space for for the page pointers\n"); rv = -ENOMEM; @@ -83,7 +84,7 @@ static int kpc_dma_transfer(struct dev_private_data *priv, } // Allocate and setup the sg_table (scatterlist entries) - rv = sg_alloc_table_from_pages(&acd->sgt, acd->user_pages, acd->page_count, iov_base & (PAGE_SIZE-1), iov_len, GFP_KERNEL); + rv = sg_alloc_table_from_pages(&acd->sgt, acd->user_pages, acd->page_count, iov_base & (PAGE_SIZE - 1), iov_len, GFP_KERNEL); if (rv) { dev_err(&priv->ldev->pldev->dev, "Couldn't alloc sg_table (%ld)\n", rv); goto err_alloc_sg_table; @@ -124,19 +125,19 @@ static int kpc_dma_transfer(struct dev_private_data *priv, pcnt = count_parts_for_sge(sg); for (p = 0 ; p < pcnt ; p++) { // Fill out the descriptor - BUG_ON(desc == NULL); + BUG_ON(!desc); clear_desc(desc); - if (p != pcnt-1) { + if (p != pcnt - 1) desc->DescByteCount = 0x80000; - } else { + else desc->DescByteCount = sg_dma_len(sg) - (p * 0x80000); - } + desc->DescBufferByteCount = desc->DescByteCount; desc->DescControlFlags |= DMA_DESC_CTL_IRQONERR; if (i == 0 && p == 0) desc->DescControlFlags |= DMA_DESC_CTL_SOP; - if (i == acd->mapped_entry_count-1 && p == pcnt-1) + if (i == acd->mapped_entry_count - 1 && p == pcnt - 1) desc->DescControlFlags |= DMA_DESC_CTL_EOP | DMA_DESC_CTL_IRQONDONE; desc->DescCardAddrLS = (card_addr & 0xFFFFFFFF); @@ -148,13 +149,13 @@ static int kpc_dma_transfer(struct dev_private_data *priv, desc->DescSystemAddrMS = (dma_addr & 0xFFFFFFFF00000000UL) >> 32; user_ctl = acd->priv->user_ctl; - if (i == acd->mapped_entry_count-1 && p == pcnt-1) { + if (i == acd->mapped_entry_count - 1 && p == pcnt - 1) user_ctl = acd->priv->user_ctl_last; - } + desc->DescUserControlLS = (user_ctl & 0x00000000FFFFFFFFUL) >> 0; desc->DescUserControlMS = (user_ctl & 0xFFFFFFFF00000000UL) >> 32; - if (i == acd->mapped_entry_count-1 && p == pcnt-1) + if (i == acd->mapped_entry_count - 1 && p == pcnt - 1) desc->acd = acd; dev_dbg(&priv->ldev->pldev->dev, " Filled descriptor %p (acd = %p)\n", desc, desc->acd); @@ -188,9 +189,9 @@ static int kpc_dma_transfer(struct dev_private_data *priv, sg_free_table(&acd->sgt); err_dma_map_sg: err_alloc_sg_table: - for (i = 0 ; i < acd->page_count ; i++) { + for (i = 0 ; i < acd->page_count ; i++) put_page(acd->user_pages[i]); - } + err_get_user_pages: kfree(acd->user_pages); err_alloc_userpages: @@ -203,23 +204,21 @@ void transfer_complete_cb(struct aio_cb_data *acd, size_t xfr_count, u32 flags) { unsigned int i; - BUG_ON(acd == NULL); - BUG_ON(acd->user_pages == NULL); - BUG_ON(acd->sgt.sgl == NULL); - BUG_ON(acd->ldev == NULL); - BUG_ON(acd->ldev->pldev == NULL); + BUG_ON(!acd); + BUG_ON(!acd->user_pages); + BUG_ON(!acd->sgt.sgl); + BUG_ON(!acd->ldev); + BUG_ON(!acd->ldev->pldev); for (i = 0 ; i < acd->page_count ; i++) { - if (!PageReserved(acd->user_pages[i])) { + if (!PageReserved(acd->user_pages[i])) set_page_dirty(acd->user_pages[i]); - } } dma_unmap_sg(&acd->ldev->pldev->dev, acd->sgt.sgl, acd->sgt.nents, acd->ldev->dir); - for (i = 0 ; i < acd->page_count ; i++) { + for (i = 0 ; i < acd->page_count ; i++) put_page(acd->user_pages[i]); - } sg_free_table(&acd->sgt); @@ -253,7 +252,7 @@ int kpc_dma_open(struct inode *inode, struct file *filp) return -EBUSY; /* already open */ } - priv = kzalloc(sizeof(struct dev_private_data), GFP_KERNEL); + priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.c b/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.c index ec79a8500caf..c3b30551e0ca 100644 --- a/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.c +++ b/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.c @@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ +// SPDX-License-Identifier: GPL-2.0+ #include <linux/init.h> #include <linux/module.h> #include <linux/types.h> -#include <asm/io.h> +#include <linux/io.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/platform_device.h> @@ -26,9 +26,8 @@ struct kpc_dma_device *kpc_dma_lookup_device(int minor) mutex_lock(&kpc_dma_mtx); list_for_each_entry(c, &kpc_dma_list, list) { - if (c->pldev->id == minor) { + if (c->pldev->id == minor) goto out; - } } c = NULL; // not-found case out: @@ -98,7 +97,7 @@ int kpc_dma_probe(struct platform_device *pldev) int rv = 0; dev_t dev; - struct kpc_dma_device *ldev = kzalloc(sizeof(struct kpc_dma_device), GFP_KERNEL); + struct kpc_dma_device *ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); if (!ldev) { dev_err(&pldev->dev, "%s: unable to kzalloc space for kpc_dma_device\n", __func__); diff --git a/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.h b/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.h index 4c8cc866b826..8b9c978257b9 100644 --- a/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.h +++ b/drivers/staging/kpc2000/kpc_dma/kpc_dma_driver.h @@ -198,14 +198,14 @@ u32 GetEngineCompletePtr(struct kpc_dma_device *eng) static inline void lock_engine(struct kpc_dma_device *eng) { - BUG_ON(eng == NULL); + BUG_ON(!eng); mutex_lock(&eng->sem); } static inline void unlock_engine(struct kpc_dma_device *eng) { - BUG_ON(eng == NULL); + BUG_ON(!eng); mutex_unlock(&eng->sem); } diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c index 4b379542ecd5..6b2660c94f4e 100644 --- a/drivers/staging/ks7010/ks7010_sdio.c +++ b/drivers/staging/ks7010/ks7010_sdio.c @@ -446,7 +446,8 @@ static void ks_wlan_hw_rx(struct ks_wlan_private *priv, size_t size) DUMP_PREFIX_OFFSET, rx_buffer->data, 32); #endif - ret = ks7010_sdio_writeb(priv, READ_STATUS_REG, REG_STATUS_IDLE); + ret = ks7010_sdio_writeb(priv, READ_STATUS_REG, + REG_STATUS_IDLE); if (ret) netdev_err(priv->net_dev, "write READ_STATUS_REG\n"); diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h index ca7dc8f5166c..39138191a556 100644 --- a/drivers/staging/ks7010/ks_hostif.h +++ b/drivers/staging/ks7010/ks_hostif.h @@ -70,7 +70,7 @@ struct hostif_data_request { #define TYPE_DATA 0x0000 #define TYPE_AUTH 0x0001 __le16 reserved; - u8 data[0]; + u8 data[]; } __packed; #define TYPE_PMK1 0x0001 @@ -194,7 +194,7 @@ enum mib_data_type { struct hostif_mib_value { __le16 size; __le16 type; - u8 body[0]; + u8 body[]; } __packed; struct hostif_mib_get_confirm_t { diff --git a/drivers/staging/media/allegro-dvt/allegro-core.c b/drivers/staging/media/allegro-dvt/allegro-core.c index 34c3e55be902..70f133a842dd 100644 --- a/drivers/staging/media/allegro-dvt/allegro-core.c +++ b/drivers/staging/media/allegro-dvt/allegro-core.c @@ -2403,10 +2403,10 @@ static int allegro_open(struct file *file) 0, ALLEGRO_GOP_SIZE_MAX, 1, channel->gop_size); v4l2_ctrl_new_std(handler, - &allegro_ctrl_ops, - V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, - 1, 32, - 1, 1); + &allegro_ctrl_ops, + V4L2_CID_MIN_BUFFERS_FOR_OUTPUT, + 1, 32, + 1, 1); if (handler->error != 0) { ret = handler->error; goto error; @@ -3083,8 +3083,8 @@ static int allegro_probe(struct platform_device *pdev) return -EINVAL; } sram_regs = devm_ioremap(&pdev->dev, - sram_res->start, - resource_size(sram_res)); + sram_res->start, + resource_size(sram_res)); if (IS_ERR(sram_regs)) { dev_err(&pdev->dev, "failed to map sram\n"); return PTR_ERR(sram_regs); diff --git a/drivers/staging/media/allegro-dvt/allegro-mail.h b/drivers/staging/media/allegro-dvt/allegro-mail.h index 1fd36f65be78..17db665f8e1e 100644 --- a/drivers/staging/media/allegro-dvt/allegro-mail.h +++ b/drivers/staging/media/allegro-dvt/allegro-mail.h @@ -169,7 +169,7 @@ struct mcu_msg_push_buffers_internal_buffer { struct mcu_msg_push_buffers_internal { struct mcu_msg_header header; u32 channel_id; - struct mcu_msg_push_buffers_internal_buffer buffer[0]; + struct mcu_msg_push_buffers_internal_buffer buffer[]; } __attribute__ ((__packed__)); struct mcu_msg_put_stream_buffer { diff --git a/drivers/staging/media/hantro/hantro_postproc.c b/drivers/staging/media/hantro/hantro_postproc.c index 28a85d301d7f..44062ffceaea 100644 --- a/drivers/staging/media/hantro/hantro_postproc.c +++ b/drivers/staging/media/hantro/hantro_postproc.c @@ -14,16 +14,16 @@ #define HANTRO_PP_REG_WRITE(vpu, reg_name, val) \ { \ - hantro_reg_write((vpu), \ - &((vpu)->variant->postproc_regs->reg_name), \ - (val)); \ + hantro_reg_write(vpu, \ + &(vpu)->variant->postproc_regs->reg_name, \ + val); \ } #define HANTRO_PP_REG_WRITE_S(vpu, reg_name, val) \ { \ - hantro_reg_write_s((vpu), \ - &((vpu)->variant->postproc_regs->reg_name), \ - (val)); \ + hantro_reg_write_s(vpu, \ + &(vpu)->variant->postproc_regs->reg_name, \ + val); \ } #define VPU_PP_IN_YUYV 0x0 diff --git a/drivers/staging/media/imx/imx6-mipi-csi2.c b/drivers/staging/media/imx/imx6-mipi-csi2.c index cd3dd6e33ef0..8ab823042c09 100644 --- a/drivers/staging/media/imx/imx6-mipi-csi2.c +++ b/drivers/staging/media/imx/imx6-mipi-csi2.c @@ -592,22 +592,19 @@ static int csi2_probe(struct platform_device *pdev) csi2->pllref_clk = devm_clk_get(&pdev->dev, "ref"); if (IS_ERR(csi2->pllref_clk)) { v4l2_err(&csi2->sd, "failed to get pll reference clock\n"); - ret = PTR_ERR(csi2->pllref_clk); - return ret; + return PTR_ERR(csi2->pllref_clk); } csi2->dphy_clk = devm_clk_get(&pdev->dev, "dphy"); if (IS_ERR(csi2->dphy_clk)) { v4l2_err(&csi2->sd, "failed to get dphy clock\n"); - ret = PTR_ERR(csi2->dphy_clk); - return ret; + return PTR_ERR(csi2->dphy_clk); } csi2->pix_clk = devm_clk_get(&pdev->dev, "pix"); if (IS_ERR(csi2->pix_clk)) { v4l2_err(&csi2->sd, "failed to get pixel clock\n"); - ret = PTR_ERR(csi2->pix_clk); - return ret; + return PTR_ERR(csi2->pix_clk); } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c index de17a1d22873..fbc1a924652a 100644 --- a/drivers/staging/media/imx/imx7-mipi-csis.c +++ b/drivers/staging/media/imx/imx7-mipi-csis.c @@ -417,7 +417,7 @@ static void mipi_csis_set_hsync_settle(struct csi_state *state, int hs_settle) { u32 val = mipi_csis_read(state, MIPI_CSIS_DPHYCTRL); - val = ((val & ~MIPI_CSIS_DPHYCTRL_HSS_MASK) | (hs_settle << 24)); + val = (val & ~MIPI_CSIS_DPHYCTRL_HSS_MASK) | (hs_settle << 24); mipi_csis_write(state, MIPI_CSIS_DPHYCTRL, val); } diff --git a/drivers/staging/most/Documentation/ABI/configfs-most.txt b/drivers/staging/most/Documentation/ABI/configfs-most.txt deleted file mode 100644 index 2bf811449b0b..000000000000 --- a/drivers/staging/most/Documentation/ABI/configfs-most.txt +++ /dev/null @@ -1,204 +0,0 @@ -What: /sys/kernel/config/most_<component> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: Interface is used to configure and connect device channels - to component drivers. - - Attributes are visible only when configfs is mounted. To mount - configfs in /sys/kernel/config directory use: - # mount -t configfs none /sys/kernel/config/ - - -What: /sys/kernel/config/most_cdev/<link> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: - The attributes: - - buffer_size configure the buffer size for this channel - - subbuffer_size configure the sub-buffer size for this channel - (needed for synchronous and isochrnous data) - - - num_buffers configure number of buffers used for this - channel - - datatype configure type of data that will travel over - this channel - - direction configure whether this link will be an input - or output - - dbr_size configure DBR data buffer size (this is used - for MediaLB communication only) - - packets_per_xact - configure the number of packets that will be - collected from the network before being - transmitted via USB (this is used for USB - communication only) - - device name of the device the link is to be attached to - - channel name of the channel the link is to be attached to - - comp_params pass parameters needed by some components - - create_link write '1' to this attribute to trigger the - creation of the link. In case of speculative - configuration, the creation is post-poned until - a physical device is being attached to the bus. - - destroy_link write '1' to this attribute to destroy an - active link - -What: /sys/kernel/config/most_video/<link> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: - The attributes: - - buffer_size configure the buffer size for this channel - - subbuffer_size configure the sub-buffer size for this channel - (needed for synchronous and isochrnous data) - - - num_buffers configure number of buffers used for this - channel - - datatype configure type of data that will travel over - this channel - - direction configure whether this link will be an input - or output - - dbr_size configure DBR data buffer size (this is used - for MediaLB communication only) - - packets_per_xact - configure the number of packets that will be - collected from the network before being - transmitted via USB (this is used for USB - communication only) - - device name of the device the link is to be attached to - - channel name of the channel the link is to be attached to - - comp_params pass parameters needed by some components - - create_link write '1' to this attribute to trigger the - creation of the link. In case of speculative - configuration, the creation is post-poned until - a physical device is being attached to the bus. - - destroy_link write '1' to this attribute to destroy an - active link - -What: /sys/kernel/config/most_net/<link> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: - The attributes: - - buffer_size configure the buffer size for this channel - - subbuffer_size configure the sub-buffer size for this channel - (needed for synchronous and isochrnous data) - - - num_buffers configure number of buffers used for this - channel - - datatype configure type of data that will travel over - this channel - - direction configure whether this link will be an input - or output - - dbr_size configure DBR data buffer size (this is used - for MediaLB communication only) - - packets_per_xact - configure the number of packets that will be - collected from the network before being - transmitted via USB (this is used for USB - communication only) - - device name of the device the link is to be attached to - - channel name of the channel the link is to be attached to - - comp_params pass parameters needed by some components - - create_link write '1' to this attribute to trigger the - creation of the link. In case of speculative - configuration, the creation is post-poned until - a physical device is being attached to the bus. - - destroy_link write '1' to this attribute to destroy an - active link - -What: /sys/kernel/config/most_sound/<card> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: - The attributes: - - create_card write '1' to this attribute to trigger the - registration of the sound card with the ALSA - subsystem. - -What: /sys/kernel/config/most_sound/<card>/<link> -Date: March 8, 2019 -KernelVersion: 5.2 -Description: - The attributes: - - buffer_size configure the buffer size for this channel - - subbuffer_size configure the sub-buffer size for this channel - (needed for synchronous and isochrnous data) - - - num_buffers configure number of buffers used for this - channel - - datatype configure type of data that will travel over - this channel - - direction configure whether this link will be an input - or output - - dbr_size configure DBR data buffer size (this is used - for MediaLB communication only) - - packets_per_xact - configure the number of packets that will be - collected from the network before being - transmitted via USB (this is used for USB - communication only) - - device name of the device the link is to be attached to - - channel name of the channel the link is to be attached to - - comp_params pass parameters needed by some components - - create_link write '1' to this attribute to trigger the - creation of the link. In case of speculative - configuration, the creation is post-poned until - a physical device is being attached to the bus. - - destroy_link write '1' to this attribute to destroy an - active link - -What: /sys/kernel/config/rdma_cm/<hca>/ports/<port-num>/default_roce_tos -Date: March 8, 2019 -KernelVersion: 5.2 -Description: RDMA-CM QPs from HCA <hca> at port <port-num> - will be created with this TOS as default. - This can be overridden by using the rdma_set_option API. - The possible RoCE TOS values are 0-255. diff --git a/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt b/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt deleted file mode 100644 index d8fa841e3742..000000000000 --- a/drivers/staging/most/Documentation/ABI/sysfs-bus-most.txt +++ /dev/null @@ -1,313 +0,0 @@ -What: /sys/bus/most/devices/.../description -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Provides information about the interface type and the physical - location of the device. Hardware attached via USB, for instance, - might return <usb_device 1-1.1:1.0> -Users: - -What: /sys/bus/most/devices/.../interface -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the type of peripheral interface the device uses. -Users: - -What: /sys/bus/most/devices/.../dci -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - If the network interface controller is attached via USB, a dci - directory is created that allows applications to read and - write the controller's DCI registers. -Users: - -What: /sys/bus/most/devices/.../dci/arb_address -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to set an arbitrary DCI register address an - application wants to read from or write to. -Users: - -What: /sys/bus/most/devices/.../dci/arb_value -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to read and write the DCI register whose address - is stored in arb_address. -Users: - -What: /sys/bus/most/devices/.../dci/mep_eui48_hi -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MAC address. -Users: - -What: /sys/bus/most/devices/.../dci/mep_eui48_lo -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MAC address. -Users: - -What: /sys/bus/most/devices/.../dci/mep_eui48_mi -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MAC address. -Users: - -What: /sys/bus/most/devices/.../dci/mep_filter -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MEP filter address. -Users: - -What: /sys/bus/most/devices/.../dci/mep_hash0 -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MEP hash table. -Users: - -What: /sys/bus/most/devices/.../dci/mep_hash1 -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MEP hash table. -Users: - -What: /sys/bus/most/devices/.../dci/mep_hash2 -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MEP hash table. -Users: - -What: /sys/bus/most/devices/.../dci/mep_hash3 -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to check and configure the MEP hash table. -Users: - -What: /sys/bus/most/devices/.../dci/ni_state -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the current network interface state. -Users: - -What: /sys/bus/most/devices/.../dci/node_address -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the current node address. -Users: - -What: /sys/bus/most/devices/.../dci/node_position -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the current node position. -Users: - -What: /sys/bus/most/devices/.../dci/packet_bandwidth -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the configured packet bandwidth. -Users: - -What: /sys/bus/most/devices/.../dci/sync_ep -Date: June 2016 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Triggers the controller's synchronization process for a certain - endpoint. -Users: - -What: /sys/bus/most/devices/.../<channel>/ -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - For every channel of the device a directory is created, whose - name is dictated by the HDM. This enables an application to - collect information about the channel's capabilities and - configure it. -Users: - -What: /sys/bus/most/devices/.../<channel>/available_datatypes -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the data types the current channel can transport. -Users: - -What: /sys/bus/most/devices/.../<channel>/available_directions -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the directions the current channel is capable of. -Users: - -What: /sys/bus/most/devices/.../<channel>/number_of_packet_buffers -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the number of packet buffers the current channel can - handle. -Users: - -What: /sys/bus/most/devices/.../<channel>/number_of_stream_buffers -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the number of streaming buffers the current channel can - handle. -Users: - -What: /sys/bus/most/devices/.../<channel>/size_of_packet_buffer -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the size of a packet buffer the current channel can - handle. -Users: - -What: /sys/bus/most/devices/.../<channel>/size_of_stream_buffer -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates the size of a streaming buffer the current channel can - handle. -Users: - -What: /sys/bus/most/devices/.../<channel>/set_number_of_buffers -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the number of buffers of the current channel. -Users: - -What: /sys/bus/most/devices/.../<channel>/set_buffer_size -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the size of a buffer of the current channel. -Users: - -What: /sys/bus/most/devices/.../<channel>/set_direction -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the direction of the current channel. - The following strings will be accepted: - 'dir_tx', - 'dir_rx' -Users: - -What: /sys/bus/most/devices/.../<channel>/set_datatype -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the data type of the current channel. - The following strings will be accepted: - 'control', - 'async', - 'sync', - 'isoc_avp' -Users: - -What: /sys/bus/most/devices/.../<channel>/set_subbuffer_size -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the subbuffer size of the current channel. -Users: - -What: /sys/bus/most/devices/.../<channel>/set_packets_per_xact -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is to configure the number of packets per transaction of - the current channel. This is only needed network interface - controller is attached via USB. -Users: - -What: /sys/bus/most/devices/.../<channel>/channel_starving -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - Indicates whether current channel ran out of buffers. -Users: - -What: /sys/bus/most/drivers/mostcore/add_link -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to link a channel to a component of the - mostcore. A link created by writing to this file is - referred to as pipe. -Users: - -What: /sys/bus/most/drivers/mostcore/remove_link -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to unlink a channel from a component. -Users: - -What: /sys/bus/most/drivers/mostcore/components -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to retrieve a list of registered components. -Users: - -What: /sys/bus/most/drivers/mostcore/links -Date: March 2017 -KernelVersion: 4.15 -Contact: Christian Gromm <christian.gromm@microchip.com> -Description: - This is used to retrieve a list of established links. -Users: diff --git a/drivers/staging/most/Kconfig b/drivers/staging/most/Kconfig index 6262eb25c80b..c5a99f750abe 100644 --- a/drivers/staging/most/Kconfig +++ b/drivers/staging/most/Kconfig @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 -menuconfig MOST +menuconfig MOST_COMPONENTS tristate "MOST support" - depends on HAS_DMA && CONFIGFS_FS + depends on HAS_DMA && CONFIGFS_FS && MOST default n help Say Y here if you want to enable MOST support. @@ -16,7 +16,7 @@ menuconfig MOST -if MOST +if MOST_COMPONENTS source "drivers/staging/most/cdev/Kconfig" diff --git a/drivers/staging/most/Makefile b/drivers/staging/most/Makefile index 20a99ecb37c4..a803a98654a8 100644 --- a/drivers/staging/most/Makefile +++ b/drivers/staging/most/Makefile @@ -1,7 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_MOST) += most_core.o -most_core-y := core.o -most_core-y += configfs.o obj-$(CONFIG_MOST_CDEV) += cdev/ obj-$(CONFIG_MOST_NET) += net/ diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c index 71943d17f825..cc1e3dea196d 100644 --- a/drivers/staging/most/cdev/cdev.c +++ b/drivers/staging/most/cdev/cdev.c @@ -16,8 +16,7 @@ #include <linux/kfifo.h> #include <linux/uaccess.h> #include <linux/idr.h> - -#include "../most.h" +#include <linux/most.h> #define CHRDEV_REGION_SIZE 50 diff --git a/drivers/staging/most/configfs.c b/drivers/staging/most/configfs.c deleted file mode 100644 index 9a961222f458..000000000000 --- a/drivers/staging/most/configfs.c +++ /dev/null @@ -1,725 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * configfs.c - Implementation of configfs interface to the driver stack - * - * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/init.h> -#include <linux/configfs.h> - -#include "most.h" - -#define MAX_STRING_SIZE 80 - -struct mdev_link { - struct config_item item; - struct list_head list; - bool create_link; - bool destroy_link; - u16 num_buffers; - u16 buffer_size; - u16 subbuffer_size; - u16 packets_per_xact; - u16 dbr_size; - char datatype[MAX_STRING_SIZE]; - char direction[MAX_STRING_SIZE]; - char name[MAX_STRING_SIZE]; - char device[MAX_STRING_SIZE]; - char channel[MAX_STRING_SIZE]; - char comp[MAX_STRING_SIZE]; - char comp_params[MAX_STRING_SIZE]; -}; - -static struct list_head mdev_link_list; - -static int set_cfg_buffer_size(struct mdev_link *link) -{ - return most_set_cfg_buffer_size(link->device, link->channel, - link->buffer_size); -} - -static int set_cfg_subbuffer_size(struct mdev_link *link) -{ - return most_set_cfg_subbuffer_size(link->device, link->channel, - link->subbuffer_size); -} - -static int set_cfg_dbr_size(struct mdev_link *link) -{ - return most_set_cfg_dbr_size(link->device, link->channel, - link->dbr_size); -} - -static int set_cfg_num_buffers(struct mdev_link *link) -{ - return most_set_cfg_num_buffers(link->device, link->channel, - link->num_buffers); -} - -static int set_cfg_packets_xact(struct mdev_link *link) -{ - return most_set_cfg_packets_xact(link->device, link->channel, - link->packets_per_xact); -} - -static int set_cfg_direction(struct mdev_link *link) -{ - return most_set_cfg_direction(link->device, link->channel, - link->direction); -} - -static int set_cfg_datatype(struct mdev_link *link) -{ - return most_set_cfg_datatype(link->device, link->channel, - link->datatype); -} - -static int (*set_config_val[])(struct mdev_link *link) = { - set_cfg_buffer_size, - set_cfg_subbuffer_size, - set_cfg_dbr_size, - set_cfg_num_buffers, - set_cfg_packets_xact, - set_cfg_direction, - set_cfg_datatype, -}; - -static struct mdev_link *to_mdev_link(struct config_item *item) -{ - return container_of(item, struct mdev_link, item); -} - -static int set_config_and_add_link(struct mdev_link *mdev_link) -{ - int i; - int ret; - - for (i = 0; i < ARRAY_SIZE(set_config_val); i++) { - ret = set_config_val[i](mdev_link); - if (ret < 0 && ret != -ENODEV) { - pr_err("Config failed\n"); - return ret; - } - } - - return most_add_link(mdev_link->device, mdev_link->channel, - mdev_link->comp, mdev_link->name, - mdev_link->comp_params); -} - -static ssize_t mdev_link_create_link_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - bool tmp; - int ret; - - ret = kstrtobool(page, &tmp); - if (ret) - return ret; - if (!tmp) - return count; - ret = set_config_and_add_link(mdev_link); - if (ret && ret != -ENODEV) - return ret; - list_add_tail(&mdev_link->list, &mdev_link_list); - mdev_link->create_link = tmp; - mdev_link->destroy_link = false; - - return count; -} - -static ssize_t mdev_link_destroy_link_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - bool tmp; - int ret; - - ret = kstrtobool(page, &tmp); - if (ret) - return ret; - if (!tmp) - return count; - - ret = most_remove_link(mdev_link->device, mdev_link->channel, - mdev_link->comp); - if (ret) - return ret; - if (!list_empty(&mdev_link_list)) - list_del(&mdev_link->list); - - mdev_link->destroy_link = tmp; - - return count; -} - -static ssize_t mdev_link_direction_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->direction); -} - -static ssize_t mdev_link_direction_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - if (!sysfs_streq(page, "dir_rx") && !sysfs_streq(page, "rx") && - !sysfs_streq(page, "dir_tx") && !sysfs_streq(page, "tx")) - return -EINVAL; - strcpy(mdev_link->direction, page); - strim(mdev_link->direction); - return count; -} - -static ssize_t mdev_link_datatype_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->datatype); -} - -static ssize_t mdev_link_datatype_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - if (!sysfs_streq(page, "control") && !sysfs_streq(page, "async") && - !sysfs_streq(page, "sync") && !sysfs_streq(page, "isoc") && - !sysfs_streq(page, "isoc_avp")) - return -EINVAL; - strcpy(mdev_link->datatype, page); - strim(mdev_link->datatype); - return count; -} - -static ssize_t mdev_link_device_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->device); -} - -static ssize_t mdev_link_device_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - strlcpy(mdev_link->device, page, sizeof(mdev_link->device)); - strim(mdev_link->device); - return count; -} - -static ssize_t mdev_link_channel_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->channel); -} - -static ssize_t mdev_link_channel_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - strlcpy(mdev_link->channel, page, sizeof(mdev_link->channel)); - strim(mdev_link->channel); - return count; -} - -static ssize_t mdev_link_comp_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->comp); -} - -static ssize_t mdev_link_comp_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - strlcpy(mdev_link->comp, page, sizeof(mdev_link->comp)); - strim(mdev_link->comp); - return count; -} - -static ssize_t mdev_link_comp_params_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%s\n", - to_mdev_link(item)->comp_params); -} - -static ssize_t mdev_link_comp_params_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - - strlcpy(mdev_link->comp_params, page, sizeof(mdev_link->comp_params)); - strim(mdev_link->comp_params); - return count; -} - -static ssize_t mdev_link_num_buffers_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%d\n", - to_mdev_link(item)->num_buffers); -} - -static ssize_t mdev_link_num_buffers_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - ret = kstrtou16(page, 0, &mdev_link->num_buffers); - if (ret) - return ret; - return count; -} - -static ssize_t mdev_link_buffer_size_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%d\n", - to_mdev_link(item)->buffer_size); -} - -static ssize_t mdev_link_buffer_size_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - ret = kstrtou16(page, 0, &mdev_link->buffer_size); - if (ret) - return ret; - return count; -} - -static ssize_t mdev_link_subbuffer_size_show(struct config_item *item, - char *page) -{ - return snprintf(page, PAGE_SIZE, "%d\n", - to_mdev_link(item)->subbuffer_size); -} - -static ssize_t mdev_link_subbuffer_size_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - ret = kstrtou16(page, 0, &mdev_link->subbuffer_size); - if (ret) - return ret; - return count; -} - -static ssize_t mdev_link_packets_per_xact_show(struct config_item *item, - char *page) -{ - return snprintf(page, PAGE_SIZE, "%d\n", - to_mdev_link(item)->packets_per_xact); -} - -static ssize_t mdev_link_packets_per_xact_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - ret = kstrtou16(page, 0, &mdev_link->packets_per_xact); - if (ret) - return ret; - return count; -} - -static ssize_t mdev_link_dbr_size_show(struct config_item *item, char *page) -{ - return snprintf(page, PAGE_SIZE, "%d\n", to_mdev_link(item)->dbr_size); -} - -static ssize_t mdev_link_dbr_size_store(struct config_item *item, - const char *page, size_t count) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - ret = kstrtou16(page, 0, &mdev_link->dbr_size); - if (ret) - return ret; - return count; -} - -CONFIGFS_ATTR_WO(mdev_link_, create_link); -CONFIGFS_ATTR_WO(mdev_link_, destroy_link); -CONFIGFS_ATTR(mdev_link_, device); -CONFIGFS_ATTR(mdev_link_, channel); -CONFIGFS_ATTR(mdev_link_, comp); -CONFIGFS_ATTR(mdev_link_, comp_params); -CONFIGFS_ATTR(mdev_link_, num_buffers); -CONFIGFS_ATTR(mdev_link_, buffer_size); -CONFIGFS_ATTR(mdev_link_, subbuffer_size); -CONFIGFS_ATTR(mdev_link_, packets_per_xact); -CONFIGFS_ATTR(mdev_link_, datatype); -CONFIGFS_ATTR(mdev_link_, direction); -CONFIGFS_ATTR(mdev_link_, dbr_size); - -static struct configfs_attribute *mdev_link_attrs[] = { - &mdev_link_attr_create_link, - &mdev_link_attr_destroy_link, - &mdev_link_attr_device, - &mdev_link_attr_channel, - &mdev_link_attr_comp, - &mdev_link_attr_comp_params, - &mdev_link_attr_num_buffers, - &mdev_link_attr_buffer_size, - &mdev_link_attr_subbuffer_size, - &mdev_link_attr_packets_per_xact, - &mdev_link_attr_datatype, - &mdev_link_attr_direction, - &mdev_link_attr_dbr_size, - NULL, -}; - -static void mdev_link_release(struct config_item *item) -{ - struct mdev_link *mdev_link = to_mdev_link(item); - int ret; - - if (mdev_link->destroy_link) - goto free_item; - - ret = most_remove_link(mdev_link->device, mdev_link->channel, - mdev_link->comp); - if (ret) { - pr_err("Removing link failed.\n"); - goto free_item; - } - - if (!list_empty(&mdev_link_list)) - list_del(&mdev_link->list); - -free_item: - kfree(to_mdev_link(item)); -} - -static struct configfs_item_operations mdev_link_item_ops = { - .release = mdev_link_release, -}; - -static const struct config_item_type mdev_link_type = { - .ct_item_ops = &mdev_link_item_ops, - .ct_attrs = mdev_link_attrs, - .ct_owner = THIS_MODULE, -}; - -struct most_common { - struct config_group group; - struct module *mod; - struct configfs_subsystem subsys; -}; - -static struct most_common *to_most_common(struct configfs_subsystem *subsys) -{ - return container_of(subsys, struct most_common, subsys); -} - -static struct config_item *most_common_make_item(struct config_group *group, - const char *name) -{ - struct mdev_link *mdev_link; - struct most_common *mc = to_most_common(group->cg_subsys); - - mdev_link = kzalloc(sizeof(*mdev_link), GFP_KERNEL); - if (!mdev_link) - return ERR_PTR(-ENOMEM); - - if (!try_module_get(mc->mod)) { - kfree(mdev_link); - return ERR_PTR(-ENOLCK); - } - config_item_init_type_name(&mdev_link->item, name, - &mdev_link_type); - - if (!strcmp(group->cg_item.ci_namebuf, "most_cdev")) - strcpy(mdev_link->comp, "cdev"); - else if (!strcmp(group->cg_item.ci_namebuf, "most_net")) - strcpy(mdev_link->comp, "net"); - else if (!strcmp(group->cg_item.ci_namebuf, "most_video")) - strcpy(mdev_link->comp, "video"); - strcpy(mdev_link->name, name); - return &mdev_link->item; -} - -static void most_common_release(struct config_item *item) -{ - struct config_group *group = to_config_group(item); - - kfree(to_most_common(group->cg_subsys)); -} - -static struct configfs_item_operations most_common_item_ops = { - .release = most_common_release, -}; - -static void most_common_disconnect(struct config_group *group, - struct config_item *item) -{ - struct most_common *mc = to_most_common(group->cg_subsys); - - module_put(mc->mod); -} - -static struct configfs_group_operations most_common_group_ops = { - .make_item = most_common_make_item, - .disconnect_notify = most_common_disconnect, -}; - -static const struct config_item_type most_common_type = { - .ct_item_ops = &most_common_item_ops, - .ct_group_ops = &most_common_group_ops, - .ct_owner = THIS_MODULE, -}; - -static struct most_common most_cdev = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "most_cdev", - .ci_type = &most_common_type, - }, - }, - }, -}; - -static struct most_common most_net = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "most_net", - .ci_type = &most_common_type, - }, - }, - }, -}; - -static struct most_common most_video = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "most_video", - .ci_type = &most_common_type, - }, - }, - }, -}; - -struct most_snd_grp { - struct config_group group; - bool create_card; - struct list_head list; -}; - -static struct most_snd_grp *to_most_snd_grp(struct config_item *item) -{ - return container_of(to_config_group(item), struct most_snd_grp, group); -} - -static struct config_item *most_snd_grp_make_item(struct config_group *group, - const char *name) -{ - struct mdev_link *mdev_link; - - mdev_link = kzalloc(sizeof(*mdev_link), GFP_KERNEL); - if (!mdev_link) - return ERR_PTR(-ENOMEM); - - config_item_init_type_name(&mdev_link->item, name, &mdev_link_type); - mdev_link->create_link = false; - strcpy(mdev_link->name, name); - strcpy(mdev_link->comp, "sound"); - return &mdev_link->item; -} - -static ssize_t most_snd_grp_create_card_store(struct config_item *item, - const char *page, size_t count) -{ - struct most_snd_grp *snd_grp = to_most_snd_grp(item); - int ret; - bool tmp; - - ret = kstrtobool(page, &tmp); - if (ret) - return ret; - if (tmp) { - ret = most_cfg_complete("sound"); - if (ret) - return ret; - } - snd_grp->create_card = tmp; - return count; -} - -CONFIGFS_ATTR_WO(most_snd_grp_, create_card); - -static struct configfs_attribute *most_snd_grp_attrs[] = { - &most_snd_grp_attr_create_card, - NULL, -}; - -static void most_snd_grp_release(struct config_item *item) -{ - struct most_snd_grp *group = to_most_snd_grp(item); - - list_del(&group->list); - kfree(group); -} - -static struct configfs_item_operations most_snd_grp_item_ops = { - .release = most_snd_grp_release, -}; - -static struct configfs_group_operations most_snd_grp_group_ops = { - .make_item = most_snd_grp_make_item, -}; - -static const struct config_item_type most_snd_grp_type = { - .ct_item_ops = &most_snd_grp_item_ops, - .ct_group_ops = &most_snd_grp_group_ops, - .ct_attrs = most_snd_grp_attrs, - .ct_owner = THIS_MODULE, -}; - -struct most_sound { - struct configfs_subsystem subsys; - struct list_head soundcard_list; - struct module *mod; -}; - -static struct config_group *most_sound_make_group(struct config_group *group, - const char *name) -{ - struct most_snd_grp *most; - struct most_sound *ms = container_of(group->cg_subsys, - struct most_sound, subsys); - - list_for_each_entry(most, &ms->soundcard_list, list) { - if (!most->create_card) { - pr_info("adapter configuration still in progress.\n"); - return ERR_PTR(-EPROTO); - } - } - if (!try_module_get(ms->mod)) - return ERR_PTR(-ENOLCK); - most = kzalloc(sizeof(*most), GFP_KERNEL); - if (!most) { - module_put(ms->mod); - return ERR_PTR(-ENOMEM); - } - config_group_init_type_name(&most->group, name, &most_snd_grp_type); - list_add_tail(&most->list, &ms->soundcard_list); - return &most->group; -} - -static void most_sound_disconnect(struct config_group *group, - struct config_item *item) -{ - struct most_sound *ms = container_of(group->cg_subsys, - struct most_sound, subsys); - module_put(ms->mod); -} - -static struct configfs_group_operations most_sound_group_ops = { - .make_group = most_sound_make_group, - .disconnect_notify = most_sound_disconnect, -}; - -static const struct config_item_type most_sound_type = { - .ct_group_ops = &most_sound_group_ops, - .ct_owner = THIS_MODULE, -}; - -static struct most_sound most_sound_subsys = { - .subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "most_sound", - .ci_type = &most_sound_type, - }, - }, - }, -}; - -int most_register_configfs_subsys(struct most_component *c) -{ - int ret; - - if (!strcmp(c->name, "cdev")) { - most_cdev.mod = c->mod; - ret = configfs_register_subsystem(&most_cdev.subsys); - } else if (!strcmp(c->name, "net")) { - most_net.mod = c->mod; - ret = configfs_register_subsystem(&most_net.subsys); - } else if (!strcmp(c->name, "video")) { - most_video.mod = c->mod; - ret = configfs_register_subsystem(&most_video.subsys); - } else if (!strcmp(c->name, "sound")) { - most_sound_subsys.mod = c->mod; - ret = configfs_register_subsystem(&most_sound_subsys.subsys); - } else { - return -ENODEV; - } - - if (ret) { - pr_err("Error %d while registering subsystem %s\n", - ret, c->name); - } - return ret; -} -EXPORT_SYMBOL_GPL(most_register_configfs_subsys); - -void most_interface_register_notify(const char *mdev) -{ - bool register_snd_card = false; - struct mdev_link *mdev_link; - - list_for_each_entry(mdev_link, &mdev_link_list, list) { - if (!strcmp(mdev_link->device, mdev)) { - set_config_and_add_link(mdev_link); - if (!strcmp(mdev_link->comp, "sound")) - register_snd_card = true; - } - } - if (register_snd_card) - most_cfg_complete("sound"); -} - -void most_deregister_configfs_subsys(struct most_component *c) -{ - if (!strcmp(c->name, "cdev")) - configfs_unregister_subsystem(&most_cdev.subsys); - else if (!strcmp(c->name, "net")) - configfs_unregister_subsystem(&most_net.subsys); - else if (!strcmp(c->name, "video")) - configfs_unregister_subsystem(&most_video.subsys); - else if (!strcmp(c->name, "sound")) - configfs_unregister_subsystem(&most_sound_subsys.subsys); -} -EXPORT_SYMBOL_GPL(most_deregister_configfs_subsys); - -int __init configfs_init(void) -{ - config_group_init(&most_cdev.subsys.su_group); - mutex_init(&most_cdev.subsys.su_mutex); - - config_group_init(&most_net.subsys.su_group); - mutex_init(&most_net.subsys.su_mutex); - - config_group_init(&most_video.subsys.su_group); - mutex_init(&most_video.subsys.su_mutex); - - config_group_init(&most_sound_subsys.subsys.su_group); - mutex_init(&most_sound_subsys.subsys.su_mutex); - - INIT_LIST_HEAD(&most_sound_subsys.soundcard_list); - INIT_LIST_HEAD(&mdev_link_list); - - return 0; -} diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c deleted file mode 100644 index 0c4ae6920d77..000000000000 --- a/drivers/staging/most/core.c +++ /dev/null @@ -1,1491 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * core.c - Implementation of core module of MOST Linux driver stack - * - * Copyright (C) 2013-2020 Microchip Technology Germany II GmbH & Co. KG - */ - -#include <linux/module.h> -#include <linux/fs.h> -#include <linux/slab.h> -#include <linux/init.h> -#include <linux/device.h> -#include <linux/list.h> -#include <linux/poll.h> -#include <linux/wait.h> -#include <linux/kobject.h> -#include <linux/mutex.h> -#include <linux/completion.h> -#include <linux/sysfs.h> -#include <linux/kthread.h> -#include <linux/dma-mapping.h> -#include <linux/idr.h> - -#include "most.h" - -#define MAX_CHANNELS 64 -#define STRING_SIZE 80 - -static struct ida mdev_id; -static int dummy_num_buffers; -static struct list_head comp_list; - -struct pipe { - struct most_component *comp; - int refs; - int num_buffers; -}; - -struct most_channel { - struct device dev; - struct completion cleanup; - atomic_t mbo_ref; - atomic_t mbo_nq_level; - u16 channel_id; - char name[STRING_SIZE]; - bool is_poisoned; - struct mutex start_mutex; /* channel activation synchronization */ - struct mutex nq_mutex; /* nq thread synchronization */ - int is_starving; - struct most_interface *iface; - struct most_channel_config cfg; - bool keep_mbo; - bool enqueue_halt; - struct list_head fifo; - spinlock_t fifo_lock; /* fifo access synchronization */ - struct list_head halt_fifo; - struct list_head list; - struct pipe pipe0; - struct pipe pipe1; - struct list_head trash_fifo; - struct task_struct *hdm_enqueue_task; - wait_queue_head_t hdm_fifo_wq; - -}; - -#define to_channel(d) container_of(d, struct most_channel, dev) - -struct interface_private { - int dev_id; - char name[STRING_SIZE]; - struct most_channel *channel[MAX_CHANNELS]; - struct list_head channel_list; -}; - -static const struct { - int most_ch_data_type; - const char *name; -} ch_data_type[] = { - { MOST_CH_CONTROL, "control" }, - { MOST_CH_ASYNC, "async" }, - { MOST_CH_SYNC, "sync" }, - { MOST_CH_ISOC, "isoc"}, - { MOST_CH_ISOC, "isoc_avp"}, -}; - -/** - * list_pop_mbo - retrieves the first MBO of the list and removes it - * @ptr: the list head to grab the MBO from. - */ -#define list_pop_mbo(ptr) \ -({ \ - struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \ - list_del(&_mbo->list); \ - _mbo; \ -}) - -/** - * most_free_mbo_coherent - free an MBO and its coherent buffer - * @mbo: most buffer - */ -static void most_free_mbo_coherent(struct mbo *mbo) -{ - struct most_channel *c = mbo->context; - u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len; - - if (c->iface->dma_free) - c->iface->dma_free(mbo, coherent_buf_size); - else - kfree(mbo->virt_address); - kfree(mbo); - if (atomic_sub_and_test(1, &c->mbo_ref)) - complete(&c->cleanup); -} - -/** - * flush_channel_fifos - clear the channel fifos - * @c: pointer to channel object - */ -static void flush_channel_fifos(struct most_channel *c) -{ - unsigned long flags, hf_flags; - struct mbo *mbo, *tmp; - - if (list_empty(&c->fifo) && list_empty(&c->halt_fifo)) - return; - - spin_lock_irqsave(&c->fifo_lock, flags); - list_for_each_entry_safe(mbo, tmp, &c->fifo, list) { - list_del(&mbo->list); - spin_unlock_irqrestore(&c->fifo_lock, flags); - most_free_mbo_coherent(mbo); - spin_lock_irqsave(&c->fifo_lock, flags); - } - spin_unlock_irqrestore(&c->fifo_lock, flags); - - spin_lock_irqsave(&c->fifo_lock, hf_flags); - list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) { - list_del(&mbo->list); - spin_unlock_irqrestore(&c->fifo_lock, hf_flags); - most_free_mbo_coherent(mbo); - spin_lock_irqsave(&c->fifo_lock, hf_flags); - } - spin_unlock_irqrestore(&c->fifo_lock, hf_flags); - - if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo)))) - dev_warn(&c->dev, "Channel or trash fifo not empty\n"); -} - -/** - * flush_trash_fifo - clear the trash fifo - * @c: pointer to channel object - */ -static int flush_trash_fifo(struct most_channel *c) -{ - struct mbo *mbo, *tmp; - unsigned long flags; - - spin_lock_irqsave(&c->fifo_lock, flags); - list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) { - list_del(&mbo->list); - spin_unlock_irqrestore(&c->fifo_lock, flags); - most_free_mbo_coherent(mbo); - spin_lock_irqsave(&c->fifo_lock, flags); - } - spin_unlock_irqrestore(&c->fifo_lock, flags); - return 0; -} - -static ssize_t available_directions_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - strcpy(buf, ""); - if (c->iface->channel_vector[i].direction & MOST_CH_RX) - strcat(buf, "rx "); - if (c->iface->channel_vector[i].direction & MOST_CH_TX) - strcat(buf, "tx "); - strcat(buf, "\n"); - return strlen(buf); -} - -static ssize_t available_datatypes_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - strcpy(buf, ""); - if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL) - strcat(buf, "control "); - if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC) - strcat(buf, "async "); - if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC) - strcat(buf, "sync "); - if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC) - strcat(buf, "isoc "); - strcat(buf, "\n"); - return strlen(buf); -} - -static ssize_t number_of_packet_buffers_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - return snprintf(buf, PAGE_SIZE, "%d\n", - c->iface->channel_vector[i].num_buffers_packet); -} - -static ssize_t number_of_stream_buffers_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - return snprintf(buf, PAGE_SIZE, "%d\n", - c->iface->channel_vector[i].num_buffers_streaming); -} - -static ssize_t size_of_packet_buffer_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - return snprintf(buf, PAGE_SIZE, "%d\n", - c->iface->channel_vector[i].buffer_size_packet); -} - -static ssize_t size_of_stream_buffer_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - unsigned int i = c->channel_id; - - return snprintf(buf, PAGE_SIZE, "%d\n", - c->iface->channel_vector[i].buffer_size_streaming); -} - -static ssize_t channel_starving_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving); -} - -static ssize_t set_number_of_buffers_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers); -} - -static ssize_t set_buffer_size_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size); -} - -static ssize_t set_direction_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - if (c->cfg.direction & MOST_CH_TX) - return snprintf(buf, PAGE_SIZE, "tx\n"); - else if (c->cfg.direction & MOST_CH_RX) - return snprintf(buf, PAGE_SIZE, "rx\n"); - return snprintf(buf, PAGE_SIZE, "unconfigured\n"); -} - -static ssize_t set_datatype_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int i; - struct most_channel *c = to_channel(dev); - - for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) { - if (c->cfg.data_type & ch_data_type[i].most_ch_data_type) - return snprintf(buf, PAGE_SIZE, "%s", - ch_data_type[i].name); - } - return snprintf(buf, PAGE_SIZE, "unconfigured\n"); -} - -static ssize_t set_subbuffer_size_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size); -} - -static ssize_t set_packets_per_xact_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact); -} - -static ssize_t set_dbr_size_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct most_channel *c = to_channel(dev); - - return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.dbr_size); -} - -#define to_dev_attr(a) container_of(a, struct device_attribute, attr) -static umode_t channel_attr_is_visible(struct kobject *kobj, - struct attribute *attr, int index) -{ - struct device_attribute *dev_attr = to_dev_attr(attr); - struct device *dev = kobj_to_dev(kobj); - struct most_channel *c = to_channel(dev); - - if (!strcmp(dev_attr->attr.name, "set_dbr_size") && - (c->iface->interface != ITYPE_MEDIALB_DIM2)) - return 0; - if (!strcmp(dev_attr->attr.name, "set_packets_per_xact") && - (c->iface->interface != ITYPE_USB)) - return 0; - - return attr->mode; -} - -#define DEV_ATTR(_name) (&dev_attr_##_name.attr) - -static DEVICE_ATTR_RO(available_directions); -static DEVICE_ATTR_RO(available_datatypes); -static DEVICE_ATTR_RO(number_of_packet_buffers); -static DEVICE_ATTR_RO(number_of_stream_buffers); -static DEVICE_ATTR_RO(size_of_stream_buffer); -static DEVICE_ATTR_RO(size_of_packet_buffer); -static DEVICE_ATTR_RO(channel_starving); -static DEVICE_ATTR_RO(set_buffer_size); -static DEVICE_ATTR_RO(set_number_of_buffers); -static DEVICE_ATTR_RO(set_direction); -static DEVICE_ATTR_RO(set_datatype); -static DEVICE_ATTR_RO(set_subbuffer_size); -static DEVICE_ATTR_RO(set_packets_per_xact); -static DEVICE_ATTR_RO(set_dbr_size); - -static struct attribute *channel_attrs[] = { - DEV_ATTR(available_directions), - DEV_ATTR(available_datatypes), - DEV_ATTR(number_of_packet_buffers), - DEV_ATTR(number_of_stream_buffers), - DEV_ATTR(size_of_stream_buffer), - DEV_ATTR(size_of_packet_buffer), - DEV_ATTR(channel_starving), - DEV_ATTR(set_buffer_size), - DEV_ATTR(set_number_of_buffers), - DEV_ATTR(set_direction), - DEV_ATTR(set_datatype), - DEV_ATTR(set_subbuffer_size), - DEV_ATTR(set_packets_per_xact), - DEV_ATTR(set_dbr_size), - NULL, -}; - -static struct attribute_group channel_attr_group = { - .attrs = channel_attrs, - .is_visible = channel_attr_is_visible, -}; - -static const struct attribute_group *channel_attr_groups[] = { - &channel_attr_group, - NULL, -}; - -static ssize_t description_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_interface *iface = dev_get_drvdata(dev); - - return snprintf(buf, PAGE_SIZE, "%s\n", iface->description); -} - -static ssize_t interface_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct most_interface *iface = dev_get_drvdata(dev); - - switch (iface->interface) { - case ITYPE_LOOPBACK: - return snprintf(buf, PAGE_SIZE, "loopback\n"); - case ITYPE_I2C: - return snprintf(buf, PAGE_SIZE, "i2c\n"); - case ITYPE_I2S: - return snprintf(buf, PAGE_SIZE, "i2s\n"); - case ITYPE_TSI: - return snprintf(buf, PAGE_SIZE, "tsi\n"); - case ITYPE_HBI: - return snprintf(buf, PAGE_SIZE, "hbi\n"); - case ITYPE_MEDIALB_DIM: - return snprintf(buf, PAGE_SIZE, "mlb_dim\n"); - case ITYPE_MEDIALB_DIM2: - return snprintf(buf, PAGE_SIZE, "mlb_dim2\n"); - case ITYPE_USB: - return snprintf(buf, PAGE_SIZE, "usb\n"); - case ITYPE_PCIE: - return snprintf(buf, PAGE_SIZE, "pcie\n"); - } - return snprintf(buf, PAGE_SIZE, "unknown\n"); -} - -static DEVICE_ATTR_RO(description); -static DEVICE_ATTR_RO(interface); - -static struct attribute *interface_attrs[] = { - DEV_ATTR(description), - DEV_ATTR(interface), - NULL, -}; - -static struct attribute_group interface_attr_group = { - .attrs = interface_attrs, -}; - -static const struct attribute_group *interface_attr_groups[] = { - &interface_attr_group, - NULL, -}; - -static struct most_component *match_component(char *name) -{ - struct most_component *comp; - - list_for_each_entry(comp, &comp_list, list) { - if (!strcmp(comp->name, name)) - return comp; - } - return NULL; -} - -struct show_links_data { - int offs; - char *buf; -}; - -static int print_links(struct device *dev, void *data) -{ - struct show_links_data *d = data; - int offs = d->offs; - char *buf = d->buf; - struct most_channel *c; - struct most_interface *iface = dev_get_drvdata(dev); - - list_for_each_entry(c, &iface->p->channel_list, list) { - if (c->pipe0.comp) { - offs += snprintf(buf + offs, - PAGE_SIZE - offs, - "%s:%s:%s\n", - c->pipe0.comp->name, - dev_name(iface->dev), - dev_name(&c->dev)); - } - if (c->pipe1.comp) { - offs += snprintf(buf + offs, - PAGE_SIZE - offs, - "%s:%s:%s\n", - c->pipe1.comp->name, - dev_name(iface->dev), - dev_name(&c->dev)); - } - } - d->offs = offs; - return 0; -} - -static int most_match(struct device *dev, struct device_driver *drv) -{ - if (!strcmp(dev_name(dev), "most")) - return 0; - else - return 1; -} - -static struct bus_type mostbus = { - .name = "most", - .match = most_match, -}; - -static ssize_t links_show(struct device_driver *drv, char *buf) -{ - struct show_links_data d = { .buf = buf }; - - bus_for_each_dev(&mostbus, NULL, &d, print_links); - return d.offs; -} - -static ssize_t components_show(struct device_driver *drv, char *buf) -{ - struct most_component *comp; - int offs = 0; - - list_for_each_entry(comp, &comp_list, list) { - offs += snprintf(buf + offs, PAGE_SIZE - offs, "%s\n", - comp->name); - } - return offs; -} - -/** - * get_channel - get pointer to channel - * @mdev: name of the device interface - * @mdev_ch: name of channel - */ -static struct most_channel *get_channel(char *mdev, char *mdev_ch) -{ - struct device *dev = NULL; - struct most_interface *iface; - struct most_channel *c, *tmp; - - dev = bus_find_device_by_name(&mostbus, NULL, mdev); - if (!dev) - return NULL; - put_device(dev); - iface = dev_get_drvdata(dev); - list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) { - if (!strcmp(dev_name(&c->dev), mdev_ch)) - return c; - } - return NULL; -} - -static -inline int link_channel_to_component(struct most_channel *c, - struct most_component *comp, - char *name, - char *comp_param) -{ - int ret; - struct most_component **comp_ptr; - - if (!c->pipe0.comp) - comp_ptr = &c->pipe0.comp; - else if (!c->pipe1.comp) - comp_ptr = &c->pipe1.comp; - else - return -ENOSPC; - - *comp_ptr = comp; - ret = comp->probe_channel(c->iface, c->channel_id, &c->cfg, name, - comp_param); - if (ret) { - *comp_ptr = NULL; - return ret; - } - return 0; -} - -int most_set_cfg_buffer_size(char *mdev, char *mdev_ch, u16 val) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - c->cfg.buffer_size = val; - return 0; -} - -int most_set_cfg_subbuffer_size(char *mdev, char *mdev_ch, u16 val) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - c->cfg.subbuffer_size = val; - return 0; -} - -int most_set_cfg_dbr_size(char *mdev, char *mdev_ch, u16 val) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - c->cfg.dbr_size = val; - return 0; -} - -int most_set_cfg_num_buffers(char *mdev, char *mdev_ch, u16 val) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - c->cfg.num_buffers = val; - return 0; -} - -int most_set_cfg_datatype(char *mdev, char *mdev_ch, char *buf) -{ - int i; - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) { - if (!strcmp(buf, ch_data_type[i].name)) { - c->cfg.data_type = ch_data_type[i].most_ch_data_type; - break; - } - } - - if (i == ARRAY_SIZE(ch_data_type)) - dev_warn(&c->dev, "Invalid attribute settings\n"); - return 0; -} - -int most_set_cfg_direction(char *mdev, char *mdev_ch, char *buf) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - if (!strcmp(buf, "dir_rx")) { - c->cfg.direction = MOST_CH_RX; - } else if (!strcmp(buf, "rx")) { - c->cfg.direction = MOST_CH_RX; - } else if (!strcmp(buf, "dir_tx")) { - c->cfg.direction = MOST_CH_TX; - } else if (!strcmp(buf, "tx")) { - c->cfg.direction = MOST_CH_TX; - } else { - dev_err(&c->dev, "Invalid direction\n"); - return -ENODATA; - } - return 0; -} - -int most_set_cfg_packets_xact(char *mdev, char *mdev_ch, u16 val) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - - if (!c) - return -ENODEV; - c->cfg.packets_per_xact = val; - return 0; -} - -int most_cfg_complete(char *comp_name) -{ - struct most_component *comp; - - comp = match_component(comp_name); - if (!comp) - return -ENODEV; - - return comp->cfg_complete(); -} - -int most_add_link(char *mdev, char *mdev_ch, char *comp_name, char *link_name, - char *comp_param) -{ - struct most_channel *c = get_channel(mdev, mdev_ch); - struct most_component *comp = match_component(comp_name); - - if (!c || !comp) - return -ENODEV; - - return link_channel_to_component(c, comp, link_name, comp_param); -} - -int most_remove_link(char *mdev, char *mdev_ch, char *comp_name) -{ - struct most_channel *c; - struct most_component *comp; - - comp = match_component(comp_name); - if (!comp) - return -ENODEV; - c = get_channel(mdev, mdev_ch); - if (!c) - return -ENODEV; - - if (comp->disconnect_channel(c->iface, c->channel_id)) - return -EIO; - if (c->pipe0.comp == comp) - c->pipe0.comp = NULL; - if (c->pipe1.comp == comp) - c->pipe1.comp = NULL; - return 0; -} - -#define DRV_ATTR(_name) (&driver_attr_##_name.attr) - -static DRIVER_ATTR_RO(links); -static DRIVER_ATTR_RO(components); - -static struct attribute *mc_attrs[] = { - DRV_ATTR(links), - DRV_ATTR(components), - NULL, -}; - -static struct attribute_group mc_attr_group = { - .attrs = mc_attrs, -}; - -static const struct attribute_group *mc_attr_groups[] = { - &mc_attr_group, - NULL, -}; - -static struct device_driver mostbus_driver = { - .name = "most_core", - .bus = &mostbus, - .groups = mc_attr_groups, -}; - -static inline void trash_mbo(struct mbo *mbo) -{ - unsigned long flags; - struct most_channel *c = mbo->context; - - spin_lock_irqsave(&c->fifo_lock, flags); - list_add(&mbo->list, &c->trash_fifo); - spin_unlock_irqrestore(&c->fifo_lock, flags); -} - -static bool hdm_mbo_ready(struct most_channel *c) -{ - bool empty; - - if (c->enqueue_halt) - return false; - - spin_lock_irq(&c->fifo_lock); - empty = list_empty(&c->halt_fifo); - spin_unlock_irq(&c->fifo_lock); - - return !empty; -} - -static void nq_hdm_mbo(struct mbo *mbo) -{ - unsigned long flags; - struct most_channel *c = mbo->context; - - spin_lock_irqsave(&c->fifo_lock, flags); - list_add_tail(&mbo->list, &c->halt_fifo); - spin_unlock_irqrestore(&c->fifo_lock, flags); - wake_up_interruptible(&c->hdm_fifo_wq); -} - -static int hdm_enqueue_thread(void *data) -{ - struct most_channel *c = data; - struct mbo *mbo; - int ret; - typeof(c->iface->enqueue) enqueue = c->iface->enqueue; - - while (likely(!kthread_should_stop())) { - wait_event_interruptible(c->hdm_fifo_wq, - hdm_mbo_ready(c) || - kthread_should_stop()); - - mutex_lock(&c->nq_mutex); - spin_lock_irq(&c->fifo_lock); - if (unlikely(c->enqueue_halt || list_empty(&c->halt_fifo))) { - spin_unlock_irq(&c->fifo_lock); - mutex_unlock(&c->nq_mutex); - continue; - } - - mbo = list_pop_mbo(&c->halt_fifo); - spin_unlock_irq(&c->fifo_lock); - - if (c->cfg.direction == MOST_CH_RX) - mbo->buffer_length = c->cfg.buffer_size; - - ret = enqueue(mbo->ifp, mbo->hdm_channel_id, mbo); - mutex_unlock(&c->nq_mutex); - - if (unlikely(ret)) { - dev_err(&c->dev, "Buffer enqueue failed\n"); - nq_hdm_mbo(mbo); - c->hdm_enqueue_task = NULL; - return 0; - } - } - - return 0; -} - -static int run_enqueue_thread(struct most_channel *c, int channel_id) -{ - struct task_struct *task = - kthread_run(hdm_enqueue_thread, c, "hdm_fifo_%d", - channel_id); - - if (IS_ERR(task)) - return PTR_ERR(task); - - c->hdm_enqueue_task = task; - return 0; -} - -/** - * arm_mbo - recycle MBO for further usage - * @mbo: most buffer - * - * This puts an MBO back to the list to have it ready for up coming - * tx transactions. - * - * In case the MBO belongs to a channel that recently has been - * poisoned, the MBO is scheduled to be trashed. - * Calls the completion handler of an attached component. - */ -static void arm_mbo(struct mbo *mbo) -{ - unsigned long flags; - struct most_channel *c; - - c = mbo->context; - - if (c->is_poisoned) { - trash_mbo(mbo); - return; - } - - spin_lock_irqsave(&c->fifo_lock, flags); - ++*mbo->num_buffers_ptr; - list_add_tail(&mbo->list, &c->fifo); - spin_unlock_irqrestore(&c->fifo_lock, flags); - - if (c->pipe0.refs && c->pipe0.comp->tx_completion) - c->pipe0.comp->tx_completion(c->iface, c->channel_id); - - if (c->pipe1.refs && c->pipe1.comp->tx_completion) - c->pipe1.comp->tx_completion(c->iface, c->channel_id); -} - -/** - * arm_mbo_chain - helper function that arms an MBO chain for the HDM - * @c: pointer to interface channel - * @dir: direction of the channel - * @compl: pointer to completion function - * - * This allocates buffer objects including the containing DMA coherent - * buffer and puts them in the fifo. - * Buffers of Rx channels are put in the kthread fifo, hence immediately - * submitted to the HDM. - * - * Returns the number of allocated and enqueued MBOs. - */ -static int arm_mbo_chain(struct most_channel *c, int dir, - void (*compl)(struct mbo *)) -{ - unsigned int i; - struct mbo *mbo; - unsigned long flags; - u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len; - - atomic_set(&c->mbo_nq_level, 0); - - for (i = 0; i < c->cfg.num_buffers; i++) { - mbo = kzalloc(sizeof(*mbo), GFP_KERNEL); - if (!mbo) - goto flush_fifos; - - mbo->context = c; - mbo->ifp = c->iface; - mbo->hdm_channel_id = c->channel_id; - if (c->iface->dma_alloc) { - mbo->virt_address = - c->iface->dma_alloc(mbo, coherent_buf_size); - } else { - mbo->virt_address = - kzalloc(coherent_buf_size, GFP_KERNEL); - } - if (!mbo->virt_address) - goto release_mbo; - - mbo->complete = compl; - mbo->num_buffers_ptr = &dummy_num_buffers; - if (dir == MOST_CH_RX) { - nq_hdm_mbo(mbo); - atomic_inc(&c->mbo_nq_level); - } else { - spin_lock_irqsave(&c->fifo_lock, flags); - list_add_tail(&mbo->list, &c->fifo); - spin_unlock_irqrestore(&c->fifo_lock, flags); - } - } - return c->cfg.num_buffers; - -release_mbo: - kfree(mbo); - -flush_fifos: - flush_channel_fifos(c); - return 0; -} - -/** - * most_submit_mbo - submits an MBO to fifo - * @mbo: most buffer - */ -void most_submit_mbo(struct mbo *mbo) -{ - if (WARN_ONCE(!mbo || !mbo->context, - "Bad buffer or missing channel reference\n")) - return; - - nq_hdm_mbo(mbo); -} -EXPORT_SYMBOL_GPL(most_submit_mbo); - -/** - * most_write_completion - write completion handler - * @mbo: most buffer - * - * This recycles the MBO for further usage. In case the channel has been - * poisoned, the MBO is scheduled to be trashed. - */ -static void most_write_completion(struct mbo *mbo) -{ - struct most_channel *c; - - c = mbo->context; - if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) - trash_mbo(mbo); - else - arm_mbo(mbo); -} - -int channel_has_mbo(struct most_interface *iface, int id, - struct most_component *comp) -{ - struct most_channel *c = iface->p->channel[id]; - unsigned long flags; - int empty; - - if (unlikely(!c)) - return -EINVAL; - - if (c->pipe0.refs && c->pipe1.refs && - ((comp == c->pipe0.comp && c->pipe0.num_buffers <= 0) || - (comp == c->pipe1.comp && c->pipe1.num_buffers <= 0))) - return 0; - - spin_lock_irqsave(&c->fifo_lock, flags); - empty = list_empty(&c->fifo); - spin_unlock_irqrestore(&c->fifo_lock, flags); - return !empty; -} -EXPORT_SYMBOL_GPL(channel_has_mbo); - -/** - * most_get_mbo - get pointer to an MBO of pool - * @iface: pointer to interface instance - * @id: channel ID - * @comp: driver component - * - * This attempts to get a free buffer out of the channel fifo. - * Returns a pointer to MBO on success or NULL otherwise. - */ -struct mbo *most_get_mbo(struct most_interface *iface, int id, - struct most_component *comp) -{ - struct mbo *mbo; - struct most_channel *c; - unsigned long flags; - int *num_buffers_ptr; - - c = iface->p->channel[id]; - if (unlikely(!c)) - return NULL; - - if (c->pipe0.refs && c->pipe1.refs && - ((comp == c->pipe0.comp && c->pipe0.num_buffers <= 0) || - (comp == c->pipe1.comp && c->pipe1.num_buffers <= 0))) - return NULL; - - if (comp == c->pipe0.comp) - num_buffers_ptr = &c->pipe0.num_buffers; - else if (comp == c->pipe1.comp) - num_buffers_ptr = &c->pipe1.num_buffers; - else - num_buffers_ptr = &dummy_num_buffers; - - spin_lock_irqsave(&c->fifo_lock, flags); - if (list_empty(&c->fifo)) { - spin_unlock_irqrestore(&c->fifo_lock, flags); - return NULL; - } - mbo = list_pop_mbo(&c->fifo); - --*num_buffers_ptr; - spin_unlock_irqrestore(&c->fifo_lock, flags); - - mbo->num_buffers_ptr = num_buffers_ptr; - mbo->buffer_length = c->cfg.buffer_size; - return mbo; -} -EXPORT_SYMBOL_GPL(most_get_mbo); - -/** - * most_put_mbo - return buffer to pool - * @mbo: most buffer - */ -void most_put_mbo(struct mbo *mbo) -{ - struct most_channel *c = mbo->context; - - if (c->cfg.direction == MOST_CH_TX) { - arm_mbo(mbo); - return; - } - nq_hdm_mbo(mbo); - atomic_inc(&c->mbo_nq_level); -} -EXPORT_SYMBOL_GPL(most_put_mbo); - -/** - * most_read_completion - read completion handler - * @mbo: most buffer - * - * This function is called by the HDM when data has been received from the - * hardware and copied to the buffer of the MBO. - * - * In case the channel has been poisoned it puts the buffer in the trash queue. - * Otherwise, it passes the buffer to an component for further processing. - */ -static void most_read_completion(struct mbo *mbo) -{ - struct most_channel *c = mbo->context; - - if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) { - trash_mbo(mbo); - return; - } - - if (mbo->status == MBO_E_INVAL) { - nq_hdm_mbo(mbo); - atomic_inc(&c->mbo_nq_level); - return; - } - - if (atomic_sub_and_test(1, &c->mbo_nq_level)) - c->is_starving = 1; - - if (c->pipe0.refs && c->pipe0.comp->rx_completion && - c->pipe0.comp->rx_completion(mbo) == 0) - return; - - if (c->pipe1.refs && c->pipe1.comp->rx_completion && - c->pipe1.comp->rx_completion(mbo) == 0) - return; - - most_put_mbo(mbo); -} - -/** - * most_start_channel - prepares a channel for communication - * @iface: pointer to interface instance - * @id: channel ID - * @comp: driver component - * - * This prepares the channel for usage. Cross-checks whether the - * channel's been properly configured. - * - * Returns 0 on success or error code otherwise. - */ -int most_start_channel(struct most_interface *iface, int id, - struct most_component *comp) -{ - int num_buffer; - int ret; - struct most_channel *c = iface->p->channel[id]; - - if (unlikely(!c)) - return -EINVAL; - - mutex_lock(&c->start_mutex); - if (c->pipe0.refs + c->pipe1.refs > 0) - goto out; /* already started by another component */ - - if (!try_module_get(iface->mod)) { - dev_err(&c->dev, "Failed to acquire HDM lock\n"); - mutex_unlock(&c->start_mutex); - return -ENOLCK; - } - - c->cfg.extra_len = 0; - if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) { - dev_err(&c->dev, "Channel configuration failed. Go check settings...\n"); - ret = -EINVAL; - goto err_put_module; - } - - init_waitqueue_head(&c->hdm_fifo_wq); - - if (c->cfg.direction == MOST_CH_RX) - num_buffer = arm_mbo_chain(c, c->cfg.direction, - most_read_completion); - else - num_buffer = arm_mbo_chain(c, c->cfg.direction, - most_write_completion); - if (unlikely(!num_buffer)) { - ret = -ENOMEM; - goto err_put_module; - } - - ret = run_enqueue_thread(c, id); - if (ret) - goto err_put_module; - - c->is_starving = 0; - c->pipe0.num_buffers = c->cfg.num_buffers / 2; - c->pipe1.num_buffers = c->cfg.num_buffers - c->pipe0.num_buffers; - atomic_set(&c->mbo_ref, num_buffer); - -out: - if (comp == c->pipe0.comp) - c->pipe0.refs++; - if (comp == c->pipe1.comp) - c->pipe1.refs++; - mutex_unlock(&c->start_mutex); - return 0; - -err_put_module: - module_put(iface->mod); - mutex_unlock(&c->start_mutex); - return ret; -} -EXPORT_SYMBOL_GPL(most_start_channel); - -/** - * most_stop_channel - stops a running channel - * @iface: pointer to interface instance - * @id: channel ID - * @comp: driver component - */ -int most_stop_channel(struct most_interface *iface, int id, - struct most_component *comp) -{ - struct most_channel *c; - - if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) { - pr_err("Bad interface or index out of range\n"); - return -EINVAL; - } - c = iface->p->channel[id]; - if (unlikely(!c)) - return -EINVAL; - - mutex_lock(&c->start_mutex); - if (c->pipe0.refs + c->pipe1.refs >= 2) - goto out; - - if (c->hdm_enqueue_task) - kthread_stop(c->hdm_enqueue_task); - c->hdm_enqueue_task = NULL; - - if (iface->mod) - module_put(iface->mod); - - c->is_poisoned = true; - if (c->iface->poison_channel(c->iface, c->channel_id)) { - dev_err(&c->dev, "Failed to stop channel %d of interface %s\n", c->channel_id, - c->iface->description); - mutex_unlock(&c->start_mutex); - return -EAGAIN; - } - flush_trash_fifo(c); - flush_channel_fifos(c); - -#ifdef CMPL_INTERRUPTIBLE - if (wait_for_completion_interruptible(&c->cleanup)) { - dev_err(&c->dev, "Interrupted while cleaning up channel %d\n", c->channel_id); - mutex_unlock(&c->start_mutex); - return -EINTR; - } -#else - wait_for_completion(&c->cleanup); -#endif - c->is_poisoned = false; - -out: - if (comp == c->pipe0.comp) - c->pipe0.refs--; - if (comp == c->pipe1.comp) - c->pipe1.refs--; - mutex_unlock(&c->start_mutex); - return 0; -} -EXPORT_SYMBOL_GPL(most_stop_channel); - -/** - * most_register_component - registers a driver component with the core - * @comp: driver component - */ -int most_register_component(struct most_component *comp) -{ - if (!comp) { - pr_err("Bad component\n"); - return -EINVAL; - } - list_add_tail(&comp->list, &comp_list); - return 0; -} -EXPORT_SYMBOL_GPL(most_register_component); - -static int disconnect_channels(struct device *dev, void *data) -{ - struct most_interface *iface; - struct most_channel *c, *tmp; - struct most_component *comp = data; - - iface = dev_get_drvdata(dev); - list_for_each_entry_safe(c, tmp, &iface->p->channel_list, list) { - if (c->pipe0.comp == comp || c->pipe1.comp == comp) - comp->disconnect_channel(c->iface, c->channel_id); - if (c->pipe0.comp == comp) - c->pipe0.comp = NULL; - if (c->pipe1.comp == comp) - c->pipe1.comp = NULL; - } - return 0; -} - -/** - * most_deregister_component - deregisters a driver component with the core - * @comp: driver component - */ -int most_deregister_component(struct most_component *comp) -{ - if (!comp) { - pr_err("Bad component\n"); - return -EINVAL; - } - - bus_for_each_dev(&mostbus, NULL, comp, disconnect_channels); - list_del(&comp->list); - return 0; -} -EXPORT_SYMBOL_GPL(most_deregister_component); - -static void release_channel(struct device *dev) -{ - struct most_channel *c = to_channel(dev); - - kfree(c); -} - -/** - * most_register_interface - registers an interface with core - * @iface: device interface - * - * Allocates and initializes a new interface instance and all of its channels. - * Returns a pointer to kobject or an error pointer. - */ -int most_register_interface(struct most_interface *iface) -{ - unsigned int i; - int id; - struct most_channel *c; - - if (!iface || !iface->enqueue || !iface->configure || - !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) { - dev_err(iface->dev, "Bad interface or channel overflow\n"); - return -EINVAL; - } - - id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL); - if (id < 0) { - dev_err(iface->dev, "Failed to allocate device ID\n"); - return id; - } - - iface->p = kzalloc(sizeof(*iface->p), GFP_KERNEL); - if (!iface->p) { - ida_simple_remove(&mdev_id, id); - return -ENOMEM; - } - - INIT_LIST_HEAD(&iface->p->channel_list); - iface->p->dev_id = id; - strscpy(iface->p->name, iface->description, sizeof(iface->p->name)); - iface->dev->bus = &mostbus; - iface->dev->groups = interface_attr_groups; - dev_set_drvdata(iface->dev, iface); - if (device_register(iface->dev)) { - dev_err(iface->dev, "Failed to register interface device\n"); - kfree(iface->p); - put_device(iface->dev); - ida_simple_remove(&mdev_id, id); - return -ENOMEM; - } - - for (i = 0; i < iface->num_channels; i++) { - const char *name_suffix = iface->channel_vector[i].name_suffix; - - c = kzalloc(sizeof(*c), GFP_KERNEL); - if (!c) - goto err_free_resources; - if (!name_suffix) - snprintf(c->name, STRING_SIZE, "ch%d", i); - else - snprintf(c->name, STRING_SIZE, "%s", name_suffix); - c->dev.init_name = c->name; - c->dev.parent = iface->dev; - c->dev.groups = channel_attr_groups; - c->dev.release = release_channel; - iface->p->channel[i] = c; - c->is_starving = 0; - c->iface = iface; - c->channel_id = i; - c->keep_mbo = false; - c->enqueue_halt = false; - c->is_poisoned = false; - c->cfg.direction = 0; - c->cfg.data_type = 0; - c->cfg.num_buffers = 0; - c->cfg.buffer_size = 0; - c->cfg.subbuffer_size = 0; - c->cfg.packets_per_xact = 0; - spin_lock_init(&c->fifo_lock); - INIT_LIST_HEAD(&c->fifo); - INIT_LIST_HEAD(&c->trash_fifo); - INIT_LIST_HEAD(&c->halt_fifo); - init_completion(&c->cleanup); - atomic_set(&c->mbo_ref, 0); - mutex_init(&c->start_mutex); - mutex_init(&c->nq_mutex); - list_add_tail(&c->list, &iface->p->channel_list); - if (device_register(&c->dev)) { - dev_err(&c->dev, "Failed to register channel device\n"); - goto err_free_most_channel; - } - } - most_interface_register_notify(iface->description); - return 0; - -err_free_most_channel: - put_device(&c->dev); - -err_free_resources: - while (i > 0) { - c = iface->p->channel[--i]; - device_unregister(&c->dev); - } - kfree(iface->p); - device_unregister(iface->dev); - ida_simple_remove(&mdev_id, id); - return -ENOMEM; -} -EXPORT_SYMBOL_GPL(most_register_interface); - -/** - * most_deregister_interface - deregisters an interface with core - * @iface: device interface - * - * Before removing an interface instance from the list, all running - * channels are stopped and poisoned. - */ -void most_deregister_interface(struct most_interface *iface) -{ - int i; - struct most_channel *c; - - for (i = 0; i < iface->num_channels; i++) { - c = iface->p->channel[i]; - if (c->pipe0.comp) - c->pipe0.comp->disconnect_channel(c->iface, - c->channel_id); - if (c->pipe1.comp) - c->pipe1.comp->disconnect_channel(c->iface, - c->channel_id); - c->pipe0.comp = NULL; - c->pipe1.comp = NULL; - list_del(&c->list); - device_unregister(&c->dev); - } - - ida_simple_remove(&mdev_id, iface->p->dev_id); - kfree(iface->p); - device_unregister(iface->dev); -} -EXPORT_SYMBOL_GPL(most_deregister_interface); - -/** - * most_stop_enqueue - prevents core from enqueueing MBOs - * @iface: pointer to interface - * @id: channel id - * - * This is called by an HDM that _cannot_ attend to its duties and - * is imminent to get run over by the core. The core is not going to - * enqueue any further packets unless the flagging HDM calls - * most_resume enqueue(). - */ -void most_stop_enqueue(struct most_interface *iface, int id) -{ - struct most_channel *c = iface->p->channel[id]; - - if (!c) - return; - - mutex_lock(&c->nq_mutex); - c->enqueue_halt = true; - mutex_unlock(&c->nq_mutex); -} -EXPORT_SYMBOL_GPL(most_stop_enqueue); - -/** - * most_resume_enqueue - allow core to enqueue MBOs again - * @iface: pointer to interface - * @id: channel id - * - * This clears the enqueue halt flag and enqueues all MBOs currently - * sitting in the wait fifo. - */ -void most_resume_enqueue(struct most_interface *iface, int id) -{ - struct most_channel *c = iface->p->channel[id]; - - if (!c) - return; - - mutex_lock(&c->nq_mutex); - c->enqueue_halt = false; - mutex_unlock(&c->nq_mutex); - - wake_up_interruptible(&c->hdm_fifo_wq); -} -EXPORT_SYMBOL_GPL(most_resume_enqueue); - -static int __init most_init(void) -{ - int err; - - INIT_LIST_HEAD(&comp_list); - ida_init(&mdev_id); - - err = bus_register(&mostbus); - if (err) { - pr_err("Failed to register most bus\n"); - return err; - } - err = driver_register(&mostbus_driver); - if (err) { - pr_err("Failed to register core driver\n"); - goto err_unregister_bus; - } - configfs_init(); - return 0; - -err_unregister_bus: - bus_unregister(&mostbus); - return err; -} - -static void __exit most_exit(void) -{ - driver_unregister(&mostbus_driver); - bus_unregister(&mostbus); - ida_destroy(&mdev_id); -} - -module_init(most_init); -module_exit(most_exit); -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>"); -MODULE_DESCRIPTION("Core module of stacked MOST Linux driver"); diff --git a/drivers/staging/most/dim2/dim2.c b/drivers/staging/most/dim2/dim2.c index 16593281fcda..8e0f27e61652 100644 --- a/drivers/staging/most/dim2/dim2.c +++ b/drivers/staging/most/dim2/dim2.c @@ -20,8 +20,7 @@ #include <linux/dma-mapping.h> #include <linux/sched.h> #include <linux/kthread.h> - -#include "../most.h" +#include <linux/most.h> #include "hal.h" #include "errors.h" #include "sysfs.h" diff --git a/drivers/staging/most/i2c/i2c.c b/drivers/staging/most/i2c/i2c.c index 2980f7065846..893a8babdb2f 100644 --- a/drivers/staging/most/i2c/i2c.c +++ b/drivers/staging/most/i2c/i2c.c @@ -13,8 +13,7 @@ #include <linux/i2c.h> #include <linux/interrupt.h> #include <linux/err.h> - -#include "../most.h" +#include <linux/most.h> enum { CH_RX, CH_TX, NUM_CHANNELS }; diff --git a/drivers/staging/most/most.h b/drivers/staging/most/most.h deleted file mode 100644 index 232e01b7f5d2..000000000000 --- a/drivers/staging/most/most.h +++ /dev/null @@ -1,337 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * most.h - API for component and adapter drivers - * - * Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG - */ - -#ifndef __MOST_CORE_H__ -#define __MOST_CORE_H__ - -#include <linux/types.h> -#include <linux/device.h> - -struct module; -struct interface_private; - -/** - * Interface type - */ -enum most_interface_type { - ITYPE_LOOPBACK = 1, - ITYPE_I2C, - ITYPE_I2S, - ITYPE_TSI, - ITYPE_HBI, - ITYPE_MEDIALB_DIM, - ITYPE_MEDIALB_DIM2, - ITYPE_USB, - ITYPE_PCIE -}; - -/** - * Channel direction. - */ -enum most_channel_direction { - MOST_CH_RX = 1 << 0, - MOST_CH_TX = 1 << 1, -}; - -/** - * Channel data type. - */ -enum most_channel_data_type { - MOST_CH_CONTROL = 1 << 0, - MOST_CH_ASYNC = 1 << 1, - MOST_CH_ISOC = 1 << 2, - MOST_CH_SYNC = 1 << 5, -}; - -enum most_status_flags { - /* MBO was processed successfully (data was send or received )*/ - MBO_SUCCESS = 0, - /* The MBO contains wrong or missing information. */ - MBO_E_INVAL, - /* MBO was completed as HDM Channel will be closed */ - MBO_E_CLOSE, -}; - -/** - * struct most_channel_capability - Channel capability - * @direction: Supported channel directions. - * The value is bitwise OR-combination of the values from the - * enumeration most_channel_direction. Zero is allowed value and means - * "channel may not be used". - * @data_type: Supported channel data types. - * The value is bitwise OR-combination of the values from the - * enumeration most_channel_data_type. Zero is allowed value and means - * "channel may not be used". - * @num_buffers_packet: Maximum number of buffers supported by this channel - * for packet data types (Async,Control,QoS) - * @buffer_size_packet: Maximum buffer size supported by this channel - * for packet data types (Async,Control,QoS) - * @num_buffers_streaming: Maximum number of buffers supported by this channel - * for streaming data types (Sync,AV Packetized) - * @buffer_size_streaming: Maximum buffer size supported by this channel - * for streaming data types (Sync,AV Packetized) - * @name_suffix: Optional suffix providean by an HDM that is attached to the - * regular channel name. - * - * Describes the capabilities of a MOST channel like supported Data Types - * and directions. This information is provided by an HDM for the MostCore. - * - * The Core creates read only sysfs attribute files in - * /sys/devices/most/mdev#/<channel>/ with the - * following attributes: - * -available_directions - * -available_datatypes - * -number_of_packet_buffers - * -number_of_stream_buffers - * -size_of_packet_buffer - * -size_of_stream_buffer - * where content of each file is a string with all supported properties of this - * very channel attribute. - */ -struct most_channel_capability { - u16 direction; - u16 data_type; - u16 num_buffers_packet; - u16 buffer_size_packet; - u16 num_buffers_streaming; - u16 buffer_size_streaming; - const char *name_suffix; -}; - -/** - * struct most_channel_config - stores channel configuration - * @direction: direction of the channel - * @data_type: data type travelling over this channel - * @num_buffers: number of buffers - * @buffer_size: size of a buffer for AIM. - * Buffer size may be cutted down by HDM in a configure callback - * to match to a given interface and channel type. - * @extra_len: additional buffer space for internal HDM purposes like padding. - * May be set by HDM in a configure callback if needed. - * @subbuffer_size: size of a subbuffer - * @packets_per_xact: number of MOST frames that are packet inside one USB - * packet. This is USB specific - * - * Describes the configuration for a MOST channel. This information is - * provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a - * parameter of the "configure" function call. - */ -struct most_channel_config { - enum most_channel_direction direction; - enum most_channel_data_type data_type; - u16 num_buffers; - u16 buffer_size; - u16 extra_len; - u16 subbuffer_size; - u16 packets_per_xact; - u16 dbr_size; -}; - -/* - * struct mbo - MOST Buffer Object. - * @context: context for core completion handler - * @priv: private data for HDM - * - * public: documented fields that are used for the communications - * between MostCore and HDMs - * - * @list: list head for use by the mbo's current owner - * @ifp: (in) associated interface instance - * @num_buffers_ptr: amount of pool buffers - * @hdm_channel_id: (in) HDM channel instance - * @virt_address: (in) kernel virtual address of the buffer - * @bus_address: (in) bus address of the buffer - * @buffer_length: (in) buffer payload length - * @processed_length: (out) processed length - * @status: (out) transfer status - * @complete: (in) completion routine - * - * The core allocates and initializes the MBO. - * - * The HDM receives MBO for transfer from the core with the call to enqueue(). - * The HDM copies the data to- or from the buffer depending on configured - * channel direction, set "processed_length" and "status" and completes - * the transfer procedure by calling the completion routine. - * - * Finally, the MBO is being deallocated or recycled for further - * transfers of the same or a different HDM. - * - * Directions of usage: - * The core driver should never access any MBO fields (even if marked - * as "public") while the MBO is owned by an HDM. The ownership starts with - * the call of enqueue() and ends with the call of its complete() routine. - * - * II. - * Every HDM attached to the core driver _must_ ensure that it returns any MBO - * it owns (due to a previous call to enqueue() by the core driver) before it - * de-registers an interface or gets unloaded from the kernel. If this direction - * is violated memory leaks will occur, since the core driver does _not_ track - * MBOs it is currently not in control of. - * - */ -struct mbo { - void *context; - void *priv; - struct list_head list; - struct most_interface *ifp; - int *num_buffers_ptr; - u16 hdm_channel_id; - void *virt_address; - dma_addr_t bus_address; - u16 buffer_length; - u16 processed_length; - enum most_status_flags status; - void (*complete)(struct mbo *mbo); -}; - -/** - * Interface instance description. - * - * Describes an interface of a MOST device the core driver is bound to. - * This structure is allocated and initialized in the HDM. MostCore may not - * modify this structure. - * - * @dev: the actual device - * @mod: module - * @interface Interface type. \sa most_interface_type. - * @description PRELIMINARY. - * Unique description of the device instance from point of view of the - * interface in free text form (ASCII). - * It may be a hexadecimal presentation of the memory address for the MediaLB - * IP or USB device ID with USB properties for USB interface, etc. - * @num_channels Number of channels and size of the channel_vector. - * @channel_vector Properties of the channels. - * Array index represents channel ID by the driver. - * @configure Callback to change data type for the channel of the - * interface instance. May be zero if the instance of the interface is not - * configurable. Parameter channel_config describes direction and data - * type for the channel, configured by the higher level. The content of - * @enqueue Delivers MBO to the HDM for processing. - * After HDM completes Rx- or Tx- operation the processed MBO shall - * be returned back to the MostCore using completion routine. - * The reason to get the MBO delivered from the MostCore after the channel - * is poisoned is the re-opening of the channel by the application. - * In this case the HDM shall hold MBOs and service the channel as usual. - * The HDM must be able to hold at least one MBO for each channel. - * The callback returns a negative value on error, otherwise 0. - * @poison_channel Informs HDM about closing the channel. The HDM shall - * cancel all transfers and synchronously or asynchronously return - * all enqueued for this channel MBOs using the completion routine. - * The callback returns a negative value on error, otherwise 0. - * @request_netinfo: triggers retrieving of network info from the HDM by - * means of "Message exchange over MDP/MEP" - * The call of the function request_netinfo with the parameter on_netinfo as - * NULL prohibits use of the previously obtained function pointer. - * @priv Private field used by mostcore to store context information. - */ -struct most_interface { - struct device *dev; - struct device *driver_dev; - struct module *mod; - enum most_interface_type interface; - const char *description; - unsigned int num_channels; - struct most_channel_capability *channel_vector; - void *(*dma_alloc)(struct mbo *mbo, u32 size); - void (*dma_free)(struct mbo *mbo, u32 size); - int (*configure)(struct most_interface *iface, int channel_idx, - struct most_channel_config *channel_config); - int (*enqueue)(struct most_interface *iface, int channel_idx, - struct mbo *mbo); - int (*poison_channel)(struct most_interface *iface, int channel_idx); - void (*request_netinfo)(struct most_interface *iface, int channel_idx, - void (*on_netinfo)(struct most_interface *iface, - unsigned char link_stat, - unsigned char *mac_addr)); - void *priv; - struct interface_private *p; -}; - -/** - * struct most_component - identifies a loadable component for the mostcore - * @list: list_head - * @name: component name - * @probe_channel: function for core to notify driver about channel connection - * @disconnect_channel: callback function to disconnect a certain channel - * @rx_completion: completion handler for received packets - * @tx_completion: completion handler for transmitted packets - */ -struct most_component { - struct list_head list; - const char *name; - struct module *mod; - int (*probe_channel)(struct most_interface *iface, int channel_idx, - struct most_channel_config *cfg, char *name, - char *param); - int (*disconnect_channel)(struct most_interface *iface, - int channel_idx); - int (*rx_completion)(struct mbo *mbo); - int (*tx_completion)(struct most_interface *iface, int channel_idx); - int (*cfg_complete)(void); -}; - -/** - * most_register_interface - Registers instance of the interface. - * @iface: Pointer to the interface instance description. - * - * Returns a pointer to the kobject of the generated instance. - * - * Note: HDM has to ensure that any reference held on the kobj is - * released before deregistering the interface. - */ -int most_register_interface(struct most_interface *iface); - -/** - * Deregisters instance of the interface. - * @intf_instance Pointer to the interface instance description. - */ -void most_deregister_interface(struct most_interface *iface); -void most_submit_mbo(struct mbo *mbo); - -/** - * most_stop_enqueue - prevents core from enqueing MBOs - * @iface: pointer to interface - * @channel_idx: channel index - */ -void most_stop_enqueue(struct most_interface *iface, int channel_idx); - -/** - * most_resume_enqueue - allow core to enqueue MBOs again - * @iface: pointer to interface - * @channel_idx: channel index - * - * This clears the enqueue halt flag and enqueues all MBOs currently - * in wait fifo. - */ -void most_resume_enqueue(struct most_interface *iface, int channel_idx); -int most_register_component(struct most_component *comp); -int most_deregister_component(struct most_component *comp); -struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx, - struct most_component *comp); -void most_put_mbo(struct mbo *mbo); -int channel_has_mbo(struct most_interface *iface, int channel_idx, - struct most_component *comp); -int most_start_channel(struct most_interface *iface, int channel_idx, - struct most_component *comp); -int most_stop_channel(struct most_interface *iface, int channel_idx, - struct most_component *comp); -int __init configfs_init(void); -int most_register_configfs_subsys(struct most_component *comp); -void most_deregister_configfs_subsys(struct most_component *comp); -int most_add_link(char *mdev, char *mdev_ch, char *comp_name, char *link_name, - char *comp_param); -int most_remove_link(char *mdev, char *mdev_ch, char *comp_name); -int most_set_cfg_buffer_size(char *mdev, char *mdev_ch, u16 val); -int most_set_cfg_subbuffer_size(char *mdev, char *mdev_ch, u16 val); -int most_set_cfg_dbr_size(char *mdev, char *mdev_ch, u16 val); -int most_set_cfg_num_buffers(char *mdev, char *mdev_ch, u16 val); -int most_set_cfg_datatype(char *mdev, char *mdev_ch, char *buf); -int most_set_cfg_direction(char *mdev, char *mdev_ch, char *buf); -int most_set_cfg_packets_xact(char *mdev, char *mdev_ch, u16 val); -int most_cfg_complete(char *comp_name); -void most_interface_register_notify(const char *mdev_name); -#endif /* MOST_CORE_H_ */ diff --git a/drivers/staging/most/net/net.c b/drivers/staging/most/net/net.c index 5547e36e09de..830f089f1a88 100644 --- a/drivers/staging/most/net/net.c +++ b/drivers/staging/most/net/net.c @@ -15,8 +15,7 @@ #include <linux/list.h> #include <linux/wait.h> #include <linux/kobject.h> - -#include "../most.h" +#include <linux/most.h> #define MEP_HDR_LEN 8 #define MDP_HDR_LEN 16 diff --git a/drivers/staging/most/sound/sound.c b/drivers/staging/most/sound/sound.c index 44cf2334834f..1527f410af2b 100644 --- a/drivers/staging/most/sound/sound.c +++ b/drivers/staging/most/sound/sound.c @@ -17,8 +17,7 @@ #include <sound/pcm_params.h> #include <linux/sched.h> #include <linux/kthread.h> - -#include "../most.h" +#include <linux/most.h> #define DRIVER_NAME "sound" #define STRING_SIZE 80 diff --git a/drivers/staging/most/usb/usb.c b/drivers/staging/most/usb/usb.c index 0bda88c4bc89..e8c5a8c98375 100644 --- a/drivers/staging/most/usb/usb.c +++ b/drivers/staging/most/usb/usb.c @@ -23,8 +23,7 @@ #include <linux/dma-mapping.h> #include <linux/etherdevice.h> #include <linux/uaccess.h> - -#include "../most.h" +#include <linux/most.h> #define USB_MTU 512 #define NO_ISOCHRONOUS_URB 0 diff --git a/drivers/staging/most/video/video.c b/drivers/staging/most/video/video.c index 4cffc8fd62bd..829df899b993 100644 --- a/drivers/staging/most/video/video.c +++ b/drivers/staging/most/video/video.c @@ -20,8 +20,7 @@ #include <media/v4l2-device.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-fh.h> - -#include "../most.h" +#include <linux/most.h> #define V4L2_CMP_MAX_INPUT 1 diff --git a/drivers/staging/mt7621-dma/mtk-hsdma.c b/drivers/staging/mt7621-dma/mtk-hsdma.c index 20b898954416..14592ed9ce98 100644 --- a/drivers/staging/mt7621-dma/mtk-hsdma.c +++ b/drivers/staging/mt7621-dma/mtk-hsdma.c @@ -220,8 +220,7 @@ static void hsdma_dump_reg(struct mtk_hsdam_engine *hsdma) mtk_hsdma_read(hsdma, HSDMA_REG_RX_CRX), mtk_hsdma_read(hsdma, HSDMA_REG_RX_DRX)); - dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, " - "intr_stat %08x, intr_mask %08x\n", + dev_dbg(hsdma->ddev.dev, "info %08x, glo %08x, delay %08x, intr_stat %08x, intr_mask %08x\n", mtk_hsdma_read(hsdma, HSDMA_REG_INFO), mtk_hsdma_read(hsdma, HSDMA_REG_GLO_CFG), mtk_hsdma_read(hsdma, HSDMA_REG_DELAY_INT), diff --git a/drivers/staging/mt7621-dts/gbpc1.dts b/drivers/staging/mt7621-dts/gbpc1.dts index 1fb560ff059c..a7c0d3115d72 100644 --- a/drivers/staging/mt7621-dts/gbpc1.dts +++ b/drivers/staging/mt7621-dts/gbpc1.dts @@ -114,6 +114,10 @@ &pcie { pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; + + reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>, + <&gpio 8 GPIO_ACTIVE_LOW>, + <&gpio 7 GPIO_ACTIVE_LOW>; status = "okay"; }; diff --git a/drivers/staging/mt7621-dts/mt7621.dtsi b/drivers/staging/mt7621-dts/mt7621.dtsi index d89d68ffa7bc..9e5cf68731bb 100644 --- a/drivers/staging/mt7621-dts/mt7621.dtsi +++ b/drivers/staging/mt7621-dts/mt7621.dtsi @@ -286,7 +286,7 @@ pcie_pins: pcie0 { pcie0 { groups = "pcie"; - function = "pcie rst"; + function = "gpio"; }; }; @@ -512,7 +512,6 @@ #address-cells = <3>; #size-cells = <2>; - perst-gpio = <&gpio 19 GPIO_ACTIVE_HIGH>; pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; @@ -532,12 +531,14 @@ status = "disabled"; - resets = <&rstctrl 23 &rstctrl 24 &rstctrl 25 &rstctrl 26>; - reset-names = "pcie", "pcie0", "pcie1", "pcie2"; + resets = <&rstctrl 24 &rstctrl 25 &rstctrl 26>; + reset-names = "pcie0", "pcie1", "pcie2"; clocks = <&clkctrl 24 &clkctrl 25 &clkctrl 26>; clock-names = "pcie0", "pcie1", "pcie2"; - phys = <&pcie0_phy 0>, <&pcie0_phy 1>, <&pcie1_phy 0>; - phy-names = "pcie-phy0", "pcie-phy1", "pcie-phy2"; + phys = <&pcie0_phy 1>, <&pcie2_phy 0>; + phy-names = "pcie-phy0", "pcie-phy2"; + + reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>; pcie@0,0 { reg = <0x0000 0 0 0 0>; @@ -570,7 +571,7 @@ #phy-cells = <1>; }; - pcie1_phy: pcie-phy@1e14a000 { + pcie2_phy: pcie-phy@1e14a000 { compatible = "mediatek,mt7621-pci-phy"; reg = <0x1e14a000 0x0700>; #phy-cells = <1>; diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c index d2a07f145143..57743fd22be4 100644 --- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c +++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c @@ -75,34 +75,27 @@ #define RG_PE1_FRC_MSTCKDIV BIT(5) -#define MAX_PHYS 2 +#define XTAL_MODE_SEL_SHIFT 6 +#define XTAL_MODE_SEL_MASK 0x7 -/** - * struct mt7621_pci_phy_instance - Mt7621 Pcie PHY device - * @phy: pointer to the kernel PHY device - * @port_base: base register - * @index: internal ID to identify the Mt7621 PCIe PHY - */ -struct mt7621_pci_phy_instance { - struct phy *phy; - void __iomem *port_base; - u32 index; -}; +#define MAX_PHYS 2 /** * struct mt7621_pci_phy - Mt7621 Pcie PHY core * @dev: pointer to device * @regmap: kernel regmap pointer - * @phys: pointer to Mt7621 PHY device - * @nphys: number of PHY devices for this core + * @phy: pointer to the kernel PHY device + * @port_base: base register + * @has_dual_port: if the phy has dual ports. * @bypass_pipe_rst: mark if 'mt7621_bypass_pipe_rst' * needs to be executed. Depends on chip revision. */ struct mt7621_pci_phy { struct device *dev; struct regmap *regmap; - struct mt7621_pci_phy_instance **phys; - int nphys; + struct phy *phy; + void __iomem *port_base; + bool has_dual_port; bool bypass_pipe_rst; }; @@ -120,162 +113,152 @@ static inline void phy_write(struct mt7621_pci_phy *phy, u32 val, u32 reg) regmap_write(phy->regmap, reg, val); } -static void mt7621_bypass_pipe_rst(struct mt7621_pci_phy *phy, - struct mt7621_pci_phy_instance *instance) +static inline void mt7621_phy_rmw(struct mt7621_pci_phy *phy, + u32 reg, u32 clr, u32 set) +{ + u32 val = phy_read(phy, reg); + + val &= ~clr; + val |= set; + phy_write(phy, val, reg); +} + +static void mt7621_bypass_pipe_rst(struct mt7621_pci_phy *phy) { - u32 offset = (instance->index != 1) ? - RG_PE1_PIPE_REG : RG_PE1_PIPE_REG + RG_P0_TO_P1_WIDTH; - u32 reg; - - reg = phy_read(phy, offset); - reg &= ~(RG_PE1_PIPE_RST | RG_PE1_PIPE_CMD_FRC); - reg |= (RG_PE1_PIPE_RST | RG_PE1_PIPE_CMD_FRC); - phy_write(phy, reg, offset); + mt7621_phy_rmw(phy, RG_PE1_PIPE_REG, 0, RG_PE1_PIPE_RST); + mt7621_phy_rmw(phy, RG_PE1_PIPE_REG, 0, RG_PE1_PIPE_CMD_FRC); + + if (phy->has_dual_port) { + mt7621_phy_rmw(phy, RG_PE1_PIPE_REG + RG_P0_TO_P1_WIDTH, + 0, RG_PE1_PIPE_RST); + mt7621_phy_rmw(phy, RG_PE1_PIPE_REG + RG_P0_TO_P1_WIDTH, + 0, RG_PE1_PIPE_CMD_FRC); + } } -static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy, - struct mt7621_pci_phy_instance *instance) +static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy) { struct device *dev = phy->dev; - u32 reg = rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0); - u32 offset; - u32 val; + u32 xtal_mode; + + xtal_mode = (rt_sysc_r32(SYSC_REG_SYSTEM_CONFIG0) + >> XTAL_MODE_SEL_SHIFT) & XTAL_MODE_SEL_MASK; - reg = (reg >> 6) & 0x7; /* Set PCIe Port PHY to disable SSC */ /* Debug Xtal Type */ - val = phy_read(phy, RG_PE1_FRC_H_XTAL_REG); - val &= ~(RG_PE1_FRC_H_XTAL_TYPE | RG_PE1_H_XTAL_TYPE); - val |= RG_PE1_FRC_H_XTAL_TYPE; - val |= RG_PE1_H_XTAL_TYPE_VAL(0x00); - phy_write(phy, val, RG_PE1_FRC_H_XTAL_REG); + mt7621_phy_rmw(phy, RG_PE1_FRC_H_XTAL_REG, + RG_PE1_FRC_H_XTAL_TYPE | RG_PE1_H_XTAL_TYPE, + RG_PE1_FRC_H_XTAL_TYPE | RG_PE1_H_XTAL_TYPE_VAL(0x00)); /* disable port */ - offset = (instance->index != 1) ? - RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH; - val = phy_read(phy, offset); - val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN); - val |= RG_PE1_FRC_PHY_EN; - phy_write(phy, val, offset); - - /* Set Pre-divider ratio (for host mode) */ - val = phy_read(phy, RG_PE1_H_PLL_REG); - val &= ~(RG_PE1_H_PLL_PREDIV); - - if (reg <= 5 && reg >= 3) { /* 40MHz Xtal */ - val |= RG_PE1_H_PLL_PREDIV_VAL(0x01); - phy_write(phy, val, RG_PE1_H_PLL_REG); + mt7621_phy_rmw(phy, RG_PE1_FRC_PHY_REG, + RG_PE1_PHY_EN, RG_PE1_FRC_PHY_EN); + + if (phy->has_dual_port) { + mt7621_phy_rmw(phy, RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH, + RG_PE1_PHY_EN, RG_PE1_FRC_PHY_EN); + } + + if (xtal_mode <= 5 && xtal_mode >= 3) { /* 40MHz Xtal */ + /* Set Pre-divider ratio (for host mode) */ + mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, + RG_PE1_H_PLL_PREDIV, + RG_PE1_H_PLL_PREDIV_VAL(0x01)); dev_info(dev, "Xtal is 40MHz\n"); - } else { /* 25MHz | 20MHz Xtal */ - val |= RG_PE1_H_PLL_PREDIV_VAL(0x00); - phy_write(phy, val, RG_PE1_H_PLL_REG); - if (reg >= 6) { - dev_info(dev, "Xtal is 25MHz\n"); - - /* Select feedback clock */ - val = phy_read(phy, RG_PE1_H_PLL_FBKSEL_REG); - val &= ~(RG_PE1_H_PLL_FBKSEL); - val |= RG_PE1_H_PLL_FBKSEL_VAL(0x01); - phy_write(phy, val, RG_PE1_H_PLL_FBKSEL_REG); - - /* DDS NCPO PCW (for host mode) */ - val = phy_read(phy, RG_PE1_H_LCDDS_SSC_PRD_REG); - val &= ~(RG_PE1_H_LCDDS_SSC_PRD); - val |= RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18000000); - phy_write(phy, val, RG_PE1_H_LCDDS_SSC_PRD_REG); - - /* DDS SSC dither period control */ - val = phy_read(phy, RG_PE1_H_LCDDS_SSC_PRD_REG); - val &= ~(RG_PE1_H_LCDDS_SSC_PRD); - val |= RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18d); - phy_write(phy, val, RG_PE1_H_LCDDS_SSC_PRD_REG); - - /* DDS SSC dither amplitude control */ - val = phy_read(phy, RG_PE1_H_LCDDS_SSC_DELTA_REG); - val &= ~(RG_PE1_H_LCDDS_SSC_DELTA | - RG_PE1_H_LCDDS_SSC_DELTA1); - val |= RG_PE1_H_LCDDS_SSC_DELTA_VAL(0x4a); - val |= RG_PE1_H_LCDDS_SSC_DELTA1_VAL(0x4a); - phy_write(phy, val, RG_PE1_H_LCDDS_SSC_DELTA_REG); - } else { - dev_info(dev, "Xtal is 20MHz\n"); - } + } else if (xtal_mode >= 6) { /* 25MHz Xal */ + mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, + RG_PE1_H_PLL_PREDIV, + RG_PE1_H_PLL_PREDIV_VAL(0x00)); + /* Select feedback clock */ + mt7621_phy_rmw(phy, RG_PE1_H_PLL_FBKSEL_REG, + RG_PE1_H_PLL_FBKSEL, + RG_PE1_H_PLL_FBKSEL_VAL(0x01)); + /* DDS NCPO PCW (for host mode) */ + mt7621_phy_rmw(phy, RG_PE1_H_LCDDS_SSC_PRD_REG, + RG_PE1_H_LCDDS_SSC_PRD, + RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18000000)); + /* DDS SSC dither period control */ + mt7621_phy_rmw(phy, RG_PE1_H_LCDDS_SSC_PRD_REG, + RG_PE1_H_LCDDS_SSC_PRD, + RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18d)); + /* DDS SSC dither amplitude control */ + mt7621_phy_rmw(phy, RG_PE1_H_LCDDS_SSC_DELTA_REG, + RG_PE1_H_LCDDS_SSC_DELTA | + RG_PE1_H_LCDDS_SSC_DELTA1, + RG_PE1_H_LCDDS_SSC_DELTA_VAL(0x4a) | + RG_PE1_H_LCDDS_SSC_DELTA1_VAL(0x4a)); + dev_info(dev, "Xtal is 25MHz\n"); + } else { /* 20MHz Xtal */ + mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, + RG_PE1_H_PLL_PREDIV, + RG_PE1_H_PLL_PREDIV_VAL(0x00)); + + dev_info(dev, "Xtal is 20MHz\n"); } /* DDS clock inversion */ - val = phy_read(phy, RG_PE1_LCDDS_CLK_PH_INV_REG); - val &= ~(RG_PE1_LCDDS_CLK_PH_INV); - val |= RG_PE1_LCDDS_CLK_PH_INV; - phy_write(phy, val, RG_PE1_LCDDS_CLK_PH_INV_REG); + mt7621_phy_rmw(phy, RG_PE1_LCDDS_CLK_PH_INV_REG, + RG_PE1_LCDDS_CLK_PH_INV, RG_PE1_LCDDS_CLK_PH_INV); /* Set PLL bits */ - val = phy_read(phy, RG_PE1_H_PLL_REG); - val &= ~(RG_PE1_H_PLL_BC | RG_PE1_H_PLL_BP | RG_PE1_H_PLL_IR | - RG_PE1_H_PLL_IC | RG_PE1_PLL_DIVEN); - val |= RG_PE1_H_PLL_BC_VAL(0x02); - val |= RG_PE1_H_PLL_BP_VAL(0x06); - val |= RG_PE1_H_PLL_IR_VAL(0x02); - val |= RG_PE1_H_PLL_IC_VAL(0x01); - val |= RG_PE1_PLL_DIVEN_VAL(0x02); - phy_write(phy, val, RG_PE1_H_PLL_REG); - - val = phy_read(phy, RG_PE1_H_PLL_BR_REG); - val &= ~(RG_PE1_H_PLL_BR); - val |= RG_PE1_H_PLL_BR_VAL(0x00); - phy_write(phy, val, RG_PE1_H_PLL_BR_REG); - - if (reg <= 5 && reg >= 3) { /* 40MHz Xtal */ + mt7621_phy_rmw(phy, RG_PE1_H_PLL_REG, + RG_PE1_H_PLL_BC | RG_PE1_H_PLL_BP | RG_PE1_H_PLL_IR | + RG_PE1_H_PLL_IC | RG_PE1_PLL_DIVEN, + RG_PE1_H_PLL_BC_VAL(0x02) | RG_PE1_H_PLL_BP_VAL(0x06) | + RG_PE1_H_PLL_IR_VAL(0x02) | RG_PE1_H_PLL_IC_VAL(0x01) | + RG_PE1_PLL_DIVEN_VAL(0x02)); + + mt7621_phy_rmw(phy, RG_PE1_H_PLL_BR_REG, + RG_PE1_H_PLL_BR, RG_PE1_H_PLL_BR_VAL(0x00)); + + if (xtal_mode <= 5 && xtal_mode >= 3) { /* 40MHz Xtal */ /* set force mode enable of da_pe1_mstckdiv */ - val = phy_read(phy, RG_PE1_MSTCKDIV_REG); - val &= ~(RG_PE1_MSTCKDIV | RG_PE1_FRC_MSTCKDIV); - val |= (RG_PE1_MSTCKDIV_VAL(0x01) | RG_PE1_FRC_MSTCKDIV); - phy_write(phy, val, RG_PE1_MSTCKDIV_REG); + mt7621_phy_rmw(phy, RG_PE1_MSTCKDIV_REG, + RG_PE1_MSTCKDIV | RG_PE1_FRC_MSTCKDIV, + RG_PE1_MSTCKDIV_VAL(0x01) | RG_PE1_FRC_MSTCKDIV); } } static int mt7621_pci_phy_init(struct phy *phy) { - struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy); - struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent); + struct mt7621_pci_phy *mphy = phy_get_drvdata(phy); if (mphy->bypass_pipe_rst) - mt7621_bypass_pipe_rst(mphy, instance); + mt7621_bypass_pipe_rst(mphy); - mt7621_set_phy_for_ssc(mphy, instance); + mt7621_set_phy_for_ssc(mphy); return 0; } static int mt7621_pci_phy_power_on(struct phy *phy) { - struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy); - struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent); - u32 offset = (instance->index != 1) ? - RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH; - u32 val; + struct mt7621_pci_phy *mphy = phy_get_drvdata(phy); /* Enable PHY and disable force mode */ - val = phy_read(mphy, offset); - val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN); - val |= (RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN); - phy_write(mphy, val, offset); + mt7621_phy_rmw(mphy, RG_PE1_FRC_PHY_REG, + RG_PE1_FRC_PHY_EN, RG_PE1_PHY_EN); + + if (mphy->has_dual_port) { + mt7621_phy_rmw(mphy, RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH, + RG_PE1_FRC_PHY_EN, RG_PE1_PHY_EN); + } return 0; } static int mt7621_pci_phy_power_off(struct phy *phy) { - struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy); - struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent); - u32 offset = (instance->index != 1) ? - RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH; - u32 val; + struct mt7621_pci_phy *mphy = phy_get_drvdata(phy); /* Disable PHY */ - val = phy_read(mphy, offset); - val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN); - val |= RG_PE1_FRC_PHY_EN; - phy_write(mphy, val, offset); + mt7621_phy_rmw(mphy, RG_PE1_FRC_PHY_REG, + RG_PE1_PHY_EN, RG_PE1_FRC_PHY_EN); + + if (mphy->has_dual_port) { + mt7621_phy_rmw(mphy, RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH, + RG_PE1_PHY_EN, RG_PE1_FRC_PHY_EN); + } return 0; } @@ -298,13 +281,15 @@ static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev, { struct mt7621_pci_phy *mt7621_phy = dev_get_drvdata(dev); - if (args->args_count == 0) - return mt7621_phy->phys[0]->phy; - if (WARN_ON(args->args[0] >= MAX_PHYS)) return ERR_PTR(-ENODEV); - return mt7621_phy->phys[args->args[0]]->phy; + mt7621_phy->has_dual_port = args->args[0]; + + dev_info(dev, "PHY for 0x%08x (dual port = %d)\n", + (unsigned int)mt7621_phy->port_base, mt7621_phy->has_dual_port); + + return mt7621_phy->phy; } static const struct soc_device_attribute mt7621_pci_quirks_match[] = { @@ -325,19 +310,11 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev) struct phy_provider *provider; struct mt7621_pci_phy *phy; struct resource *res; - int port; - void __iomem *port_base; phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); if (!phy) return -ENOMEM; - phy->nphys = MAX_PHYS; - phy->phys = devm_kcalloc(dev, phy->nphys, - sizeof(*phy->phys), GFP_KERNEL); - if (!phy->phys) - return -ENOMEM; - attr = soc_device_match(mt7621_pci_quirks_match); if (attr) phy->bypass_pipe_rst = true; @@ -351,39 +328,25 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev) return -ENXIO; } - port_base = devm_ioremap_resource(dev, res); - if (IS_ERR(port_base)) { + phy->port_base = devm_ioremap_resource(dev, res); + if (IS_ERR(phy->port_base)) { dev_err(dev, "failed to remap phy regs\n"); - return PTR_ERR(port_base); + return PTR_ERR(phy->port_base); } - phy->regmap = devm_regmap_init_mmio(phy->dev, port_base, + phy->regmap = devm_regmap_init_mmio(phy->dev, phy->port_base, &mt7621_pci_phy_regmap_config); if (IS_ERR(phy->regmap)) return PTR_ERR(phy->regmap); - for (port = 0; port < MAX_PHYS; port++) { - struct mt7621_pci_phy_instance *instance; - struct phy *pphy; - - instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL); - if (!instance) - return -ENOMEM; - - phy->phys[port] = instance; - - pphy = devm_phy_create(dev, dev->of_node, &mt7621_pci_phy_ops); - if (IS_ERR(phy)) { - dev_err(dev, "failed to create phy\n"); - return PTR_ERR(phy); - } - - instance->port_base = port_base; - instance->phy = pphy; - instance->index = port; - phy_set_drvdata(pphy, instance); + phy->phy = devm_phy_create(dev, dev->of_node, &mt7621_pci_phy_ops); + if (IS_ERR(phy)) { + dev_err(dev, "failed to create phy\n"); + return PTR_ERR(phy); } + phy_set_drvdata(phy->phy, phy); + provider = devm_of_phy_provider_register(dev, mt7621_pcie_phy_of_xlate); return PTR_ERR_OR_ZERO(provider); @@ -403,12 +366,7 @@ static struct platform_driver mt7621_pci_phy_driver = { }, }; -static int __init mt7621_pci_phy_drv_init(void) -{ - return platform_driver_register(&mt7621_pci_phy_driver); -} - -module_init(mt7621_pci_phy_drv_init); +builtin_platform_driver(mt7621_pci_phy_driver); MODULE_AUTHOR("Sergio Paracuellos <sergio.paracuellos@gmail.com>"); MODULE_DESCRIPTION("MediaTek MT7621 PCIe PHY driver"); diff --git a/drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt b/drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt index 604ec813bd45..327a68267309 100644 --- a/drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt +++ b/drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt @@ -6,7 +6,6 @@ Required properties: - reg: Base addresses and lengths of the PCIe subsys and root ports. - bus-range: Range of bus numbers associated with this controller. - #address-cells: Address representation for root ports (must be 3) -- perst-gpio: PCIe reset signal line. - pinctrl-names : The pin control state names. - pinctrl-0: The "default" pinctrl state. - #size-cells: Size representation for root ports (must be 2) @@ -24,6 +23,7 @@ Required properties: See ../clocks/clock-bindings.txt for details. - clock-names: Must be "pcie0", "pcie1", "pcieN"... based on the number of root ports. +- reset-gpios: GPIO specs for the reset pins. In addition, the device tree node must have sub-nodes describing each PCIe port interface, having the following mandatory properties: @@ -49,7 +49,6 @@ Example for MT7621: #address-cells = <3>; #size-cells = <2>; - perst-gpio = <&gpio 19 GPIO_ACTIVE_HIGH>; pinctrl-names = "default"; pinctrl-0 = <&pcie_pins>; @@ -74,6 +73,10 @@ Example for MT7621: clocks = <&clkctrl 24 &clkctrl 25 &clkctrl 26>; clock-names = "pcie0", "pcie1", "pcie2"; + reset-gpios = <&gpio 19 GPIO_ACTIVE_LOW>, + <&gpio 8 GPIO_ACTIVE_LOW>, + <&gpio 7 GPIO_ACTIVE_LOW>; + pcie@0,0 { reg = <0x0000 0 0 0 0>; #address-cells = <3>; diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c index 3633c924848e..f58e3a51fc71 100644 --- a/drivers/staging/mt7621-pci/pci-mt7621.c +++ b/drivers/staging/mt7621-pci/pci-mt7621.c @@ -45,8 +45,6 @@ /* rt_sysc_membase relative registers */ #define RALINK_CLKCFG1 0x30 -#define RALINK_PCIE_CLK_GEN 0x7c -#define RALINK_PCIE_CLK_GEN1 0x80 /* Host-PCI bridge registers */ #define RALINK_PCI_PCICFG_ADDR 0x0000 @@ -57,13 +55,13 @@ #define RALINK_PCI_IOBASE 0x002C /* PCICFG virtual bridges */ -#define MT7621_BR0_MASK GENMASK(19, 16) -#define MT7621_BR1_MASK GENMASK(23, 20) -#define MT7621_BR2_MASK GENMASK(27, 24) -#define MT7621_BR_ALL_MASK GENMASK(27, 16) -#define MT7621_BR0_SHIFT 16 -#define MT7621_BR1_SHIFT 20 -#define MT7621_BR2_SHIFT 24 +#define PCIE_P2P_MAX 3 +#define PCIE_P2P_BR_DEVNUM_SHIFT(p) (16 + (p) * 4) +#define PCIE_P2P_BR_DEVNUM0_SHIFT PCIE_P2P_BR_DEVNUM_SHIFT(0) +#define PCIE_P2P_BR_DEVNUM1_SHIFT PCIE_P2P_BR_DEVNUM_SHIFT(1) +#define PCIE_P2P_BR_DEVNUM2_SHIFT PCIE_P2P_BR_DEVNUM_SHIFT(2) +#define PCIE_P2P_BR_DEVNUM_MASK 0xf +#define PCIE_P2P_BR_DEVNUM_MASK_FULL (0xfff << PCIE_P2P_BR_DEVNUM0_SHIFT) /* PCIe RC control registers */ #define MT7621_PCIE_OFFSET 0x2000 @@ -85,14 +83,10 @@ #define PCIE_PORT_CLK_EN(x) BIT(24 + (x)) #define PCIE_PORT_LINKUP BIT(0) -#define PCIE_CLK_GEN_EN BIT(31) -#define PCIE_CLK_GEN_DIS 0 -#define PCIE_CLK_GEN1_DIS GENMASK(30, 24) -#define PCIE_CLK_GEN1_EN (BIT(27) | BIT(25)) #define MEMORY_BASE 0x0 #define PERST_MODE_MASK GENMASK(11, 10) #define PERST_MODE_GPIO BIT(10) -#define PERST_DELAY_US 1000 +#define PERST_DELAY_MS 100 /** * struct mt7621_pcie_port - PCIe port information @@ -101,6 +95,7 @@ * @pcie: pointer to PCIe host info * @phy: pointer to PHY control block * @pcie_rst: pointer to port reset control + * @gpio_rst: gpio reset * @slot: port slot * @enabled: indicates if port is enabled */ @@ -110,6 +105,7 @@ struct mt7621_pcie_port { struct mt7621_pcie *pcie; struct phy *phy; struct reset_control *pcie_rst; + struct gpio_desc *gpio_rst; u32 slot; bool enabled; }; @@ -122,9 +118,8 @@ struct mt7621_pcie_port { * @busn: bus range * @offset: IO / Memory offset * @dev: Pointer to PCIe device + * @io_map_base: virtual memory base address for io * @ports: pointer to PCIe port information - * @perst: gpio reset - * @rst: pointer to pcie reset * @resets_inverted: depends on chip revision * reset lines are inverted. */ @@ -138,9 +133,8 @@ struct mt7621_pcie { resource_size_t mem; resource_size_t io; } offset; + unsigned long io_map_base; struct list_head ports; - struct gpio_desc *perst; - struct reset_control *rst; bool resets_inverted; }; @@ -154,6 +148,15 @@ static inline void pcie_write(struct mt7621_pcie *pcie, u32 val, u32 reg) writel(val, pcie->base + reg); } +static inline void pcie_rmw(struct mt7621_pcie *pcie, u32 reg, u32 clr, u32 set) +{ + u32 val = readl(pcie->base + reg); + + val &= ~clr; + val |= set; + writel(val, pcie->base + reg); +} + static inline u32 pcie_port_read(struct mt7621_pcie_port *port, u32 reg) { return readl(port->base + reg); @@ -207,16 +210,16 @@ static void write_config(struct mt7621_pcie *pcie, unsigned int dev, pcie_write(pcie, val, RALINK_PCI_CONFIG_DATA); } -static inline void mt7621_perst_gpio_pcie_assert(struct mt7621_pcie *pcie) +static inline void mt7621_rst_gpio_pcie_assert(struct mt7621_pcie_port *port) { - gpiod_set_value(pcie->perst, 0); - mdelay(PERST_DELAY_US); + if (port->gpio_rst) + gpiod_set_value(port->gpio_rst, 1); } -static inline void mt7621_perst_gpio_pcie_deassert(struct mt7621_pcie *pcie) +static inline void mt7621_rst_gpio_pcie_deassert(struct mt7621_pcie_port *port) { - gpiod_set_value(pcie->perst, 1); - mdelay(PERST_DELAY_US); + if (port->gpio_rst) + gpiod_set_value(port->gpio_rst, 0); } static inline bool mt7621_pcie_port_is_linkup(struct mt7621_pcie_port *port) @@ -224,6 +227,11 @@ static inline bool mt7621_pcie_port_is_linkup(struct mt7621_pcie_port *port) return (pcie_port_read(port, RALINK_PCI_STATUS) & PCIE_PORT_LINKUP) != 0; } +static inline void mt7621_pcie_port_clk_enable(struct mt7621_pcie_port *port) +{ + rt_sysc_m32(0, PCIE_PORT_CLK_EN(port->slot), RALINK_CLKCFG1); +} + static inline void mt7621_pcie_port_clk_disable(struct mt7621_pcie_port *port) { rt_sysc_m32(PCIE_PORT_CLK_EN(port->slot), 0, RALINK_CLKCFG1); @@ -249,13 +257,6 @@ static inline void mt7621_control_deassert(struct mt7621_pcie_port *port) reset_control_assert(port->pcie_rst); } -static void mt7621_reset_port(struct mt7621_pcie_port *port) -{ - mt7621_control_assert(port); - msleep(100); - mt7621_control_deassert(port); -} - static void setup_cm_memory_region(struct mt7621_pcie *pcie) { struct resource *mem_resource = &pcie->mem; @@ -292,22 +293,21 @@ static int mt7621_pci_parse_request_of_pci_ranges(struct mt7621_pcie *pcie) } for_each_of_pci_range(&parser, &range) { - struct resource *res = NULL; - switch (range.flags & IORESOURCE_TYPE_BITS) { case IORESOURCE_IO: - ioremap(range.cpu_addr, range.size); - res = &pcie->io; + pcie->io_map_base = + (unsigned long)ioremap(range.cpu_addr, + range.size); + of_pci_range_to_resource(&range, node, &pcie->io); + pcie->io.start = range.cpu_addr; + pcie->io.end = range.cpu_addr + range.size - 1; pcie->offset.io = 0x00000000UL; break; case IORESOURCE_MEM: - res = &pcie->mem; + of_pci_range_to_resource(&range, node, &pcie->mem); pcie->offset.mem = 0x00000000UL; break; } - - if (res) - of_pci_range_to_resource(&range, node, res); } err = of_pci_parse_bus_range(node, &pcie->busn); @@ -319,6 +319,8 @@ static int mt7621_pci_parse_request_of_pci_ranges(struct mt7621_pcie *pcie) pcie->busn.flags = IORESOURCE_BUS; } + set_io_port_base(pcie->io_map_base); + return 0; } @@ -356,9 +358,16 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie, snprintf(name, sizeof(name), "pcie-phy%d", slot); port->phy = devm_phy_get(dev, name); - if (IS_ERR(port->phy)) + if (IS_ERR(port->phy) && slot != 1) return PTR_ERR(port->phy); + port->gpio_rst = devm_gpiod_get_index_optional(dev, "reset", slot, + GPIOD_OUT_LOW); + if (IS_ERR(port->gpio_rst)) { + dev_err(dev, "Failed to get GPIO for PCIe%d\n", slot); + return PTR_ERR(port->gpio_rst); + } + port->slot = slot; port->pcie = pcie; @@ -375,12 +384,6 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) struct resource regs; int err; - pcie->perst = devm_gpiod_get(dev, "perst", GPIOD_OUT_HIGH); - if (IS_ERR(pcie->perst)) { - dev_err(dev, "failed to get gpio perst\n"); - return PTR_ERR(pcie->perst); - } - err = of_address_to_resource(node, 0, ®s); if (err) { dev_err(dev, "missing \"reg\" property\n"); @@ -391,12 +394,6 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie) if (IS_ERR(pcie->base)) return PTR_ERR(pcie->base); - pcie->rst = devm_reset_control_get_exclusive(dev, "pcie"); - if (PTR_ERR(pcie->rst) == -EPROBE_DEFER) { - dev_err(dev, "failed to get pcie reset control\n"); - return PTR_ERR(pcie->rst); - } - for_each_available_child_of_node(node, child) { int slot; @@ -426,12 +423,6 @@ static int mt7621_pcie_init_port(struct mt7621_pcie_port *port) u32 slot = port->slot; int err; - /* - * Any MT7621 Ralink pcie controller that doesn't have 0x0101 at - * the end of the chip_id has inverted PCI resets. - */ - mt7621_reset_port(port); - err = phy_init(port->phy); if (err) { dev_err(dev, "failed to initialize port%d phy\n", slot); @@ -450,34 +441,66 @@ static int mt7621_pcie_init_port(struct mt7621_pcie_port *port) return 0; } +static void mt7621_pcie_reset_assert(struct mt7621_pcie *pcie) +{ + struct mt7621_pcie_port *port; + + list_for_each_entry(port, &pcie->ports, list) { + /* PCIe RC reset assert */ + mt7621_control_assert(port); + + /* PCIe EP reset assert */ + mt7621_rst_gpio_pcie_assert(port); + } + + mdelay(PERST_DELAY_MS); +} + +static void mt7621_pcie_reset_rc_deassert(struct mt7621_pcie *pcie) +{ + struct mt7621_pcie_port *port; + + list_for_each_entry(port, &pcie->ports, list) + mt7621_control_deassert(port); +} + +static void mt7621_pcie_reset_ep_deassert(struct mt7621_pcie *pcie) +{ + struct mt7621_pcie_port *port; + + list_for_each_entry(port, &pcie->ports, list) + mt7621_rst_gpio_pcie_deassert(port); + + mdelay(PERST_DELAY_MS); +} + static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie) { struct device *dev = pcie->dev; struct mt7621_pcie_port *port, *tmp; - u32 val = 0; int err; rt_sysc_m32(PERST_MODE_MASK, PERST_MODE_GPIO, MT7621_GPIO_MODE); - mt7621_perst_gpio_pcie_assert(pcie); + mt7621_pcie_reset_assert(pcie); + mt7621_pcie_reset_rc_deassert(pcie); list_for_each_entry_safe(port, tmp, &pcie->ports, list) { u32 slot = port->slot; + if (slot == 1) { + port->enabled = true; + continue; + } + err = mt7621_pcie_init_port(port); if (err) { dev_err(dev, "Initiating port %d failed\n", slot); list_del(&port->list); - } else { - val = read_config(pcie, slot, PCIE_FTS_NUM); - dev_info(dev, "Port %d N_FTS = %x\n", slot, - (unsigned int)val); } } - reset_control_assert(pcie->rst); - - mt7621_perst_gpio_pcie_deassert(pcie); + mt7621_pcie_reset_ep_deassert(pcie); list_for_each_entry(port, &pcie->ports, list) { u32 slot = port->slot; @@ -485,19 +508,13 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie) if (!mt7621_pcie_port_is_linkup(port)) { dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n", slot); - phy_power_off(port->phy); + if (slot != 1) + phy_power_off(port->phy); mt7621_control_assert(port); mt7621_pcie_port_clk_disable(port); port->enabled = false; } } - - rt_sysc_m32(0x30, 2 << 4, SYSC_REG_SYSTEM_CONFIG1); - rt_sysc_m32(PCIE_CLK_GEN_EN, PCIE_CLK_GEN_DIS, RALINK_PCIE_CLK_GEN); - rt_sysc_m32(PCIE_CLK_GEN1_DIS, PCIE_CLK_GEN1_EN, RALINK_PCIE_CLK_GEN1); - rt_sysc_m32(PCIE_CLK_GEN_DIS, PCIE_CLK_GEN_EN, RALINK_PCIE_CLK_GEN); - msleep(50); - reset_control_deassert(pcie->rst); } static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port) @@ -531,10 +548,15 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie) u32 slot; u32 val; + /* Setup MEMWIN and IOWIN */ + pcie_write(pcie, 0xffffffff, RALINK_PCI_MEMBASE); + pcie_write(pcie, pcie->io.start, RALINK_PCI_IOBASE); + list_for_each_entry(port, &pcie->ports, list) { if (port->enabled) { + mt7621_pcie_port_clk_enable(port); mt7621_pcie_enable_port(port); - dev_info(dev, "PCIE%d enabled\n", num_slots_enabled); + dev_info(dev, "PCIE%d enabled\n", port->slot); num_slots_enabled++; } } @@ -554,7 +576,9 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie) static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie) { u32 pcie_link_status = 0; - u32 val = 0; + u32 n; + int i; + u32 p2p_br_devnum[PCIE_P2P_MAX]; struct mt7621_pcie_port *port; list_for_each_entry(port, &pcie->ports, list) { @@ -567,50 +591,20 @@ static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie) if (pcie_link_status == 0) return -1; - /* - * pcie(2/1/0) link status pcie2_num pcie1_num pcie0_num - * 3'b000 x x x - * 3'b001 x x 0 - * 3'b010 x 0 x - * 3'b011 x 1 0 - * 3'b100 0 x x - * 3'b101 1 x 0 - * 3'b110 1 0 x - * 3'b111 2 1 0 - */ - switch (pcie_link_status) { - case 2: - val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR); - val &= ~(MT7621_BR0_MASK | MT7621_BR1_MASK); - val |= 0x1 << MT7621_BR0_SHIFT; - val |= 0x0 << MT7621_BR1_SHIFT; - pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR); - break; - case 4: - val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR); - val &= ~MT7621_BR_ALL_MASK; - val |= 0x1 << MT7621_BR0_SHIFT; - val |= 0x2 << MT7621_BR1_SHIFT; - val |= 0x0 << MT7621_BR2_SHIFT; - pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR); - break; - case 5: - val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR); - val &= ~MT7621_BR_ALL_MASK; - val |= 0x0 << MT7621_BR0_SHIFT; - val |= 0x2 << MT7621_BR1_SHIFT; - val |= 0x1 << MT7621_BR2_SHIFT; - pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR); - break; - case 6: - val = pcie_read(pcie, RALINK_PCI_PCICFG_ADDR); - val &= ~MT7621_BR_ALL_MASK; - val |= 0x2 << MT7621_BR0_SHIFT; - val |= 0x0 << MT7621_BR1_SHIFT; - val |= 0x1 << MT7621_BR2_SHIFT; - pcie_write(pcie, val, RALINK_PCI_PCICFG_ADDR); - break; - } + n = 0; + for (i = 0; i < PCIE_P2P_MAX; i++) + if (pcie_link_status & BIT(i)) + p2p_br_devnum[i] = n++; + + for (i = 0; i < PCIE_P2P_MAX; i++) + if ((pcie_link_status & BIT(i)) == 0) + p2p_br_devnum[i] = n++; + + pcie_rmw(pcie, RALINK_PCI_PCICFG_ADDR, + PCIE_P2P_BR_DEVNUM_MASK_FULL, + (p2p_br_devnum[0] << PCIE_P2P_BR_DEVNUM0_SHIFT) | + (p2p_br_devnum[1] << PCIE_P2P_BR_DEVNUM1_SHIFT) | + (p2p_br_devnum[2] << PCIE_P2P_BR_DEVNUM2_SHIFT)); return 0; } @@ -678,11 +672,15 @@ static int mt7621_pci_probe(struct platform_device *pdev) return err; } + err = mt7621_pci_parse_request_of_pci_ranges(pcie); + if (err) { + dev_err(dev, "Error requesting pci resources from ranges"); + return err; + } + /* set resources limits */ - iomem_resource.start = 0; - iomem_resource.end = ~0UL; /* no limit */ - ioport_resource.start = 0; - ioport_resource.end = ~0UL; /* no limit */ + ioport_resource.start = pcie->io.start; + ioport_resource.end = pcie->io.end; mt7621_pcie_init_ports(pcie); @@ -694,12 +692,6 @@ static int mt7621_pci_probe(struct platform_device *pdev) mt7621_pcie_enable_ports(pcie); - err = mt7621_pci_parse_request_of_pci_ranges(pcie); - if (err) { - dev_err(dev, "Error requesting pci resources from ranges"); - return err; - } - setup_cm_memory_region(pcie); err = mt7621_pcie_request_resources(pcie, &res); @@ -731,9 +723,4 @@ static struct platform_driver mt7621_pci_driver = { }, }; -static int __init mt7621_pci_init(void) -{ - return platform_driver_register(&mt7621_pci_driver); -} - -module_init(mt7621_pci_init); +builtin_platform_driver(mt7621_pci_driver); diff --git a/drivers/staging/netlogic/platform_net.h b/drivers/staging/netlogic/platform_net.h index f152d84099a2..c8d4c13424c6 100644 --- a/drivers/staging/netlogic/platform_net.h +++ b/drivers/staging/netlogic/platform_net.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) - * +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ +/* * Copyright (c) 2003-2012 Broadcom Corporation * All Rights Reserved */ diff --git a/drivers/staging/netlogic/xlr_net.h b/drivers/staging/netlogic/xlr_net.h index 518ea809b8fa..8365b744f9b3 100644 --- a/drivers/staging/netlogic/xlr_net.h +++ b/drivers/staging/netlogic/xlr_net.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) - * +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ +/* * Copyright (c) 2003-2012 Broadcom Corporation * All Rights Reserved */ diff --git a/drivers/staging/octeon-usb/Kconfig b/drivers/staging/octeon-usb/Kconfig new file mode 100644 index 000000000000..6a5d842ee0f2 --- /dev/null +++ b/drivers/staging/octeon-usb/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +config OCTEON_USB + tristate "Cavium Networks Octeon USB support" + depends on CAVIUM_OCTEON_SOC && USB + help + This driver supports USB host controller on some Cavium + Networks' products in the Octeon family. + + To compile this driver as a module, choose M here. The module + will be called octeon-hcd. + diff --git a/drivers/staging/octeon-usb/Makefile b/drivers/staging/octeon-usb/Makefile new file mode 100644 index 000000000000..9873a0130ad5 --- /dev/null +++ b/drivers/staging/octeon-usb/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-${CONFIG_OCTEON_USB} := octeon-hcd.o diff --git a/drivers/staging/octeon-usb/TODO b/drivers/staging/octeon-usb/TODO new file mode 100644 index 000000000000..2b29acca5caa --- /dev/null +++ b/drivers/staging/octeon-usb/TODO @@ -0,0 +1,8 @@ +This driver is functional and has been tested on EdgeRouter Lite, +D-Link DSR-1000N and EBH5600 evaluation board with USB mass storage. + +TODO: + - kernel coding style + - checkpatch warnings + +Contact: Aaro Koskinen <aaro.koskinen@iki.fi> diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c new file mode 100644 index 000000000000..61471a19d4e6 --- /dev/null +++ b/drivers/staging/octeon-usb/octeon-hcd.c @@ -0,0 +1,3737 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * Copyright (C) 2008 Cavium Networks + * + * Some parts of the code were originally released under BSD license: + * + * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * * Neither the name of Cavium Networks nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written + * permission. + * + * This Software, including technical data, may be subject to U.S. export + * control laws, including the U.S. Export Administration Act and its associated + * regulations, and may be subject to export or import regulations in other + * countries. + * + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" + * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR + * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO + * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION + * OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM + * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, + * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF + * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR + * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. + */ + +#include <linux/usb.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/usb/hcd.h> +#include <linux/prefetch.h> +#include <linux/dma-mapping.h> +#include <linux/platform_device.h> + +#include <asm/octeon/octeon.h> + +#include "octeon-hcd.h" + +/** + * enum cvmx_usb_speed - the possible USB device speeds + * + * @CVMX_USB_SPEED_HIGH: Device is operation at 480Mbps + * @CVMX_USB_SPEED_FULL: Device is operation at 12Mbps + * @CVMX_USB_SPEED_LOW: Device is operation at 1.5Mbps + */ +enum cvmx_usb_speed { + CVMX_USB_SPEED_HIGH = 0, + CVMX_USB_SPEED_FULL = 1, + CVMX_USB_SPEED_LOW = 2, +}; + +/** + * enum cvmx_usb_transfer - the possible USB transfer types + * + * @CVMX_USB_TRANSFER_CONTROL: USB transfer type control for hub and status + * transfers + * @CVMX_USB_TRANSFER_ISOCHRONOUS: USB transfer type isochronous for low + * priority periodic transfers + * @CVMX_USB_TRANSFER_BULK: USB transfer type bulk for large low priority + * transfers + * @CVMX_USB_TRANSFER_INTERRUPT: USB transfer type interrupt for high priority + * periodic transfers + */ +enum cvmx_usb_transfer { + CVMX_USB_TRANSFER_CONTROL = 0, + CVMX_USB_TRANSFER_ISOCHRONOUS = 1, + CVMX_USB_TRANSFER_BULK = 2, + CVMX_USB_TRANSFER_INTERRUPT = 3, +}; + +/** + * enum cvmx_usb_direction - the transfer directions + * + * @CVMX_USB_DIRECTION_OUT: Data is transferring from Octeon to the device/host + * @CVMX_USB_DIRECTION_IN: Data is transferring from the device/host to Octeon + */ +enum cvmx_usb_direction { + CVMX_USB_DIRECTION_OUT, + CVMX_USB_DIRECTION_IN, +}; + +/** + * enum cvmx_usb_status - possible callback function status codes + * + * @CVMX_USB_STATUS_OK: The transaction / operation finished without + * any errors + * @CVMX_USB_STATUS_SHORT: FIXME: This is currently not implemented + * @CVMX_USB_STATUS_CANCEL: The transaction was canceled while in flight + * by a user call to cvmx_usb_cancel + * @CVMX_USB_STATUS_ERROR: The transaction aborted with an unexpected + * error status + * @CVMX_USB_STATUS_STALL: The transaction received a USB STALL response + * from the device + * @CVMX_USB_STATUS_XACTERR: The transaction failed with an error from the + * device even after a number of retries + * @CVMX_USB_STATUS_DATATGLERR: The transaction failed with a data toggle + * error even after a number of retries + * @CVMX_USB_STATUS_BABBLEERR: The transaction failed with a babble error + * @CVMX_USB_STATUS_FRAMEERR: The transaction failed with a frame error + * even after a number of retries + */ +enum cvmx_usb_status { + CVMX_USB_STATUS_OK, + CVMX_USB_STATUS_SHORT, + CVMX_USB_STATUS_CANCEL, + CVMX_USB_STATUS_ERROR, + CVMX_USB_STATUS_STALL, + CVMX_USB_STATUS_XACTERR, + CVMX_USB_STATUS_DATATGLERR, + CVMX_USB_STATUS_BABBLEERR, + CVMX_USB_STATUS_FRAMEERR, +}; + +/** + * struct cvmx_usb_port_status - the USB port status information + * + * @port_enabled: 1 = Usb port is enabled, 0 = disabled + * @port_over_current: 1 = Over current detected, 0 = Over current not + * detected. Octeon doesn't support over current detection. + * @port_powered: 1 = Port power is being supplied to the device, 0 = + * power is off. Octeon doesn't support turning port power + * off. + * @port_speed: Current port speed. + * @connected: 1 = A device is connected to the port, 0 = No device is + * connected. + * @connect_change: 1 = Device connected state changed since the last set + * status call. + */ +struct cvmx_usb_port_status { + u32 reserved : 25; + u32 port_enabled : 1; + u32 port_over_current : 1; + u32 port_powered : 1; + enum cvmx_usb_speed port_speed : 2; + u32 connected : 1; + u32 connect_change : 1; +}; + +/** + * struct cvmx_usb_iso_packet - descriptor for Isochronous packets + * + * @offset: This is the offset in bytes into the main buffer where this data + * is stored. + * @length: This is the length in bytes of the data. + * @status: This is the status of this individual packet transfer. + */ +struct cvmx_usb_iso_packet { + int offset; + int length; + enum cvmx_usb_status status; +}; + +/** + * enum cvmx_usb_initialize_flags - flags used by the initialization function + * + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI: The USB port uses a 12MHz crystal + * as clock source at USB_XO and + * USB_XI. + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND: The USB port uses 12/24/48MHz 2.5V + * board clock source at USB_XO. + * USB_XI should be tied to GND. + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK: Mask for clock speed field + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ: Speed of reference clock or + * crystal + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ: Speed of reference clock + * @CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ: Speed of reference clock + * @CVMX_USB_INITIALIZE_FLAGS_NO_DMA: Disable DMA and used polled IO for + * data transfer use for the USB + */ +enum cvmx_usb_initialize_flags { + CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI = 1 << 0, + CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND = 1 << 1, + CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK = 3 << 3, + CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ = 1 << 3, + CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ = 2 << 3, + CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ = 3 << 3, + /* Bits 3-4 used to encode the clock frequency */ + CVMX_USB_INITIALIZE_FLAGS_NO_DMA = 1 << 5, +}; + +/** + * enum cvmx_usb_pipe_flags - internal flags for a pipe. + * + * @CVMX_USB_PIPE_FLAGS_SCHEDULED: Used internally to determine if a pipe is + * actively using hardware. + * @CVMX_USB_PIPE_FLAGS_NEED_PING: Used internally to determine if a high speed + * pipe is in the ping state. + */ +enum cvmx_usb_pipe_flags { + CVMX_USB_PIPE_FLAGS_SCHEDULED = 1 << 17, + CVMX_USB_PIPE_FLAGS_NEED_PING = 1 << 18, +}; + +/* Maximum number of times to retry failed transactions */ +#define MAX_RETRIES 3 + +/* Maximum number of hardware channels supported by the USB block */ +#define MAX_CHANNELS 8 + +/* + * The low level hardware can transfer a maximum of this number of bytes in each + * transfer. The field is 19 bits wide + */ +#define MAX_TRANSFER_BYTES ((1 << 19) - 1) + +/* + * The low level hardware can transfer a maximum of this number of packets in + * each transfer. The field is 10 bits wide + */ +#define MAX_TRANSFER_PACKETS ((1 << 10) - 1) + +/** + * Logical transactions may take numerous low level + * transactions, especially when splits are concerned. This + * enum represents all of the possible stages a transaction can + * be in. Note that split completes are always even. This is so + * the NAK handler can backup to the previous low level + * transaction with a simple clearing of bit 0. + */ +enum cvmx_usb_stage { + CVMX_USB_STAGE_NON_CONTROL, + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE, + CVMX_USB_STAGE_SETUP, + CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE, + CVMX_USB_STAGE_DATA, + CVMX_USB_STAGE_DATA_SPLIT_COMPLETE, + CVMX_USB_STAGE_STATUS, + CVMX_USB_STAGE_STATUS_SPLIT_COMPLETE, +}; + +/** + * struct cvmx_usb_transaction - describes each pending USB transaction + * regardless of type. These are linked together + * to form a list of pending requests for a pipe. + * + * @node: List node for transactions in the pipe. + * @type: Type of transaction, duplicated of the pipe. + * @flags: State flags for this transaction. + * @buffer: User's physical buffer address to read/write. + * @buffer_length: Size of the user's buffer in bytes. + * @control_header: For control transactions, physical address of the 8 + * byte standard header. + * @iso_start_frame: For ISO transactions, the starting frame number. + * @iso_number_packets: For ISO transactions, the number of packets in the + * request. + * @iso_packets: For ISO transactions, the sub packets in the request. + * @actual_bytes: Actual bytes transfer for this transaction. + * @stage: For control transactions, the current stage. + * @urb: URB. + */ +struct cvmx_usb_transaction { + struct list_head node; + enum cvmx_usb_transfer type; + u64 buffer; + int buffer_length; + u64 control_header; + int iso_start_frame; + int iso_number_packets; + struct cvmx_usb_iso_packet *iso_packets; + int xfersize; + int pktcnt; + int retries; + int actual_bytes; + enum cvmx_usb_stage stage; + struct urb *urb; +}; + +/** + * struct cvmx_usb_pipe - a pipe represents a virtual connection between Octeon + * and some USB device. It contains a list of pending + * request to the device. + * + * @node: List node for pipe list + * @next: Pipe after this one in the list + * @transactions: List of pending transactions + * @interval: For periodic pipes, the interval between packets in + * frames + * @next_tx_frame: The next frame this pipe is allowed to transmit on + * @flags: State flags for this pipe + * @device_speed: Speed of device connected to this pipe + * @transfer_type: Type of transaction supported by this pipe + * @transfer_dir: IN or OUT. Ignored for Control + * @multi_count: Max packet in a row for the device + * @max_packet: The device's maximum packet size in bytes + * @device_addr: USB device address at other end of pipe + * @endpoint_num: USB endpoint number at other end of pipe + * @hub_device_addr: Hub address this device is connected to + * @hub_port: Hub port this device is connected to + * @pid_toggle: This toggles between 0/1 on every packet send to track + * the data pid needed + * @channel: Hardware DMA channel for this pipe + * @split_sc_frame: The low order bits of the frame number the split + * complete should be sent on + */ +struct cvmx_usb_pipe { + struct list_head node; + struct list_head transactions; + u64 interval; + u64 next_tx_frame; + enum cvmx_usb_pipe_flags flags; + enum cvmx_usb_speed device_speed; + enum cvmx_usb_transfer transfer_type; + enum cvmx_usb_direction transfer_dir; + int multi_count; + u16 max_packet; + u8 device_addr; + u8 endpoint_num; + u8 hub_device_addr; + u8 hub_port; + u8 pid_toggle; + u8 channel; + s8 split_sc_frame; +}; + +struct cvmx_usb_tx_fifo { + struct { + int channel; + int size; + u64 address; + } entry[MAX_CHANNELS + 1]; + int head; + int tail; +}; + +/** + * struct octeon_hcd - the state of the USB block + * + * lock: Serialization lock. + * init_flags: Flags passed to initialize. + * index: Which USB block this is for. + * idle_hardware_channels: Bit set for every idle hardware channel. + * usbcx_hprt: Stored port status so we don't need to read a CSR to + * determine splits. + * pipe_for_channel: Map channels to pipes. + * pipe: Storage for pipes. + * indent: Used by debug output to indent functions. + * port_status: Last port status used for change notification. + * idle_pipes: List of open pipes that have no transactions. + * active_pipes: Active pipes indexed by transfer type. + * frame_number: Increments every SOF interrupt for time keeping. + * active_split: Points to the current active split, or NULL. + */ +struct octeon_hcd { + spinlock_t lock; /* serialization lock */ + int init_flags; + int index; + int idle_hardware_channels; + union cvmx_usbcx_hprt usbcx_hprt; + struct cvmx_usb_pipe *pipe_for_channel[MAX_CHANNELS]; + int indent; + struct cvmx_usb_port_status port_status; + struct list_head idle_pipes; + struct list_head active_pipes[4]; + u64 frame_number; + struct cvmx_usb_transaction *active_split; + struct cvmx_usb_tx_fifo periodic; + struct cvmx_usb_tx_fifo nonperiodic; +}; + +/* + * This macro logically sets a single field in a CSR. It does the sequence + * read, modify, and write + */ +#define USB_SET_FIELD32(address, _union, field, value) \ + do { \ + union _union c; \ + \ + c.u32 = cvmx_usb_read_csr32(usb, address); \ + c.s.field = value; \ + cvmx_usb_write_csr32(usb, address, c.u32); \ + } while (0) + +/* Returns the IO address to push/pop stuff data from the FIFOs */ +#define USB_FIFO_ADDRESS(channel, usb_index) \ + (CVMX_USBCX_GOTGCTL(usb_index) + ((channel) + 1) * 0x1000) + +/** + * struct octeon_temp_buffer - a bounce buffer for USB transfers + * @orig_buffer: the original buffer passed by the USB stack + * @data: the newly allocated temporary buffer (excluding meta-data) + * + * Both the DMA engine and FIFO mode will always transfer full 32-bit words. If + * the buffer is too short, we need to allocate a temporary one, and this struct + * represents it. + */ +struct octeon_temp_buffer { + void *orig_buffer; + u8 data[]; +}; + +static inline struct usb_hcd *octeon_to_hcd(struct octeon_hcd *p) +{ + return container_of((void *)p, struct usb_hcd, hcd_priv); +} + +/** + * octeon_alloc_temp_buffer - allocate a temporary buffer for USB transfer + * (if needed) + * @urb: URB. + * @mem_flags: Memory allocation flags. + * + * This function allocates a temporary bounce buffer whenever it's needed + * due to HW limitations. + */ +static int octeon_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags) +{ + struct octeon_temp_buffer *temp; + + if (urb->num_sgs || urb->sg || + (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) || + !(urb->transfer_buffer_length % sizeof(u32))) + return 0; + + temp = kmalloc(ALIGN(urb->transfer_buffer_length, sizeof(u32)) + + sizeof(*temp), mem_flags); + if (!temp) + return -ENOMEM; + + temp->orig_buffer = urb->transfer_buffer; + if (usb_urb_dir_out(urb)) + memcpy(temp->data, urb->transfer_buffer, + urb->transfer_buffer_length); + urb->transfer_buffer = temp->data; + urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER; + + return 0; +} + +/** + * octeon_free_temp_buffer - free a temporary buffer used by USB transfers. + * @urb: URB. + * + * Frees a buffer allocated by octeon_alloc_temp_buffer(). + */ +static void octeon_free_temp_buffer(struct urb *urb) +{ + struct octeon_temp_buffer *temp; + size_t length; + + if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) + return; + + temp = container_of(urb->transfer_buffer, struct octeon_temp_buffer, + data); + if (usb_urb_dir_in(urb)) { + if (usb_pipeisoc(urb->pipe)) + length = urb->transfer_buffer_length; + else + length = urb->actual_length; + + memcpy(temp->orig_buffer, urb->transfer_buffer, length); + } + urb->transfer_buffer = temp->orig_buffer; + urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER; + kfree(temp); +} + +/** + * octeon_map_urb_for_dma - Octeon-specific map_urb_for_dma(). + * @hcd: USB HCD structure. + * @urb: URB. + * @mem_flags: Memory allocation flags. + */ +static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) +{ + int ret; + + ret = octeon_alloc_temp_buffer(urb, mem_flags); + if (ret) + return ret; + + ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); + if (ret) + octeon_free_temp_buffer(urb); + + return ret; +} + +/** + * octeon_unmap_urb_for_dma - Octeon-specific unmap_urb_for_dma() + * @hcd: USB HCD structure. + * @urb: URB. + */ +static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) +{ + usb_hcd_unmap_urb_for_dma(hcd, urb); + octeon_free_temp_buffer(urb); +} + +/** + * Read a USB 32bit CSR. It performs the necessary address swizzle + * for 32bit CSRs and logs the value in a readable format if + * debugging is on. + * + * @usb: USB block this access is for + * @address: 64bit address to read + * + * Returns: Result of the read + */ +static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address) +{ + return cvmx_read64_uint32(address ^ 4); +} + +/** + * Write a USB 32bit CSR. It performs the necessary address + * swizzle for 32bit CSRs and logs the value in a readable format + * if debugging is on. + * + * @usb: USB block this access is for + * @address: 64bit address to write + * @value: Value to write + */ +static inline void cvmx_usb_write_csr32(struct octeon_hcd *usb, + u64 address, u32 value) +{ + cvmx_write64_uint32(address ^ 4, value); + cvmx_read64_uint64(CVMX_USBNX_DMA0_INB_CHN0(usb->index)); +} + +/** + * Return non zero if this pipe connects to a non HIGH speed + * device through a high speed hub. + * + * @usb: USB block this access is for + * @pipe: Pipe to check + * + * Returns: Non zero if we need to do split transactions + */ +static inline int cvmx_usb_pipe_needs_split(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe) +{ + return pipe->device_speed != CVMX_USB_SPEED_HIGH && + usb->usbcx_hprt.s.prtspd == CVMX_USB_SPEED_HIGH; +} + +/** + * Trivial utility function to return the correct PID for a pipe + * + * @pipe: pipe to check + * + * Returns: PID for pipe + */ +static inline int cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe) +{ + if (pipe->pid_toggle) + return 2; /* Data1 */ + return 0; /* Data0 */ +} + +/* Loops through register until txfflsh or rxfflsh become zero.*/ +static int cvmx_wait_tx_rx(struct octeon_hcd *usb, int fflsh_type) +{ + int result; + u64 address = CVMX_USBCX_GRSTCTL(usb->index); + u64 done = cvmx_get_cycle() + 100 * + (u64)octeon_get_clock_rate / 1000000; + union cvmx_usbcx_grstctl c; + + while (1) { + c.u32 = cvmx_usb_read_csr32(usb, address); + if (fflsh_type == 0 && c.s.txfflsh == 0) { + result = 0; + break; + } else if (fflsh_type == 1 && c.s.rxfflsh == 0) { + result = 0; + break; + } else if (cvmx_get_cycle() > done) { + result = -1; + break; + } + + __delay(100); + } + return result; +} + +static void cvmx_fifo_setup(struct octeon_hcd *usb) +{ + union cvmx_usbcx_ghwcfg3 usbcx_ghwcfg3; + union cvmx_usbcx_gnptxfsiz npsiz; + union cvmx_usbcx_hptxfsiz psiz; + + usbcx_ghwcfg3.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GHWCFG3(usb->index)); + + /* + * Program the USBC_GRXFSIZ register to select the size of the receive + * FIFO (25%). + */ + USB_SET_FIELD32(CVMX_USBCX_GRXFSIZ(usb->index), cvmx_usbcx_grxfsiz, + rxfdep, usbcx_ghwcfg3.s.dfifodepth / 4); + + /* + * Program the USBC_GNPTXFSIZ register to select the size and the start + * address of the non-periodic transmit FIFO for nonperiodic + * transactions (50%). + */ + npsiz.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_GNPTXFSIZ(usb->index)); + npsiz.s.nptxfdep = usbcx_ghwcfg3.s.dfifodepth / 2; + npsiz.s.nptxfstaddr = usbcx_ghwcfg3.s.dfifodepth / 4; + cvmx_usb_write_csr32(usb, CVMX_USBCX_GNPTXFSIZ(usb->index), npsiz.u32); + + /* + * Program the USBC_HPTXFSIZ register to select the size and start + * address of the periodic transmit FIFO for periodic transactions + * (25%). + */ + psiz.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HPTXFSIZ(usb->index)); + psiz.s.ptxfsize = usbcx_ghwcfg3.s.dfifodepth / 4; + psiz.s.ptxfstaddr = 3 * usbcx_ghwcfg3.s.dfifodepth / 4; + cvmx_usb_write_csr32(usb, CVMX_USBCX_HPTXFSIZ(usb->index), psiz.u32); + + /* Flush all FIFOs */ + USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), + cvmx_usbcx_grstctl, txfnum, 0x10); + USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), + cvmx_usbcx_grstctl, txfflsh, 1); + cvmx_wait_tx_rx(usb, 0); + USB_SET_FIELD32(CVMX_USBCX_GRSTCTL(usb->index), + cvmx_usbcx_grstctl, rxfflsh, 1); + cvmx_wait_tx_rx(usb, 1); +} + +/** + * Shutdown a USB port after a call to cvmx_usb_initialize(). + * The port should be disabled with all pipes closed when this + * function is called. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_shutdown(struct octeon_hcd *usb) +{ + union cvmx_usbnx_clk_ctl usbn_clk_ctl; + + /* Make sure all pipes are closed */ + if (!list_empty(&usb->idle_pipes) || + !list_empty(&usb->active_pipes[CVMX_USB_TRANSFER_ISOCHRONOUS]) || + !list_empty(&usb->active_pipes[CVMX_USB_TRANSFER_INTERRUPT]) || + !list_empty(&usb->active_pipes[CVMX_USB_TRANSFER_CONTROL]) || + !list_empty(&usb->active_pipes[CVMX_USB_TRANSFER_BULK])) + return -EBUSY; + + /* Disable the clocks and put them in power on reset */ + usbn_clk_ctl.u64 = cvmx_read64_uint64(CVMX_USBNX_CLK_CTL(usb->index)); + usbn_clk_ctl.s.enable = 1; + usbn_clk_ctl.s.por = 1; + usbn_clk_ctl.s.hclk_rst = 1; + usbn_clk_ctl.s.prst = 0; + usbn_clk_ctl.s.hrst = 0; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + return 0; +} + +/** + * Initialize a USB port for use. This must be called before any + * other access to the Octeon USB port is made. The port starts + * off in the disabled state. + * + * @dev: Pointer to struct device for logging purposes. + * @usb: Pointer to struct octeon_hcd. + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_initialize(struct device *dev, + struct octeon_hcd *usb) +{ + int channel; + int divisor; + int retries = 0; + union cvmx_usbcx_hcfg usbcx_hcfg; + union cvmx_usbnx_clk_ctl usbn_clk_ctl; + union cvmx_usbcx_gintsts usbc_gintsts; + union cvmx_usbcx_gahbcfg usbcx_gahbcfg; + union cvmx_usbcx_gintmsk usbcx_gintmsk; + union cvmx_usbcx_gusbcfg usbcx_gusbcfg; + union cvmx_usbnx_usbp_ctl_status usbn_usbp_ctl_status; + +retry: + /* + * Power On Reset and PHY Initialization + * + * 1. Wait for DCOK to assert (nothing to do) + * + * 2a. Write USBN0/1_CLK_CTL[POR] = 1 and + * USBN0/1_CLK_CTL[HRST,PRST,HCLK_RST] = 0 + */ + usbn_clk_ctl.u64 = cvmx_read64_uint64(CVMX_USBNX_CLK_CTL(usb->index)); + usbn_clk_ctl.s.por = 1; + usbn_clk_ctl.s.hrst = 0; + usbn_clk_ctl.s.prst = 0; + usbn_clk_ctl.s.hclk_rst = 0; + usbn_clk_ctl.s.enable = 0; + /* + * 2b. Select the USB reference clock/crystal parameters by writing + * appropriate values to USBN0/1_CLK_CTL[P_C_SEL, P_RTYPE, P_COM_ON] + */ + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND) { + /* + * The USB port uses 12/24/48MHz 2.5V board clock + * source at USB_XO. USB_XI should be tied to GND. + * Most Octeon evaluation boards require this setting + */ + if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || + OCTEON_IS_MODEL(OCTEON_CN56XX) || + OCTEON_IS_MODEL(OCTEON_CN50XX)) + /* From CN56XX,CN50XX,CN31XX,CN30XX manuals */ + usbn_clk_ctl.s.p_rtype = 2; /* p_rclk=1 & p_xenbn=0 */ + else + /* From CN52XX manual */ + usbn_clk_ctl.s.p_rtype = 1; + + switch (usb->init_flags & + CVMX_USB_INITIALIZE_FLAGS_CLOCK_MHZ_MASK) { + case CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ: + usbn_clk_ctl.s.p_c_sel = 0; + break; + case CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ: + usbn_clk_ctl.s.p_c_sel = 1; + break; + case CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ: + usbn_clk_ctl.s.p_c_sel = 2; + break; + } + } else { + /* + * The USB port uses a 12MHz crystal as clock source + * at USB_XO and USB_XI + */ + if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) + /* From CN31XX,CN30XX manual */ + usbn_clk_ctl.s.p_rtype = 3; /* p_rclk=1 & p_xenbn=1 */ + else + /* From CN56XX,CN52XX,CN50XX manuals. */ + usbn_clk_ctl.s.p_rtype = 0; + + usbn_clk_ctl.s.p_c_sel = 0; + } + /* + * 2c. Select the HCLK via writing USBN0/1_CLK_CTL[DIVIDE, DIVIDE2] and + * setting USBN0/1_CLK_CTL[ENABLE] = 1. Divide the core clock down + * such that USB is as close as possible to 125Mhz + */ + divisor = DIV_ROUND_UP(octeon_get_clock_rate(), 125000000); + /* Lower than 4 doesn't seem to work properly */ + if (divisor < 4) + divisor = 4; + usbn_clk_ctl.s.divide = divisor; + usbn_clk_ctl.s.divide2 = 0; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + + /* 2d. Write USBN0/1_CLK_CTL[HCLK_RST] = 1 */ + usbn_clk_ctl.s.hclk_rst = 1; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + /* 2e. Wait 64 core-clock cycles for HCLK to stabilize */ + __delay(64); + /* + * 3. Program the power-on reset field in the USBN clock-control + * register: + * USBN_CLK_CTL[POR] = 0 + */ + usbn_clk_ctl.s.por = 0; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + /* 4. Wait 1 ms for PHY clock to start */ + mdelay(1); + /* + * 5. Program the Reset input from automatic test equipment field in the + * USBP control and status register: + * USBN_USBP_CTL_STATUS[ATE_RESET] = 1 + */ + usbn_usbp_ctl_status.u64 = + cvmx_read64_uint64(CVMX_USBNX_USBP_CTL_STATUS(usb->index)); + usbn_usbp_ctl_status.s.ate_reset = 1; + cvmx_write64_uint64(CVMX_USBNX_USBP_CTL_STATUS(usb->index), + usbn_usbp_ctl_status.u64); + /* 6. Wait 10 cycles */ + __delay(10); + /* + * 7. Clear ATE_RESET field in the USBN clock-control register: + * USBN_USBP_CTL_STATUS[ATE_RESET] = 0 + */ + usbn_usbp_ctl_status.s.ate_reset = 0; + cvmx_write64_uint64(CVMX_USBNX_USBP_CTL_STATUS(usb->index), + usbn_usbp_ctl_status.u64); + /* + * 8. Program the PHY reset field in the USBN clock-control register: + * USBN_CLK_CTL[PRST] = 1 + */ + usbn_clk_ctl.s.prst = 1; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + /* + * 9. Program the USBP control and status register to select host or + * device mode. USBN_USBP_CTL_STATUS[HST_MODE] = 0 for host, = 1 for + * device + */ + usbn_usbp_ctl_status.s.hst_mode = 0; + cvmx_write64_uint64(CVMX_USBNX_USBP_CTL_STATUS(usb->index), + usbn_usbp_ctl_status.u64); + /* 10. Wait 1 us */ + udelay(1); + /* + * 11. Program the hreset_n field in the USBN clock-control register: + * USBN_CLK_CTL[HRST] = 1 + */ + usbn_clk_ctl.s.hrst = 1; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + /* 12. Proceed to USB core initialization */ + usbn_clk_ctl.s.enable = 1; + cvmx_write64_uint64(CVMX_USBNX_CLK_CTL(usb->index), usbn_clk_ctl.u64); + udelay(1); + + /* + * USB Core Initialization + * + * 1. Read USBC_GHWCFG1, USBC_GHWCFG2, USBC_GHWCFG3, USBC_GHWCFG4 to + * determine USB core configuration parameters. + * + * Nothing needed + * + * 2. Program the following fields in the global AHB configuration + * register (USBC_GAHBCFG) + * DMA mode, USBC_GAHBCFG[DMAEn]: 1 = DMA mode, 0 = slave mode + * Burst length, USBC_GAHBCFG[HBSTLEN] = 0 + * Nonperiodic TxFIFO empty level (slave mode only), + * USBC_GAHBCFG[NPTXFEMPLVL] + * Periodic TxFIFO empty level (slave mode only), + * USBC_GAHBCFG[PTXFEMPLVL] + * Global interrupt mask, USBC_GAHBCFG[GLBLINTRMSK] = 1 + */ + usbcx_gahbcfg.u32 = 0; + usbcx_gahbcfg.s.dmaen = !(usb->init_flags & + CVMX_USB_INITIALIZE_FLAGS_NO_DMA); + usbcx_gahbcfg.s.hbstlen = 0; + usbcx_gahbcfg.s.nptxfemplvl = 1; + usbcx_gahbcfg.s.ptxfemplvl = 1; + usbcx_gahbcfg.s.glblintrmsk = 1; + cvmx_usb_write_csr32(usb, CVMX_USBCX_GAHBCFG(usb->index), + usbcx_gahbcfg.u32); + + /* + * 3. Program the following fields in USBC_GUSBCFG register. + * HS/FS timeout calibration, USBC_GUSBCFG[TOUTCAL] = 0 + * ULPI DDR select, USBC_GUSBCFG[DDRSEL] = 0 + * USB turnaround time, USBC_GUSBCFG[USBTRDTIM] = 0x5 + * PHY low-power clock select, USBC_GUSBCFG[PHYLPWRCLKSEL] = 0 + */ + usbcx_gusbcfg.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GUSBCFG(usb->index)); + usbcx_gusbcfg.s.toutcal = 0; + usbcx_gusbcfg.s.ddrsel = 0; + usbcx_gusbcfg.s.usbtrdtim = 0x5; + usbcx_gusbcfg.s.phylpwrclksel = 0; + cvmx_usb_write_csr32(usb, CVMX_USBCX_GUSBCFG(usb->index), + usbcx_gusbcfg.u32); + + /* + * 4. The software must unmask the following bits in the USBC_GINTMSK + * register. + * OTG interrupt mask, USBC_GINTMSK[OTGINTMSK] = 1 + * Mode mismatch interrupt mask, USBC_GINTMSK[MODEMISMSK] = 1 + */ + usbcx_gintmsk.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GINTMSK(usb->index)); + usbcx_gintmsk.s.otgintmsk = 1; + usbcx_gintmsk.s.modemismsk = 1; + usbcx_gintmsk.s.hchintmsk = 1; + usbcx_gintmsk.s.sofmsk = 0; + /* We need RX FIFO interrupts if we don't have DMA */ + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) + usbcx_gintmsk.s.rxflvlmsk = 1; + cvmx_usb_write_csr32(usb, CVMX_USBCX_GINTMSK(usb->index), + usbcx_gintmsk.u32); + + /* + * Disable all channel interrupts. We'll enable them per channel later. + */ + for (channel = 0; channel < 8; channel++) + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCINTMSKX(channel, usb->index), + 0); + + /* + * Host Port Initialization + * + * 1. Program the host-port interrupt-mask field to unmask, + * USBC_GINTMSK[PRTINT] = 1 + */ + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, prtintmsk, 1); + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, disconnintmsk, 1); + + /* + * 2. Program the USBC_HCFG register to select full-speed host + * or high-speed host. + */ + usbcx_hcfg.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HCFG(usb->index)); + usbcx_hcfg.s.fslssupp = 0; + usbcx_hcfg.s.fslspclksel = 0; + cvmx_usb_write_csr32(usb, CVMX_USBCX_HCFG(usb->index), usbcx_hcfg.u32); + + cvmx_fifo_setup(usb); + + /* + * If the controller is getting port events right after the reset, it + * means the initialization failed. Try resetting the controller again + * in such case. This is seen to happen after cold boot on DSR-1000N. + */ + usbc_gintsts.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GINTSTS(usb->index)); + cvmx_usb_write_csr32(usb, CVMX_USBCX_GINTSTS(usb->index), + usbc_gintsts.u32); + dev_dbg(dev, "gintsts after reset: 0x%x\n", (int)usbc_gintsts.u32); + if (!usbc_gintsts.s.disconnint && !usbc_gintsts.s.prtint) + return 0; + if (retries++ >= 5) + return -EAGAIN; + dev_info(dev, "controller reset failed (gintsts=0x%x) - retrying\n", + (int)usbc_gintsts.u32); + msleep(50); + cvmx_usb_shutdown(usb); + msleep(50); + goto retry; +} + +/** + * Reset a USB port. After this call succeeds, the USB port is + * online and servicing requests. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + */ +static void cvmx_usb_reset_port(struct octeon_hcd *usb) +{ + usb->usbcx_hprt.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HPRT(usb->index)); + + /* Program the port reset bit to start the reset process */ + USB_SET_FIELD32(CVMX_USBCX_HPRT(usb->index), cvmx_usbcx_hprt, + prtrst, 1); + + /* + * Wait at least 50ms (high speed), or 10ms (full speed) for the reset + * process to complete. + */ + mdelay(50); + + /* Program the port reset bit to 0, USBC_HPRT[PRTRST] = 0 */ + USB_SET_FIELD32(CVMX_USBCX_HPRT(usb->index), cvmx_usbcx_hprt, + prtrst, 0); + + /* + * Read the port speed field to get the enumerated speed, + * USBC_HPRT[PRTSPD]. + */ + usb->usbcx_hprt.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HPRT(usb->index)); +} + +/** + * Disable a USB port. After this call the USB port will not + * generate data transfers and will not generate events. + * Transactions in process will fail and call their + * associated callbacks. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_disable(struct octeon_hcd *usb) +{ + /* Disable the port */ + USB_SET_FIELD32(CVMX_USBCX_HPRT(usb->index), cvmx_usbcx_hprt, + prtena, 1); + return 0; +} + +/** + * Get the current state of the USB port. Use this call to + * determine if the usb port has anything connected, is enabled, + * or has some sort of error condition. The return value of this + * call has "changed" bits to signal of the value of some fields + * have changed between calls. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * + * Returns: Port status information + */ +static struct cvmx_usb_port_status cvmx_usb_get_status(struct octeon_hcd *usb) +{ + union cvmx_usbcx_hprt usbc_hprt; + struct cvmx_usb_port_status result; + + memset(&result, 0, sizeof(result)); + + usbc_hprt.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HPRT(usb->index)); + result.port_enabled = usbc_hprt.s.prtena; + result.port_over_current = usbc_hprt.s.prtovrcurract; + result.port_powered = usbc_hprt.s.prtpwr; + result.port_speed = usbc_hprt.s.prtspd; + result.connected = usbc_hprt.s.prtconnsts; + result.connect_change = + result.connected != usb->port_status.connected; + + return result; +} + +/** + * Open a virtual pipe between the host and a USB device. A pipe + * must be opened before data can be transferred between a device + * and Octeon. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @device_addr: + * USB device address to open the pipe to + * (0-127). + * @endpoint_num: + * USB endpoint number to open the pipe to + * (0-15). + * @device_speed: + * The speed of the device the pipe is going + * to. This must match the device's speed, + * which may be different than the port speed. + * @max_packet: The maximum packet length the device can + * transmit/receive (low speed=0-8, full + * speed=0-1023, high speed=0-1024). This value + * comes from the standard endpoint descriptor + * field wMaxPacketSize bits <10:0>. + * @transfer_type: + * The type of transfer this pipe is for. + * @transfer_dir: + * The direction the pipe is in. This is not + * used for control pipes. + * @interval: For ISOCHRONOUS and INTERRUPT transfers, + * this is how often the transfer is scheduled + * for. All other transfers should specify + * zero. The units are in frames (8000/sec at + * high speed, 1000/sec for full speed). + * @multi_count: + * For high speed devices, this is the maximum + * allowed number of packet per microframe. + * Specify zero for non high speed devices. This + * value comes from the standard endpoint descriptor + * field wMaxPacketSize bits <12:11>. + * @hub_device_addr: + * Hub device address this device is connected + * to. Devices connected directly to Octeon + * use zero. This is only used when the device + * is full/low speed behind a high speed hub. + * The address will be of the high speed hub, + * not and full speed hubs after it. + * @hub_port: Which port on the hub the device is + * connected. Use zero for devices connected + * directly to Octeon. Like hub_device_addr, + * this is only used for full/low speed + * devices behind a high speed hub. + * + * Returns: A non-NULL value is a pipe. NULL means an error. + */ +static struct cvmx_usb_pipe *cvmx_usb_open_pipe(struct octeon_hcd *usb, + int device_addr, + int endpoint_num, + enum cvmx_usb_speed + device_speed, + int max_packet, + enum cvmx_usb_transfer + transfer_type, + enum cvmx_usb_direction + transfer_dir, + int interval, int multi_count, + int hub_device_addr, + int hub_port) +{ + struct cvmx_usb_pipe *pipe; + + pipe = kzalloc(sizeof(*pipe), GFP_ATOMIC); + if (!pipe) + return NULL; + if ((device_speed == CVMX_USB_SPEED_HIGH) && + (transfer_dir == CVMX_USB_DIRECTION_OUT) && + (transfer_type == CVMX_USB_TRANSFER_BULK)) + pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING; + pipe->device_addr = device_addr; + pipe->endpoint_num = endpoint_num; + pipe->device_speed = device_speed; + pipe->max_packet = max_packet; + pipe->transfer_type = transfer_type; + pipe->transfer_dir = transfer_dir; + INIT_LIST_HEAD(&pipe->transactions); + + /* + * All pipes use interval to rate limit NAK processing. Force an + * interval if one wasn't supplied + */ + if (!interval) + interval = 1; + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + pipe->interval = interval * 8; + /* Force start splits to be schedule on uFrame 0 */ + pipe->next_tx_frame = ((usb->frame_number + 7) & ~7) + + pipe->interval; + } else { + pipe->interval = interval; + pipe->next_tx_frame = usb->frame_number + pipe->interval; + } + pipe->multi_count = multi_count; + pipe->hub_device_addr = hub_device_addr; + pipe->hub_port = hub_port; + pipe->pid_toggle = 0; + pipe->split_sc_frame = -1; + list_add_tail(&pipe->node, &usb->idle_pipes); + + /* + * We don't need to tell the hardware about this pipe yet since + * it doesn't have any submitted requests + */ + + return pipe; +} + +/** + * Poll the RX FIFOs and remove data as needed. This function is only used + * in non DMA mode. It is very important that this function be called quickly + * enough to prevent FIFO overflow. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + */ +static void cvmx_usb_poll_rx_fifo(struct octeon_hcd *usb) +{ + union cvmx_usbcx_grxstsph rx_status; + int channel; + int bytes; + u64 address; + u32 *ptr; + + rx_status.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GRXSTSPH(usb->index)); + /* Only read data if IN data is there */ + if (rx_status.s.pktsts != 2) + return; + /* Check if no data is available */ + if (!rx_status.s.bcnt) + return; + + channel = rx_status.s.chnum; + bytes = rx_status.s.bcnt; + if (!bytes) + return; + + /* Get where the DMA engine would have written this data */ + address = cvmx_read64_uint64(CVMX_USBNX_DMA0_INB_CHN0(usb->index) + + channel * 8); + + ptr = cvmx_phys_to_ptr(address); + cvmx_write64_uint64(CVMX_USBNX_DMA0_INB_CHN0(usb->index) + channel * 8, + address + bytes); + + /* Loop writing the FIFO data for this packet into memory */ + while (bytes > 0) { + *ptr++ = cvmx_usb_read_csr32(usb, + USB_FIFO_ADDRESS(channel, usb->index)); + bytes -= 4; + } + CVMX_SYNCW; +} + +/** + * Fill the TX hardware fifo with data out of the software + * fifos + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @fifo: Software fifo to use + * @available: Amount of space in the hardware fifo + * + * Returns: Non zero if the hardware fifo was too small and needs + * to be serviced again. + */ +static int cvmx_usb_fill_tx_hw(struct octeon_hcd *usb, + struct cvmx_usb_tx_fifo *fifo, int available) +{ + /* + * We're done either when there isn't anymore space or the software FIFO + * is empty + */ + while (available && (fifo->head != fifo->tail)) { + int i = fifo->tail; + const u32 *ptr = cvmx_phys_to_ptr(fifo->entry[i].address); + u64 csr_address = USB_FIFO_ADDRESS(fifo->entry[i].channel, + usb->index) ^ 4; + int words = available; + + /* Limit the amount of data to what the SW fifo has */ + if (fifo->entry[i].size <= available) { + words = fifo->entry[i].size; + fifo->tail++; + if (fifo->tail > MAX_CHANNELS) + fifo->tail = 0; + } + + /* Update the next locations and counts */ + available -= words; + fifo->entry[i].address += words * 4; + fifo->entry[i].size -= words; + + /* + * Write the HW fifo data. The read every three writes is due + * to an errata on CN3XXX chips + */ + while (words > 3) { + cvmx_write64_uint32(csr_address, *ptr++); + cvmx_write64_uint32(csr_address, *ptr++); + cvmx_write64_uint32(csr_address, *ptr++); + cvmx_read64_uint64( + CVMX_USBNX_DMA0_INB_CHN0(usb->index)); + words -= 3; + } + cvmx_write64_uint32(csr_address, *ptr++); + if (--words) { + cvmx_write64_uint32(csr_address, *ptr++); + if (--words) + cvmx_write64_uint32(csr_address, *ptr++); + } + cvmx_read64_uint64(CVMX_USBNX_DMA0_INB_CHN0(usb->index)); + } + return fifo->head != fifo->tail; +} + +/** + * Check the hardware FIFOs and fill them as needed + * + * @usb: USB device state populated by cvmx_usb_initialize(). + */ +static void cvmx_usb_poll_tx_fifo(struct octeon_hcd *usb) +{ + if (usb->periodic.head != usb->periodic.tail) { + union cvmx_usbcx_hptxsts tx_status; + + tx_status.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HPTXSTS(usb->index)); + if (cvmx_usb_fill_tx_hw(usb, &usb->periodic, + tx_status.s.ptxfspcavail)) + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, ptxfempmsk, 1); + else + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, ptxfempmsk, 0); + } + + if (usb->nonperiodic.head != usb->nonperiodic.tail) { + union cvmx_usbcx_gnptxsts tx_status; + + tx_status.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GNPTXSTS(usb->index)); + if (cvmx_usb_fill_tx_hw(usb, &usb->nonperiodic, + tx_status.s.nptxfspcavail)) + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, nptxfempmsk, 1); + else + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, nptxfempmsk, 0); + } +} + +/** + * Fill the TX FIFO with an outgoing packet + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @channel: Channel number to get packet from + */ +static void cvmx_usb_fill_tx_fifo(struct octeon_hcd *usb, int channel) +{ + union cvmx_usbcx_hccharx hcchar; + union cvmx_usbcx_hcspltx usbc_hcsplt; + union cvmx_usbcx_hctsizx usbc_hctsiz; + struct cvmx_usb_tx_fifo *fifo; + + /* We only need to fill data on outbound channels */ + hcchar.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCCHARX(channel, usb->index)); + if (hcchar.s.epdir != CVMX_USB_DIRECTION_OUT) + return; + + /* OUT Splits only have data on the start and not the complete */ + usbc_hcsplt.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCSPLTX(channel, usb->index)); + if (usbc_hcsplt.s.spltena && usbc_hcsplt.s.compsplt) + return; + + /* + * Find out how many bytes we need to fill and convert it into 32bit + * words. + */ + usbc_hctsiz.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCTSIZX(channel, usb->index)); + if (!usbc_hctsiz.s.xfersize) + return; + + if ((hcchar.s.eptype == CVMX_USB_TRANSFER_INTERRUPT) || + (hcchar.s.eptype == CVMX_USB_TRANSFER_ISOCHRONOUS)) + fifo = &usb->periodic; + else + fifo = &usb->nonperiodic; + + fifo->entry[fifo->head].channel = channel; + fifo->entry[fifo->head].address = + cvmx_read64_uint64(CVMX_USBNX_DMA0_OUTB_CHN0(usb->index) + + channel * 8); + fifo->entry[fifo->head].size = (usbc_hctsiz.s.xfersize + 3) >> 2; + fifo->head++; + if (fifo->head > MAX_CHANNELS) + fifo->head = 0; + + cvmx_usb_poll_tx_fifo(usb); +} + +/** + * Perform channel specific setup for Control transactions. All + * the generic stuff will already have been done in cvmx_usb_start_channel(). + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @channel: Channel to setup + * @pipe: Pipe for control transaction + */ +static void cvmx_usb_start_channel_control(struct octeon_hcd *usb, + int channel, + struct cvmx_usb_pipe *pipe) +{ + struct usb_hcd *hcd = octeon_to_hcd(usb); + struct device *dev = hcd->self.controller; + struct cvmx_usb_transaction *transaction = + list_first_entry(&pipe->transactions, typeof(*transaction), + node); + struct usb_ctrlrequest *header = + cvmx_phys_to_ptr(transaction->control_header); + int bytes_to_transfer = transaction->buffer_length - + transaction->actual_bytes; + int packets_to_transfer; + union cvmx_usbcx_hctsizx usbc_hctsiz; + + usbc_hctsiz.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCTSIZX(channel, usb->index)); + + switch (transaction->stage) { + case CVMX_USB_STAGE_NON_CONTROL: + case CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE: + dev_err(dev, "%s: ERROR - Non control stage\n", __func__); + break; + case CVMX_USB_STAGE_SETUP: + usbc_hctsiz.s.pid = 3; /* Setup */ + bytes_to_transfer = sizeof(*header); + /* All Control operations start with a setup going OUT */ + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + CVMX_USB_DIRECTION_OUT); + /* + * Setup send the control header instead of the buffer data. The + * buffer data will be used in the next stage + */ + cvmx_write64_uint64(CVMX_USBNX_DMA0_OUTB_CHN0(usb->index) + + channel * 8, + transaction->control_header); + break; + case CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE: + usbc_hctsiz.s.pid = 3; /* Setup */ + bytes_to_transfer = 0; + /* All Control operations start with a setup going OUT */ + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + CVMX_USB_DIRECTION_OUT); + + USB_SET_FIELD32(CVMX_USBCX_HCSPLTX(channel, usb->index), + cvmx_usbcx_hcspltx, compsplt, 1); + break; + case CVMX_USB_STAGE_DATA: + usbc_hctsiz.s.pid = cvmx_usb_get_data_pid(pipe); + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + if (header->bRequestType & USB_DIR_IN) + bytes_to_transfer = 0; + else if (bytes_to_transfer > pipe->max_packet) + bytes_to_transfer = pipe->max_packet; + } + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + ((header->bRequestType & USB_DIR_IN) ? + CVMX_USB_DIRECTION_IN : + CVMX_USB_DIRECTION_OUT)); + break; + case CVMX_USB_STAGE_DATA_SPLIT_COMPLETE: + usbc_hctsiz.s.pid = cvmx_usb_get_data_pid(pipe); + if (!(header->bRequestType & USB_DIR_IN)) + bytes_to_transfer = 0; + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + ((header->bRequestType & USB_DIR_IN) ? + CVMX_USB_DIRECTION_IN : + CVMX_USB_DIRECTION_OUT)); + USB_SET_FIELD32(CVMX_USBCX_HCSPLTX(channel, usb->index), + cvmx_usbcx_hcspltx, compsplt, 1); + break; + case CVMX_USB_STAGE_STATUS: + usbc_hctsiz.s.pid = cvmx_usb_get_data_pid(pipe); + bytes_to_transfer = 0; + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + ((header->bRequestType & USB_DIR_IN) ? + CVMX_USB_DIRECTION_OUT : + CVMX_USB_DIRECTION_IN)); + break; + case CVMX_USB_STAGE_STATUS_SPLIT_COMPLETE: + usbc_hctsiz.s.pid = cvmx_usb_get_data_pid(pipe); + bytes_to_transfer = 0; + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, epdir, + ((header->bRequestType & USB_DIR_IN) ? + CVMX_USB_DIRECTION_OUT : + CVMX_USB_DIRECTION_IN)); + USB_SET_FIELD32(CVMX_USBCX_HCSPLTX(channel, usb->index), + cvmx_usbcx_hcspltx, compsplt, 1); + break; + } + + /* + * Make sure the transfer never exceeds the byte limit of the hardware. + * Further bytes will be sent as continued transactions + */ + if (bytes_to_transfer > MAX_TRANSFER_BYTES) { + /* Round MAX_TRANSFER_BYTES to a multiple of out packet size */ + bytes_to_transfer = MAX_TRANSFER_BYTES / pipe->max_packet; + bytes_to_transfer *= pipe->max_packet; + } + + /* + * Calculate the number of packets to transfer. If the length is zero + * we still need to transfer one packet + */ + packets_to_transfer = DIV_ROUND_UP(bytes_to_transfer, + pipe->max_packet); + if (packets_to_transfer == 0) { + packets_to_transfer = 1; + } else if ((packets_to_transfer > 1) && + (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA)) { + /* + * Limit to one packet when not using DMA. Channels must be + * restarted between every packet for IN transactions, so there + * is no reason to do multiple packets in a row + */ + packets_to_transfer = 1; + bytes_to_transfer = packets_to_transfer * pipe->max_packet; + } else if (packets_to_transfer > MAX_TRANSFER_PACKETS) { + /* + * Limit the number of packet and data transferred to what the + * hardware can handle + */ + packets_to_transfer = MAX_TRANSFER_PACKETS; + bytes_to_transfer = packets_to_transfer * pipe->max_packet; + } + + usbc_hctsiz.s.xfersize = bytes_to_transfer; + usbc_hctsiz.s.pktcnt = packets_to_transfer; + + cvmx_usb_write_csr32(usb, CVMX_USBCX_HCTSIZX(channel, usb->index), + usbc_hctsiz.u32); +} + +/** + * Start a channel to perform the pipe's head transaction + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @channel: Channel to setup + * @pipe: Pipe to start + */ +static void cvmx_usb_start_channel(struct octeon_hcd *usb, int channel, + struct cvmx_usb_pipe *pipe) +{ + struct cvmx_usb_transaction *transaction = + list_first_entry(&pipe->transactions, typeof(*transaction), + node); + + /* Make sure all writes to the DMA region get flushed */ + CVMX_SYNCW; + + /* Attach the channel to the pipe */ + usb->pipe_for_channel[channel] = pipe; + pipe->channel = channel; + pipe->flags |= CVMX_USB_PIPE_FLAGS_SCHEDULED; + + /* Mark this channel as in use */ + usb->idle_hardware_channels &= ~(1 << channel); + + /* Enable the channel interrupt bits */ + { + union cvmx_usbcx_hcintx usbc_hcint; + union cvmx_usbcx_hcintmskx usbc_hcintmsk; + union cvmx_usbcx_haintmsk usbc_haintmsk; + + /* Clear all channel status bits */ + usbc_hcint.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCINTX(channel, usb->index)); + + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCINTX(channel, usb->index), + usbc_hcint.u32); + + usbc_hcintmsk.u32 = 0; + usbc_hcintmsk.s.chhltdmsk = 1; + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) { + /* + * Channels need these extra interrupts when we aren't + * in DMA mode. + */ + usbc_hcintmsk.s.datatglerrmsk = 1; + usbc_hcintmsk.s.frmovrunmsk = 1; + usbc_hcintmsk.s.bblerrmsk = 1; + usbc_hcintmsk.s.xacterrmsk = 1; + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + /* + * Splits don't generate xfercompl, so we need + * ACK and NYET. + */ + usbc_hcintmsk.s.nyetmsk = 1; + usbc_hcintmsk.s.ackmsk = 1; + } + usbc_hcintmsk.s.nakmsk = 1; + usbc_hcintmsk.s.stallmsk = 1; + usbc_hcintmsk.s.xfercomplmsk = 1; + } + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCINTMSKX(channel, usb->index), + usbc_hcintmsk.u32); + + /* Enable the channel interrupt to propagate */ + usbc_haintmsk.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HAINTMSK(usb->index)); + usbc_haintmsk.s.haintmsk |= 1 << channel; + cvmx_usb_write_csr32(usb, CVMX_USBCX_HAINTMSK(usb->index), + usbc_haintmsk.u32); + } + + /* Setup the location the DMA engine uses. */ + { + u64 reg; + u64 dma_address = transaction->buffer + + transaction->actual_bytes; + + if (transaction->type == CVMX_USB_TRANSFER_ISOCHRONOUS) + dma_address = transaction->buffer + + transaction->iso_packets[0].offset + + transaction->actual_bytes; + + if (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) + reg = CVMX_USBNX_DMA0_OUTB_CHN0(usb->index); + else + reg = CVMX_USBNX_DMA0_INB_CHN0(usb->index); + cvmx_write64_uint64(reg + channel * 8, dma_address); + } + + /* Setup both the size of the transfer and the SPLIT characteristics */ + { + union cvmx_usbcx_hcspltx usbc_hcsplt = {.u32 = 0}; + union cvmx_usbcx_hctsizx usbc_hctsiz = {.u32 = 0}; + int packets_to_transfer; + int bytes_to_transfer = transaction->buffer_length - + transaction->actual_bytes; + + /* + * ISOCHRONOUS transactions store each individual transfer size + * in the packet structure, not the global buffer_length + */ + if (transaction->type == CVMX_USB_TRANSFER_ISOCHRONOUS) + bytes_to_transfer = + transaction->iso_packets[0].length - + transaction->actual_bytes; + + /* + * We need to do split transactions when we are talking to non + * high speed devices that are behind a high speed hub + */ + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + /* + * On the start split phase (stage is even) record the + * frame number we will need to send the split complete. + * We only store the lower two bits since the time ahead + * can only be two frames + */ + if ((transaction->stage & 1) == 0) { + if (transaction->type == CVMX_USB_TRANSFER_BULK) + pipe->split_sc_frame = + (usb->frame_number + 1) & 0x7f; + else + pipe->split_sc_frame = + (usb->frame_number + 2) & 0x7f; + } else { + pipe->split_sc_frame = -1; + } + + usbc_hcsplt.s.spltena = 1; + usbc_hcsplt.s.hubaddr = pipe->hub_device_addr; + usbc_hcsplt.s.prtaddr = pipe->hub_port; + usbc_hcsplt.s.compsplt = (transaction->stage == + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE); + + /* + * SPLIT transactions can only ever transmit one data + * packet so limit the transfer size to the max packet + * size + */ + if (bytes_to_transfer > pipe->max_packet) + bytes_to_transfer = pipe->max_packet; + + /* + * ISOCHRONOUS OUT splits are unique in that they limit + * data transfers to 188 byte chunks representing the + * begin/middle/end of the data or all + */ + if (!usbc_hcsplt.s.compsplt && + (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) && + (pipe->transfer_type == + CVMX_USB_TRANSFER_ISOCHRONOUS)) { + /* + * Clear the split complete frame number as + * there isn't going to be a split complete + */ + pipe->split_sc_frame = -1; + /* + * See if we've started this transfer and sent + * data + */ + if (transaction->actual_bytes == 0) { + /* + * Nothing sent yet, this is either a + * begin or the entire payload + */ + if (bytes_to_transfer <= 188) + /* Entire payload in one go */ + usbc_hcsplt.s.xactpos = 3; + else + /* First part of payload */ + usbc_hcsplt.s.xactpos = 2; + } else { + /* + * Continuing the previous data, we must + * either be in the middle or at the end + */ + if (bytes_to_transfer <= 188) + /* End of payload */ + usbc_hcsplt.s.xactpos = 1; + else + /* Middle of payload */ + usbc_hcsplt.s.xactpos = 0; + } + /* + * Again, the transfer size is limited to 188 + * bytes + */ + if (bytes_to_transfer > 188) + bytes_to_transfer = 188; + } + } + + /* + * Make sure the transfer never exceeds the byte limit of the + * hardware. Further bytes will be sent as continued + * transactions + */ + if (bytes_to_transfer > MAX_TRANSFER_BYTES) { + /* + * Round MAX_TRANSFER_BYTES to a multiple of out packet + * size + */ + bytes_to_transfer = MAX_TRANSFER_BYTES / + pipe->max_packet; + bytes_to_transfer *= pipe->max_packet; + } + + /* + * Calculate the number of packets to transfer. If the length is + * zero we still need to transfer one packet + */ + packets_to_transfer = + DIV_ROUND_UP(bytes_to_transfer, pipe->max_packet); + if (packets_to_transfer == 0) { + packets_to_transfer = 1; + } else if ((packets_to_transfer > 1) && + (usb->init_flags & + CVMX_USB_INITIALIZE_FLAGS_NO_DMA)) { + /* + * Limit to one packet when not using DMA. Channels must + * be restarted between every packet for IN + * transactions, so there is no reason to do multiple + * packets in a row + */ + packets_to_transfer = 1; + bytes_to_transfer = packets_to_transfer * + pipe->max_packet; + } else if (packets_to_transfer > MAX_TRANSFER_PACKETS) { + /* + * Limit the number of packet and data transferred to + * what the hardware can handle + */ + packets_to_transfer = MAX_TRANSFER_PACKETS; + bytes_to_transfer = packets_to_transfer * + pipe->max_packet; + } + + usbc_hctsiz.s.xfersize = bytes_to_transfer; + usbc_hctsiz.s.pktcnt = packets_to_transfer; + + /* Update the DATA0/DATA1 toggle */ + usbc_hctsiz.s.pid = cvmx_usb_get_data_pid(pipe); + /* + * High speed pipes may need a hardware ping before they start + */ + if (pipe->flags & CVMX_USB_PIPE_FLAGS_NEED_PING) + usbc_hctsiz.s.dopng = 1; + + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCSPLTX(channel, usb->index), + usbc_hcsplt.u32); + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCTSIZX(channel, usb->index), + usbc_hctsiz.u32); + } + + /* Setup the Host Channel Characteristics Register */ + { + union cvmx_usbcx_hccharx usbc_hcchar = {.u32 = 0}; + + /* + * Set the startframe odd/even properly. This is only used for + * periodic + */ + usbc_hcchar.s.oddfrm = usb->frame_number & 1; + + /* + * Set the number of back to back packets allowed by this + * endpoint. Split transactions interpret "ec" as the number of + * immediate retries of failure. These retries happen too + * quickly, so we disable these entirely for splits + */ + if (cvmx_usb_pipe_needs_split(usb, pipe)) + usbc_hcchar.s.ec = 1; + else if (pipe->multi_count < 1) + usbc_hcchar.s.ec = 1; + else if (pipe->multi_count > 3) + usbc_hcchar.s.ec = 3; + else + usbc_hcchar.s.ec = pipe->multi_count; + + /* Set the rest of the endpoint specific settings */ + usbc_hcchar.s.devaddr = pipe->device_addr; + usbc_hcchar.s.eptype = transaction->type; + usbc_hcchar.s.lspddev = + (pipe->device_speed == CVMX_USB_SPEED_LOW); + usbc_hcchar.s.epdir = pipe->transfer_dir; + usbc_hcchar.s.epnum = pipe->endpoint_num; + usbc_hcchar.s.mps = pipe->max_packet; + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCCHARX(channel, usb->index), + usbc_hcchar.u32); + } + + /* Do transaction type specific fixups as needed */ + switch (transaction->type) { + case CVMX_USB_TRANSFER_CONTROL: + cvmx_usb_start_channel_control(usb, channel, pipe); + break; + case CVMX_USB_TRANSFER_BULK: + case CVMX_USB_TRANSFER_INTERRUPT: + break; + case CVMX_USB_TRANSFER_ISOCHRONOUS: + if (!cvmx_usb_pipe_needs_split(usb, pipe)) { + /* + * ISO transactions require different PIDs depending on + * direction and how many packets are needed + */ + if (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) { + if (pipe->multi_count < 2) /* Need DATA0 */ + USB_SET_FIELD32( + CVMX_USBCX_HCTSIZX(channel, + usb->index), + cvmx_usbcx_hctsizx, pid, 0); + else /* Need MDATA */ + USB_SET_FIELD32( + CVMX_USBCX_HCTSIZX(channel, + usb->index), + cvmx_usbcx_hctsizx, pid, 3); + } + } + break; + } + { + union cvmx_usbcx_hctsizx usbc_hctsiz = { .u32 = + cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCTSIZX(channel, + usb->index)) + }; + transaction->xfersize = usbc_hctsiz.s.xfersize; + transaction->pktcnt = usbc_hctsiz.s.pktcnt; + } + /* Remember when we start a split transaction */ + if (cvmx_usb_pipe_needs_split(usb, pipe)) + usb->active_split = transaction; + USB_SET_FIELD32(CVMX_USBCX_HCCHARX(channel, usb->index), + cvmx_usbcx_hccharx, chena, 1); + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) + cvmx_usb_fill_tx_fifo(usb, channel); +} + +/** + * Find a pipe that is ready to be scheduled to hardware. + * @usb: USB device state populated by cvmx_usb_initialize(). + * @xfer_type: Transfer type + * + * Returns: Pipe or NULL if none are ready + */ +static struct cvmx_usb_pipe *cvmx_usb_find_ready_pipe(struct octeon_hcd *usb, + enum cvmx_usb_transfer xfer_type) +{ + struct list_head *list = usb->active_pipes + xfer_type; + u64 current_frame = usb->frame_number; + struct cvmx_usb_pipe *pipe; + + list_for_each_entry(pipe, list, node) { + struct cvmx_usb_transaction *t = + list_first_entry(&pipe->transactions, typeof(*t), + node); + if (!(pipe->flags & CVMX_USB_PIPE_FLAGS_SCHEDULED) && t && + (pipe->next_tx_frame <= current_frame) && + ((pipe->split_sc_frame == -1) || + ((((int)current_frame - pipe->split_sc_frame) & 0x7f) < + 0x40)) && + (!usb->active_split || (usb->active_split == t))) { + prefetch(t); + return pipe; + } + } + return NULL; +} + +static struct cvmx_usb_pipe *cvmx_usb_next_pipe(struct octeon_hcd *usb, + int is_sof) +{ + struct cvmx_usb_pipe *pipe; + + /* Find a pipe needing service. */ + if (is_sof) { + /* + * Only process periodic pipes on SOF interrupts. This way we + * are sure that the periodic data is sent in the beginning of + * the frame. + */ + pipe = cvmx_usb_find_ready_pipe(usb, + CVMX_USB_TRANSFER_ISOCHRONOUS); + if (pipe) + return pipe; + pipe = cvmx_usb_find_ready_pipe(usb, + CVMX_USB_TRANSFER_INTERRUPT); + if (pipe) + return pipe; + } + pipe = cvmx_usb_find_ready_pipe(usb, CVMX_USB_TRANSFER_CONTROL); + if (pipe) + return pipe; + return cvmx_usb_find_ready_pipe(usb, CVMX_USB_TRANSFER_BULK); +} + +/** + * Called whenever a pipe might need to be scheduled to the + * hardware. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @is_sof: True if this schedule was called on a SOF interrupt. + */ +static void cvmx_usb_schedule(struct octeon_hcd *usb, int is_sof) +{ + int channel; + struct cvmx_usb_pipe *pipe; + int need_sof; + enum cvmx_usb_transfer ttype; + + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) { + /* + * Without DMA we need to be careful to not schedule something + * at the end of a frame and cause an overrun. + */ + union cvmx_usbcx_hfnum hfnum = { + .u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HFNUM(usb->index)) + }; + + union cvmx_usbcx_hfir hfir = { + .u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HFIR(usb->index)) + }; + + if (hfnum.s.frrem < hfir.s.frint / 4) + goto done; + } + + while (usb->idle_hardware_channels) { + /* Find an idle channel */ + channel = __fls(usb->idle_hardware_channels); + if (unlikely(channel > 7)) + break; + + pipe = cvmx_usb_next_pipe(usb, is_sof); + if (!pipe) + break; + + cvmx_usb_start_channel(usb, channel, pipe); + } + +done: + /* + * Only enable SOF interrupts when we have transactions pending in the + * future that might need to be scheduled + */ + need_sof = 0; + for (ttype = CVMX_USB_TRANSFER_CONTROL; + ttype <= CVMX_USB_TRANSFER_INTERRUPT; ttype++) { + list_for_each_entry(pipe, &usb->active_pipes[ttype], node) { + if (pipe->next_tx_frame > usb->frame_number) { + need_sof = 1; + break; + } + } + } + USB_SET_FIELD32(CVMX_USBCX_GINTMSK(usb->index), + cvmx_usbcx_gintmsk, sofmsk, need_sof); +} + +static void octeon_usb_urb_complete_callback(struct octeon_hcd *usb, + enum cvmx_usb_status status, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction + *transaction, + int bytes_transferred, + struct urb *urb) +{ + struct usb_hcd *hcd = octeon_to_hcd(usb); + struct device *dev = hcd->self.controller; + + if (likely(status == CVMX_USB_STATUS_OK)) + urb->actual_length = bytes_transferred; + else + urb->actual_length = 0; + + urb->hcpriv = NULL; + + /* For Isochronous transactions we need to update the URB packet status + * list from data in our private copy + */ + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { + int i; + /* + * The pointer to the private list is stored in the setup_packet + * field. + */ + struct cvmx_usb_iso_packet *iso_packet = + (struct cvmx_usb_iso_packet *)urb->setup_packet; + /* Recalculate the transfer size by adding up each packet */ + urb->actual_length = 0; + for (i = 0; i < urb->number_of_packets; i++) { + if (iso_packet[i].status == CVMX_USB_STATUS_OK) { + urb->iso_frame_desc[i].status = 0; + urb->iso_frame_desc[i].actual_length = + iso_packet[i].length; + urb->actual_length += + urb->iso_frame_desc[i].actual_length; + } else { + dev_dbg(dev, "ISOCHRONOUS packet=%d of %d status=%d pipe=%p transaction=%p size=%d\n", + i, urb->number_of_packets, + iso_packet[i].status, pipe, + transaction, iso_packet[i].length); + urb->iso_frame_desc[i].status = -EREMOTEIO; + } + } + /* Free the private list now that we don't need it anymore */ + kfree(iso_packet); + urb->setup_packet = NULL; + } + + switch (status) { + case CVMX_USB_STATUS_OK: + urb->status = 0; + break; + case CVMX_USB_STATUS_CANCEL: + if (urb->status == 0) + urb->status = -ENOENT; + break; + case CVMX_USB_STATUS_STALL: + dev_dbg(dev, "status=stall pipe=%p transaction=%p size=%d\n", + pipe, transaction, bytes_transferred); + urb->status = -EPIPE; + break; + case CVMX_USB_STATUS_BABBLEERR: + dev_dbg(dev, "status=babble pipe=%p transaction=%p size=%d\n", + pipe, transaction, bytes_transferred); + urb->status = -EPIPE; + break; + case CVMX_USB_STATUS_SHORT: + dev_dbg(dev, "status=short pipe=%p transaction=%p size=%d\n", + pipe, transaction, bytes_transferred); + urb->status = -EREMOTEIO; + break; + case CVMX_USB_STATUS_ERROR: + case CVMX_USB_STATUS_XACTERR: + case CVMX_USB_STATUS_DATATGLERR: + case CVMX_USB_STATUS_FRAMEERR: + dev_dbg(dev, "status=%d pipe=%p transaction=%p size=%d\n", + status, pipe, transaction, bytes_transferred); + urb->status = -EPROTO; + break; + } + usb_hcd_unlink_urb_from_ep(octeon_to_hcd(usb), urb); + spin_unlock(&usb->lock); + usb_hcd_giveback_urb(octeon_to_hcd(usb), urb, urb->status); + spin_lock(&usb->lock); +} + +/** + * Signal the completion of a transaction and free it. The + * transaction will be removed from the pipe transaction list. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Pipe the transaction is on + * @transaction: + * Transaction that completed + * @complete_code: + * Completion code + */ +static void cvmx_usb_complete(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction, + enum cvmx_usb_status complete_code) +{ + /* If this was a split then clear our split in progress marker */ + if (usb->active_split == transaction) + usb->active_split = NULL; + + /* + * Isochronous transactions need extra processing as they might not be + * done after a single data transfer + */ + if (unlikely(transaction->type == CVMX_USB_TRANSFER_ISOCHRONOUS)) { + /* Update the number of bytes transferred in this ISO packet */ + transaction->iso_packets[0].length = transaction->actual_bytes; + transaction->iso_packets[0].status = complete_code; + + /* + * If there are more ISOs pending and we succeeded, schedule the + * next one + */ + if ((transaction->iso_number_packets > 1) && + (complete_code == CVMX_USB_STATUS_OK)) { + /* No bytes transferred for this packet as of yet */ + transaction->actual_bytes = 0; + /* One less ISO waiting to transfer */ + transaction->iso_number_packets--; + /* Increment to the next location in our packet array */ + transaction->iso_packets++; + transaction->stage = CVMX_USB_STAGE_NON_CONTROL; + return; + } + } + + /* Remove the transaction from the pipe list */ + list_del(&transaction->node); + if (list_empty(&pipe->transactions)) + list_move_tail(&pipe->node, &usb->idle_pipes); + octeon_usb_urb_complete_callback(usb, complete_code, pipe, + transaction, + transaction->actual_bytes, + transaction->urb); + kfree(transaction); +} + +/** + * Submit a usb transaction to a pipe. Called for all types + * of transactions. + * + * @usb: + * @pipe: Which pipe to submit to. + * @type: Transaction type + * @buffer: User buffer for the transaction + * @buffer_length: + * User buffer's length in bytes + * @control_header: + * For control transactions, the 8 byte standard header + * @iso_start_frame: + * For ISO transactions, the start frame + * @iso_number_packets: + * For ISO, the number of packet in the transaction. + * @iso_packets: + * A description of each ISO packet + * @urb: URB for the callback + * + * Returns: Transaction or NULL on failure. + */ +static struct cvmx_usb_transaction *cvmx_usb_submit_transaction( + struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + enum cvmx_usb_transfer type, + u64 buffer, + int buffer_length, + u64 control_header, + int iso_start_frame, + int iso_number_packets, + struct cvmx_usb_iso_packet *iso_packets, + struct urb *urb) +{ + struct cvmx_usb_transaction *transaction; + + if (unlikely(pipe->transfer_type != type)) + return NULL; + + transaction = kzalloc(sizeof(*transaction), GFP_ATOMIC); + if (unlikely(!transaction)) + return NULL; + + transaction->type = type; + transaction->buffer = buffer; + transaction->buffer_length = buffer_length; + transaction->control_header = control_header; + /* FIXME: This is not used, implement it. */ + transaction->iso_start_frame = iso_start_frame; + transaction->iso_number_packets = iso_number_packets; + transaction->iso_packets = iso_packets; + transaction->urb = urb; + if (transaction->type == CVMX_USB_TRANSFER_CONTROL) + transaction->stage = CVMX_USB_STAGE_SETUP; + else + transaction->stage = CVMX_USB_STAGE_NON_CONTROL; + + if (!list_empty(&pipe->transactions)) { + list_add_tail(&transaction->node, &pipe->transactions); + } else { + list_add_tail(&transaction->node, &pipe->transactions); + list_move_tail(&pipe->node, + &usb->active_pipes[pipe->transfer_type]); + + /* + * We may need to schedule the pipe if this was the head of the + * pipe. + */ + cvmx_usb_schedule(usb, 0); + } + + return transaction; +} + +/** + * Call to submit a USB Bulk transfer to a pipe. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Handle to the pipe for the transfer. + * @urb: URB. + * + * Returns: A submitted transaction or NULL on failure. + */ +static struct cvmx_usb_transaction *cvmx_usb_submit_bulk( + struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct urb *urb) +{ + return cvmx_usb_submit_transaction(usb, pipe, CVMX_USB_TRANSFER_BULK, + urb->transfer_dma, + urb->transfer_buffer_length, + 0, /* control_header */ + 0, /* iso_start_frame */ + 0, /* iso_number_packets */ + NULL, /* iso_packets */ + urb); +} + +/** + * Call to submit a USB Interrupt transfer to a pipe. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Handle to the pipe for the transfer. + * @urb: URB returned when the callback is called. + * + * Returns: A submitted transaction or NULL on failure. + */ +static struct cvmx_usb_transaction *cvmx_usb_submit_interrupt( + struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct urb *urb) +{ + return cvmx_usb_submit_transaction(usb, pipe, + CVMX_USB_TRANSFER_INTERRUPT, + urb->transfer_dma, + urb->transfer_buffer_length, + 0, /* control_header */ + 0, /* iso_start_frame */ + 0, /* iso_number_packets */ + NULL, /* iso_packets */ + urb); +} + +/** + * Call to submit a USB Control transfer to a pipe. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Handle to the pipe for the transfer. + * @urb: URB. + * + * Returns: A submitted transaction or NULL on failure. + */ +static struct cvmx_usb_transaction *cvmx_usb_submit_control( + struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct urb *urb) +{ + int buffer_length = urb->transfer_buffer_length; + u64 control_header = urb->setup_dma; + struct usb_ctrlrequest *header = cvmx_phys_to_ptr(control_header); + + if ((header->bRequestType & USB_DIR_IN) == 0) + buffer_length = le16_to_cpu(header->wLength); + + return cvmx_usb_submit_transaction(usb, pipe, + CVMX_USB_TRANSFER_CONTROL, + urb->transfer_dma, buffer_length, + control_header, + 0, /* iso_start_frame */ + 0, /* iso_number_packets */ + NULL, /* iso_packets */ + urb); +} + +/** + * Call to submit a USB Isochronous transfer to a pipe. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Handle to the pipe for the transfer. + * @urb: URB returned when the callback is called. + * + * Returns: A submitted transaction or NULL on failure. + */ +static struct cvmx_usb_transaction *cvmx_usb_submit_isochronous( + struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct urb *urb) +{ + struct cvmx_usb_iso_packet *packets; + + packets = (struct cvmx_usb_iso_packet *)urb->setup_packet; + return cvmx_usb_submit_transaction(usb, pipe, + CVMX_USB_TRANSFER_ISOCHRONOUS, + urb->transfer_dma, + urb->transfer_buffer_length, + 0, /* control_header */ + urb->start_frame, + urb->number_of_packets, + packets, urb); +} + +/** + * Cancel one outstanding request in a pipe. Canceling a request + * can fail if the transaction has already completed before cancel + * is called. Even after a successful cancel call, it may take + * a frame or two for the cvmx_usb_poll() function to call the + * associated callback. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Pipe to cancel requests in. + * @transaction: Transaction to cancel, returned by the submit function. + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_cancel(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction) +{ + /* + * If the transaction is the HEAD of the queue and scheduled. We need to + * treat it special + */ + if (list_first_entry(&pipe->transactions, typeof(*transaction), node) == + transaction && (pipe->flags & CVMX_USB_PIPE_FLAGS_SCHEDULED)) { + union cvmx_usbcx_hccharx usbc_hcchar; + + usb->pipe_for_channel[pipe->channel] = NULL; + pipe->flags &= ~CVMX_USB_PIPE_FLAGS_SCHEDULED; + + CVMX_SYNCW; + + usbc_hcchar.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCCHARX(pipe->channel, usb->index)); + /* + * If the channel isn't enabled then the transaction already + * completed. + */ + if (usbc_hcchar.s.chena) { + usbc_hcchar.s.chdis = 1; + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCCHARX(pipe->channel, + usb->index), + usbc_hcchar.u32); + } + } + cvmx_usb_complete(usb, pipe, transaction, CVMX_USB_STATUS_CANCEL); + return 0; +} + +/** + * Cancel all outstanding requests in a pipe. Logically all this + * does is call cvmx_usb_cancel() in a loop. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Pipe to cancel requests in. + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_cancel_all(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe) +{ + struct cvmx_usb_transaction *transaction, *next; + + /* Simply loop through and attempt to cancel each transaction */ + list_for_each_entry_safe(transaction, next, &pipe->transactions, node) { + int result = cvmx_usb_cancel(usb, pipe, transaction); + + if (unlikely(result != 0)) + return result; + } + return 0; +} + +/** + * Close a pipe created with cvmx_usb_open_pipe(). + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * @pipe: Pipe to close. + * + * Returns: 0 or a negative error code. EBUSY is returned if the pipe has + * outstanding transfers. + */ +static int cvmx_usb_close_pipe(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe) +{ + /* Fail if the pipe has pending transactions */ + if (!list_empty(&pipe->transactions)) + return -EBUSY; + + list_del(&pipe->node); + kfree(pipe); + + return 0; +} + +/** + * Get the current USB protocol level frame number. The frame + * number is always in the range of 0-0x7ff. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * + * Returns: USB frame number + */ +static int cvmx_usb_get_frame_number(struct octeon_hcd *usb) +{ + union cvmx_usbcx_hfnum usbc_hfnum; + + usbc_hfnum.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HFNUM(usb->index)); + + return usbc_hfnum.s.frnum; +} + +static void cvmx_usb_transfer_control(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction, + union cvmx_usbcx_hccharx usbc_hcchar, + int buffer_space_left, + int bytes_in_last_packet) +{ + switch (transaction->stage) { + case CVMX_USB_STAGE_NON_CONTROL: + case CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE: + /* This should be impossible */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_ERROR); + break; + case CVMX_USB_STAGE_SETUP: + pipe->pid_toggle = 1; + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + transaction->stage = + CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE; + } else { + struct usb_ctrlrequest *header = + cvmx_phys_to_ptr(transaction->control_header); + if (header->wLength) + transaction->stage = CVMX_USB_STAGE_DATA; + else + transaction->stage = CVMX_USB_STAGE_STATUS; + } + break; + case CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE: + { + struct usb_ctrlrequest *header = + cvmx_phys_to_ptr(transaction->control_header); + if (header->wLength) + transaction->stage = CVMX_USB_STAGE_DATA; + else + transaction->stage = CVMX_USB_STAGE_STATUS; + } + break; + case CVMX_USB_STAGE_DATA: + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + transaction->stage = CVMX_USB_STAGE_DATA_SPLIT_COMPLETE; + /* + * For setup OUT data that are splits, + * the hardware doesn't appear to count + * transferred data. Here we manually + * update the data transferred + */ + if (!usbc_hcchar.s.epdir) { + if (buffer_space_left < pipe->max_packet) + transaction->actual_bytes += + buffer_space_left; + else + transaction->actual_bytes += + pipe->max_packet; + } + } else if ((buffer_space_left == 0) || + (bytes_in_last_packet < pipe->max_packet)) { + pipe->pid_toggle = 1; + transaction->stage = CVMX_USB_STAGE_STATUS; + } + break; + case CVMX_USB_STAGE_DATA_SPLIT_COMPLETE: + if ((buffer_space_left == 0) || + (bytes_in_last_packet < pipe->max_packet)) { + pipe->pid_toggle = 1; + transaction->stage = CVMX_USB_STAGE_STATUS; + } else { + transaction->stage = CVMX_USB_STAGE_DATA; + } + break; + case CVMX_USB_STAGE_STATUS: + if (cvmx_usb_pipe_needs_split(usb, pipe)) + transaction->stage = + CVMX_USB_STAGE_STATUS_SPLIT_COMPLETE; + else + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + break; + case CVMX_USB_STAGE_STATUS_SPLIT_COMPLETE: + cvmx_usb_complete(usb, pipe, transaction, CVMX_USB_STATUS_OK); + break; + } +} + +static void cvmx_usb_transfer_bulk(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction, + union cvmx_usbcx_hcintx usbc_hcint, + int buffer_space_left, + int bytes_in_last_packet) +{ + /* + * The only time a bulk transfer isn't complete when it finishes with + * an ACK is during a split transaction. For splits we need to continue + * the transfer if more data is needed. + */ + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + if (transaction->stage == CVMX_USB_STAGE_NON_CONTROL) + transaction->stage = + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE; + else if (buffer_space_left && + (bytes_in_last_packet == pipe->max_packet)) + transaction->stage = CVMX_USB_STAGE_NON_CONTROL; + else + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + } else { + if ((pipe->device_speed == CVMX_USB_SPEED_HIGH) && + (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) && + (usbc_hcint.s.nak)) + pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING; + if (!buffer_space_left || + (bytes_in_last_packet < pipe->max_packet)) + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + } +} + +static void cvmx_usb_transfer_intr(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction, + int buffer_space_left, + int bytes_in_last_packet) +{ + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + if (transaction->stage == CVMX_USB_STAGE_NON_CONTROL) { + transaction->stage = + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE; + } else if (buffer_space_left && + (bytes_in_last_packet == pipe->max_packet)) { + transaction->stage = CVMX_USB_STAGE_NON_CONTROL; + } else { + pipe->next_tx_frame += pipe->interval; + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + } + } else if (!buffer_space_left || + (bytes_in_last_packet < pipe->max_packet)) { + pipe->next_tx_frame += pipe->interval; + cvmx_usb_complete(usb, pipe, transaction, CVMX_USB_STATUS_OK); + } +} + +static void cvmx_usb_transfer_isoc(struct octeon_hcd *usb, + struct cvmx_usb_pipe *pipe, + struct cvmx_usb_transaction *transaction, + int buffer_space_left, + int bytes_in_last_packet, + int bytes_this_transfer) +{ + if (cvmx_usb_pipe_needs_split(usb, pipe)) { + /* + * ISOCHRONOUS OUT splits don't require a complete split stage. + * Instead they use a sequence of begin OUT splits to transfer + * the data 188 bytes at a time. Once the transfer is complete, + * the pipe sleeps until the next schedule interval. + */ + if (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) { + /* + * If no space left or this wasn't a max size packet + * then this transfer is complete. Otherwise start it + * again to send the next 188 bytes + */ + if (!buffer_space_left || (bytes_this_transfer < 188)) { + pipe->next_tx_frame += pipe->interval; + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + } + return; + } + if (transaction->stage == + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE) { + /* + * We are in the incoming data phase. Keep getting data + * until we run out of space or get a small packet + */ + if ((buffer_space_left == 0) || + (bytes_in_last_packet < pipe->max_packet)) { + pipe->next_tx_frame += pipe->interval; + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_OK); + } + } else { + transaction->stage = + CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE; + } + } else { + pipe->next_tx_frame += pipe->interval; + cvmx_usb_complete(usb, pipe, transaction, CVMX_USB_STATUS_OK); + } +} + +/** + * Poll a channel for status + * + * @usb: USB device + * @channel: Channel to poll + * + * Returns: Zero on success + */ +static int cvmx_usb_poll_channel(struct octeon_hcd *usb, int channel) +{ + struct usb_hcd *hcd = octeon_to_hcd(usb); + struct device *dev = hcd->self.controller; + union cvmx_usbcx_hcintx usbc_hcint; + union cvmx_usbcx_hctsizx usbc_hctsiz; + union cvmx_usbcx_hccharx usbc_hcchar; + struct cvmx_usb_pipe *pipe; + struct cvmx_usb_transaction *transaction; + int bytes_this_transfer; + int bytes_in_last_packet; + int packets_processed; + int buffer_space_left; + + /* Read the interrupt status bits for the channel */ + usbc_hcint.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCINTX(channel, usb->index)); + + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) { + usbc_hcchar.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCCHARX(channel, usb->index)); + + if (usbc_hcchar.s.chena && usbc_hcchar.s.chdis) { + /* + * There seems to be a bug in CN31XX which can cause + * interrupt IN transfers to get stuck until we do a + * write of HCCHARX without changing things + */ + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCCHARX(channel, + usb->index), + usbc_hcchar.u32); + return 0; + } + + /* + * In non DMA mode the channels don't halt themselves. We need + * to manually disable channels that are left running + */ + if (!usbc_hcint.s.chhltd) { + if (usbc_hcchar.s.chena) { + union cvmx_usbcx_hcintmskx hcintmsk; + /* Disable all interrupts except CHHLTD */ + hcintmsk.u32 = 0; + hcintmsk.s.chhltdmsk = 1; + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCINTMSKX(channel, usb->index), + hcintmsk.u32); + usbc_hcchar.s.chdis = 1; + cvmx_usb_write_csr32(usb, + CVMX_USBCX_HCCHARX(channel, usb->index), + usbc_hcchar.u32); + return 0; + } else if (usbc_hcint.s.xfercompl) { + /* + * Successful IN/OUT with transfer complete. + * Channel halt isn't needed. + */ + } else { + dev_err(dev, "USB%d: Channel %d interrupt without halt\n", + usb->index, channel); + return 0; + } + } + } else { + /* + * There is are no interrupts that we need to process when the + * channel is still running + */ + if (!usbc_hcint.s.chhltd) + return 0; + } + + /* Disable the channel interrupts now that it is done */ + cvmx_usb_write_csr32(usb, CVMX_USBCX_HCINTMSKX(channel, usb->index), 0); + usb->idle_hardware_channels |= (1 << channel); + + /* Make sure this channel is tied to a valid pipe */ + pipe = usb->pipe_for_channel[channel]; + prefetch(pipe); + if (!pipe) + return 0; + transaction = list_first_entry(&pipe->transactions, + typeof(*transaction), + node); + prefetch(transaction); + + /* + * Disconnect this pipe from the HW channel. Later the schedule + * function will figure out which pipe needs to go + */ + usb->pipe_for_channel[channel] = NULL; + pipe->flags &= ~CVMX_USB_PIPE_FLAGS_SCHEDULED; + + /* + * Read the channel config info so we can figure out how much data + * transferred + */ + usbc_hcchar.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCCHARX(channel, usb->index)); + usbc_hctsiz.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HCTSIZX(channel, usb->index)); + + /* + * Calculating the number of bytes successfully transferred is dependent + * on the transfer direction + */ + packets_processed = transaction->pktcnt - usbc_hctsiz.s.pktcnt; + if (usbc_hcchar.s.epdir) { + /* + * IN transactions are easy. For every byte received the + * hardware decrements xfersize. All we need to do is subtract + * the current value of xfersize from its starting value and we + * know how many bytes were written to the buffer + */ + bytes_this_transfer = transaction->xfersize - + usbc_hctsiz.s.xfersize; + } else { + /* + * OUT transaction don't decrement xfersize. Instead pktcnt is + * decremented on every successful packet send. The hardware + * does this when it receives an ACK, or NYET. If it doesn't + * receive one of these responses pktcnt doesn't change + */ + bytes_this_transfer = packets_processed * usbc_hcchar.s.mps; + /* + * The last packet may not be a full transfer if we didn't have + * enough data + */ + if (bytes_this_transfer > transaction->xfersize) + bytes_this_transfer = transaction->xfersize; + } + /* Figure out how many bytes were in the last packet of the transfer */ + if (packets_processed) + bytes_in_last_packet = bytes_this_transfer - + (packets_processed - 1) * usbc_hcchar.s.mps; + else + bytes_in_last_packet = bytes_this_transfer; + + /* + * As a special case, setup transactions output the setup header, not + * the user's data. For this reason we don't count setup data as bytes + * transferred + */ + if ((transaction->stage == CVMX_USB_STAGE_SETUP) || + (transaction->stage == CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE)) + bytes_this_transfer = 0; + + /* + * Add the bytes transferred to the running total. It is important that + * bytes_this_transfer doesn't count any data that needs to be + * retransmitted + */ + transaction->actual_bytes += bytes_this_transfer; + if (transaction->type == CVMX_USB_TRANSFER_ISOCHRONOUS) + buffer_space_left = transaction->iso_packets[0].length - + transaction->actual_bytes; + else + buffer_space_left = transaction->buffer_length - + transaction->actual_bytes; + + /* + * We need to remember the PID toggle state for the next transaction. + * The hardware already updated it for the next transaction + */ + pipe->pid_toggle = !(usbc_hctsiz.s.pid == 0); + + /* + * For high speed bulk out, assume the next transaction will need to do + * a ping before proceeding. If this isn't true the ACK processing below + * will clear this flag + */ + if ((pipe->device_speed == CVMX_USB_SPEED_HIGH) && + (pipe->transfer_type == CVMX_USB_TRANSFER_BULK) && + (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT)) + pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING; + + if (WARN_ON_ONCE(bytes_this_transfer < 0)) { + /* + * In some rare cases the DMA engine seems to get stuck and + * keeps substracting same byte count over and over again. In + * such case we just need to fail every transaction. + */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_ERROR); + return 0; + } + + if (usbc_hcint.s.stall) { + /* + * STALL as a response means this transaction cannot be + * completed because the device can't process transactions. Tell + * the user. Any data that was transferred will be counted on + * the actual bytes transferred + */ + pipe->pid_toggle = 0; + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_STALL); + } else if (usbc_hcint.s.xacterr) { + /* + * XactErr as a response means the device signaled + * something wrong with the transfer. For example, PID + * toggle errors cause these. + */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_XACTERR); + } else if (usbc_hcint.s.bblerr) { + /* Babble Error (BblErr) */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_BABBLEERR); + } else if (usbc_hcint.s.datatglerr) { + /* Data toggle error */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_DATATGLERR); + } else if (usbc_hcint.s.nyet) { + /* + * NYET as a response is only allowed in three cases: as a + * response to a ping, as a response to a split transaction, and + * as a response to a bulk out. The ping case is handled by + * hardware, so we only have splits and bulk out + */ + if (!cvmx_usb_pipe_needs_split(usb, pipe)) { + transaction->retries = 0; + /* + * If there is more data to go then we need to try + * again. Otherwise this transaction is complete + */ + if ((buffer_space_left == 0) || + (bytes_in_last_packet < pipe->max_packet)) + cvmx_usb_complete(usb, pipe, + transaction, + CVMX_USB_STATUS_OK); + } else { + /* + * Split transactions retry the split complete 4 times + * then rewind to the start split and do the entire + * transactions again + */ + transaction->retries++; + if ((transaction->retries & 0x3) == 0) { + /* + * Rewind to the beginning of the transaction by + * anding off the split complete bit + */ + transaction->stage &= ~1; + pipe->split_sc_frame = -1; + } + } + } else if (usbc_hcint.s.ack) { + transaction->retries = 0; + /* + * The ACK bit can only be checked after the other error bits. + * This is because a multi packet transfer may succeed in a + * number of packets and then get a different response on the + * last packet. In this case both ACK and the last response bit + * will be set. If none of the other response bits is set, then + * the last packet must have been an ACK + * + * Since we got an ACK, we know we don't need to do a ping on + * this pipe + */ + pipe->flags &= ~CVMX_USB_PIPE_FLAGS_NEED_PING; + + switch (transaction->type) { + case CVMX_USB_TRANSFER_CONTROL: + cvmx_usb_transfer_control(usb, pipe, transaction, + usbc_hcchar, + buffer_space_left, + bytes_in_last_packet); + break; + case CVMX_USB_TRANSFER_BULK: + cvmx_usb_transfer_bulk(usb, pipe, transaction, + usbc_hcint, buffer_space_left, + bytes_in_last_packet); + break; + case CVMX_USB_TRANSFER_INTERRUPT: + cvmx_usb_transfer_intr(usb, pipe, transaction, + buffer_space_left, + bytes_in_last_packet); + break; + case CVMX_USB_TRANSFER_ISOCHRONOUS: + cvmx_usb_transfer_isoc(usb, pipe, transaction, + buffer_space_left, + bytes_in_last_packet, + bytes_this_transfer); + break; + } + } else if (usbc_hcint.s.nak) { + /* + * If this was a split then clear our split in progress marker. + */ + if (usb->active_split == transaction) + usb->active_split = NULL; + /* + * NAK as a response means the device couldn't accept the + * transaction, but it should be retried in the future. Rewind + * to the beginning of the transaction by anding off the split + * complete bit. Retry in the next interval + */ + transaction->retries = 0; + transaction->stage &= ~1; + pipe->next_tx_frame += pipe->interval; + if (pipe->next_tx_frame < usb->frame_number) + pipe->next_tx_frame = usb->frame_number + + pipe->interval - + (usb->frame_number - pipe->next_tx_frame) % + pipe->interval; + } else { + struct cvmx_usb_port_status port; + + port = cvmx_usb_get_status(usb); + if (port.port_enabled) { + /* We'll retry the exact same transaction again */ + transaction->retries++; + } else { + /* + * We get channel halted interrupts with no result bits + * sets when the cable is unplugged + */ + cvmx_usb_complete(usb, pipe, transaction, + CVMX_USB_STATUS_ERROR); + } + } + return 0; +} + +static void octeon_usb_port_callback(struct octeon_hcd *usb) +{ + spin_unlock(&usb->lock); + usb_hcd_poll_rh_status(octeon_to_hcd(usb)); + spin_lock(&usb->lock); +} + +/** + * Poll the USB block for status and call all needed callback + * handlers. This function is meant to be called in the interrupt + * handler for the USB controller. It can also be called + * periodically in a loop for non-interrupt based operation. + * + * @usb: USB device state populated by cvmx_usb_initialize(). + * + * Returns: 0 or a negative error code. + */ +static int cvmx_usb_poll(struct octeon_hcd *usb) +{ + union cvmx_usbcx_hfnum usbc_hfnum; + union cvmx_usbcx_gintsts usbc_gintsts; + + prefetch_range(usb, sizeof(*usb)); + + /* Update the frame counter */ + usbc_hfnum.u32 = cvmx_usb_read_csr32(usb, CVMX_USBCX_HFNUM(usb->index)); + if ((usb->frame_number & 0x3fff) > usbc_hfnum.s.frnum) + usb->frame_number += 0x4000; + usb->frame_number &= ~0x3fffull; + usb->frame_number |= usbc_hfnum.s.frnum; + + /* Read the pending interrupts */ + usbc_gintsts.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_GINTSTS(usb->index)); + + /* Clear the interrupts now that we know about them */ + cvmx_usb_write_csr32(usb, CVMX_USBCX_GINTSTS(usb->index), + usbc_gintsts.u32); + + if (usbc_gintsts.s.rxflvl) { + /* + * RxFIFO Non-Empty (RxFLvl) + * Indicates that there is at least one packet pending to be + * read from the RxFIFO. + * + * In DMA mode this is handled by hardware + */ + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) + cvmx_usb_poll_rx_fifo(usb); + } + if (usbc_gintsts.s.ptxfemp || usbc_gintsts.s.nptxfemp) { + /* Fill the Tx FIFOs when not in DMA mode */ + if (usb->init_flags & CVMX_USB_INITIALIZE_FLAGS_NO_DMA) + cvmx_usb_poll_tx_fifo(usb); + } + if (usbc_gintsts.s.disconnint || usbc_gintsts.s.prtint) { + union cvmx_usbcx_hprt usbc_hprt; + /* + * Disconnect Detected Interrupt (DisconnInt) + * Asserted when a device disconnect is detected. + * + * Host Port Interrupt (PrtInt) + * The core sets this bit to indicate a change in port status of + * one of the O2P USB core ports in Host mode. The application + * must read the Host Port Control and Status (HPRT) register to + * determine the exact event that caused this interrupt. The + * application must clear the appropriate status bit in the Host + * Port Control and Status register to clear this bit. + * + * Call the user's port callback + */ + octeon_usb_port_callback(usb); + /* Clear the port change bits */ + usbc_hprt.u32 = + cvmx_usb_read_csr32(usb, CVMX_USBCX_HPRT(usb->index)); + usbc_hprt.s.prtena = 0; + cvmx_usb_write_csr32(usb, CVMX_USBCX_HPRT(usb->index), + usbc_hprt.u32); + } + if (usbc_gintsts.s.hchint) { + /* + * Host Channels Interrupt (HChInt) + * The core sets this bit to indicate that an interrupt is + * pending on one of the channels of the core (in Host mode). + * The application must read the Host All Channels Interrupt + * (HAINT) register to determine the exact number of the channel + * on which the interrupt occurred, and then read the + * corresponding Host Channel-n Interrupt (HCINTn) register to + * determine the exact cause of the interrupt. The application + * must clear the appropriate status bit in the HCINTn register + * to clear this bit. + */ + union cvmx_usbcx_haint usbc_haint; + + usbc_haint.u32 = cvmx_usb_read_csr32(usb, + CVMX_USBCX_HAINT(usb->index)); + while (usbc_haint.u32) { + int channel; + + channel = __fls(usbc_haint.u32); + cvmx_usb_poll_channel(usb, channel); + usbc_haint.u32 ^= 1 << channel; + } + } + + cvmx_usb_schedule(usb, usbc_gintsts.s.sof); + + return 0; +} + +/* convert between an HCD pointer and the corresponding struct octeon_hcd */ +static inline struct octeon_hcd *hcd_to_octeon(struct usb_hcd *hcd) +{ + return (struct octeon_hcd *)(hcd->hcd_priv); +} + +static irqreturn_t octeon_usb_irq(struct usb_hcd *hcd) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + unsigned long flags; + + spin_lock_irqsave(&usb->lock, flags); + cvmx_usb_poll(usb); + spin_unlock_irqrestore(&usb->lock, flags); + return IRQ_HANDLED; +} + +static int octeon_usb_start(struct usb_hcd *hcd) +{ + hcd->state = HC_STATE_RUNNING; + return 0; +} + +static void octeon_usb_stop(struct usb_hcd *hcd) +{ + hcd->state = HC_STATE_HALT; +} + +static int octeon_usb_get_frame_number(struct usb_hcd *hcd) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + + return cvmx_usb_get_frame_number(usb); +} + +static int octeon_usb_urb_enqueue(struct usb_hcd *hcd, + struct urb *urb, + gfp_t mem_flags) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + struct device *dev = hcd->self.controller; + struct cvmx_usb_transaction *transaction = NULL; + struct cvmx_usb_pipe *pipe; + unsigned long flags; + struct cvmx_usb_iso_packet *iso_packet; + struct usb_host_endpoint *ep = urb->ep; + int rc; + + urb->status = 0; + spin_lock_irqsave(&usb->lock, flags); + + rc = usb_hcd_link_urb_to_ep(hcd, urb); + if (rc) { + spin_unlock_irqrestore(&usb->lock, flags); + return rc; + } + + if (!ep->hcpriv) { + enum cvmx_usb_transfer transfer_type; + enum cvmx_usb_speed speed; + int split_device = 0; + int split_port = 0; + + switch (usb_pipetype(urb->pipe)) { + case PIPE_ISOCHRONOUS: + transfer_type = CVMX_USB_TRANSFER_ISOCHRONOUS; + break; + case PIPE_INTERRUPT: + transfer_type = CVMX_USB_TRANSFER_INTERRUPT; + break; + case PIPE_CONTROL: + transfer_type = CVMX_USB_TRANSFER_CONTROL; + break; + default: + transfer_type = CVMX_USB_TRANSFER_BULK; + break; + } + switch (urb->dev->speed) { + case USB_SPEED_LOW: + speed = CVMX_USB_SPEED_LOW; + break; + case USB_SPEED_FULL: + speed = CVMX_USB_SPEED_FULL; + break; + default: + speed = CVMX_USB_SPEED_HIGH; + break; + } + /* + * For slow devices on high speed ports we need to find the hub + * that does the speed translation so we know where to send the + * split transactions. + */ + if (speed != CVMX_USB_SPEED_HIGH) { + /* + * Start at this device and work our way up the usb + * tree. + */ + struct usb_device *dev = urb->dev; + + while (dev->parent) { + /* + * If our parent is high speed then he'll + * receive the splits. + */ + if (dev->parent->speed == USB_SPEED_HIGH) { + split_device = dev->parent->devnum; + split_port = dev->portnum; + break; + } + /* + * Move up the tree one level. If we make it all + * the way up the tree, then the port must not + * be in high speed mode and we don't need a + * split. + */ + dev = dev->parent; + } + } + pipe = cvmx_usb_open_pipe(usb, usb_pipedevice(urb->pipe), + usb_pipeendpoint(urb->pipe), speed, + le16_to_cpu(ep->desc.wMaxPacketSize) + & 0x7ff, + transfer_type, + usb_pipein(urb->pipe) ? + CVMX_USB_DIRECTION_IN : + CVMX_USB_DIRECTION_OUT, + urb->interval, + (le16_to_cpu(ep->desc.wMaxPacketSize) + >> 11) & 0x3, + split_device, split_port); + if (!pipe) { + usb_hcd_unlink_urb_from_ep(hcd, urb); + spin_unlock_irqrestore(&usb->lock, flags); + dev_dbg(dev, "Failed to create pipe\n"); + return -ENOMEM; + } + ep->hcpriv = pipe; + } else { + pipe = ep->hcpriv; + } + + switch (usb_pipetype(urb->pipe)) { + case PIPE_ISOCHRONOUS: + dev_dbg(dev, "Submit isochronous to %d.%d\n", + usb_pipedevice(urb->pipe), + usb_pipeendpoint(urb->pipe)); + /* + * Allocate a structure to use for our private list of + * isochronous packets. + */ + iso_packet = kmalloc_array(urb->number_of_packets, + sizeof(struct cvmx_usb_iso_packet), + GFP_ATOMIC); + if (iso_packet) { + int i; + /* Fill the list with the data from the URB */ + for (i = 0; i < urb->number_of_packets; i++) { + iso_packet[i].offset = + urb->iso_frame_desc[i].offset; + iso_packet[i].length = + urb->iso_frame_desc[i].length; + iso_packet[i].status = CVMX_USB_STATUS_ERROR; + } + /* + * Store a pointer to the list in the URB setup_packet + * field. We know this currently isn't being used and + * this saves us a bunch of logic. + */ + urb->setup_packet = (char *)iso_packet; + transaction = cvmx_usb_submit_isochronous(usb, + pipe, urb); + /* + * If submit failed we need to free our private packet + * list. + */ + if (!transaction) { + urb->setup_packet = NULL; + kfree(iso_packet); + } + } + break; + case PIPE_INTERRUPT: + dev_dbg(dev, "Submit interrupt to %d.%d\n", + usb_pipedevice(urb->pipe), + usb_pipeendpoint(urb->pipe)); + transaction = cvmx_usb_submit_interrupt(usb, pipe, urb); + break; + case PIPE_CONTROL: + dev_dbg(dev, "Submit control to %d.%d\n", + usb_pipedevice(urb->pipe), + usb_pipeendpoint(urb->pipe)); + transaction = cvmx_usb_submit_control(usb, pipe, urb); + break; + case PIPE_BULK: + dev_dbg(dev, "Submit bulk to %d.%d\n", + usb_pipedevice(urb->pipe), + usb_pipeendpoint(urb->pipe)); + transaction = cvmx_usb_submit_bulk(usb, pipe, urb); + break; + } + if (!transaction) { + usb_hcd_unlink_urb_from_ep(hcd, urb); + spin_unlock_irqrestore(&usb->lock, flags); + dev_dbg(dev, "Failed to submit\n"); + return -ENOMEM; + } + urb->hcpriv = transaction; + spin_unlock_irqrestore(&usb->lock, flags); + return 0; +} + +static int octeon_usb_urb_dequeue(struct usb_hcd *hcd, + struct urb *urb, + int status) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + unsigned long flags; + int rc; + + if (!urb->dev) + return -EINVAL; + + spin_lock_irqsave(&usb->lock, flags); + + rc = usb_hcd_check_unlink_urb(hcd, urb, status); + if (rc) + goto out; + + urb->status = status; + cvmx_usb_cancel(usb, urb->ep->hcpriv, urb->hcpriv); + +out: + spin_unlock_irqrestore(&usb->lock, flags); + + return rc; +} + +static void octeon_usb_endpoint_disable(struct usb_hcd *hcd, + struct usb_host_endpoint *ep) +{ + struct device *dev = hcd->self.controller; + + if (ep->hcpriv) { + struct octeon_hcd *usb = hcd_to_octeon(hcd); + struct cvmx_usb_pipe *pipe = ep->hcpriv; + unsigned long flags; + + spin_lock_irqsave(&usb->lock, flags); + cvmx_usb_cancel_all(usb, pipe); + if (cvmx_usb_close_pipe(usb, pipe)) + dev_dbg(dev, "Closing pipe %p failed\n", pipe); + spin_unlock_irqrestore(&usb->lock, flags); + ep->hcpriv = NULL; + } +} + +static int octeon_usb_hub_status_data(struct usb_hcd *hcd, char *buf) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + struct cvmx_usb_port_status port_status; + unsigned long flags; + + spin_lock_irqsave(&usb->lock, flags); + port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + buf[0] = port_status.connect_change << 1; + + return buf[0] != 0; +} + +static int octeon_usb_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + u16 wIndex, char *buf, u16 wLength) +{ + struct octeon_hcd *usb = hcd_to_octeon(hcd); + struct device *dev = hcd->self.controller; + struct cvmx_usb_port_status usb_port_status; + int port_status; + struct usb_hub_descriptor *desc; + unsigned long flags; + + switch (typeReq) { + case ClearHubFeature: + dev_dbg(dev, "ClearHubFeature\n"); + switch (wValue) { + case C_HUB_LOCAL_POWER: + case C_HUB_OVER_CURRENT: + /* Nothing required here */ + break; + default: + return -EINVAL; + } + break; + case ClearPortFeature: + dev_dbg(dev, "ClearPortFeature\n"); + if (wIndex != 1) { + dev_dbg(dev, " INVALID\n"); + return -EINVAL; + } + + switch (wValue) { + case USB_PORT_FEAT_ENABLE: + dev_dbg(dev, " ENABLE\n"); + spin_lock_irqsave(&usb->lock, flags); + cvmx_usb_disable(usb); + spin_unlock_irqrestore(&usb->lock, flags); + break; + case USB_PORT_FEAT_SUSPEND: + dev_dbg(dev, " SUSPEND\n"); + /* Not supported on Octeon */ + break; + case USB_PORT_FEAT_POWER: + dev_dbg(dev, " POWER\n"); + /* Not supported on Octeon */ + break; + case USB_PORT_FEAT_INDICATOR: + dev_dbg(dev, " INDICATOR\n"); + /* Port inidicator not supported */ + break; + case USB_PORT_FEAT_C_CONNECTION: + dev_dbg(dev, " C_CONNECTION\n"); + /* Clears drivers internal connect status change flag */ + spin_lock_irqsave(&usb->lock, flags); + usb->port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + break; + case USB_PORT_FEAT_C_RESET: + dev_dbg(dev, " C_RESET\n"); + /* + * Clears the driver's internal Port Reset Change flag. + */ + spin_lock_irqsave(&usb->lock, flags); + usb->port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + break; + case USB_PORT_FEAT_C_ENABLE: + dev_dbg(dev, " C_ENABLE\n"); + /* + * Clears the driver's internal Port Enable/Disable + * Change flag. + */ + spin_lock_irqsave(&usb->lock, flags); + usb->port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + break; + case USB_PORT_FEAT_C_SUSPEND: + dev_dbg(dev, " C_SUSPEND\n"); + /* + * Clears the driver's internal Port Suspend Change + * flag, which is set when resume signaling on the host + * port is complete. + */ + break; + case USB_PORT_FEAT_C_OVER_CURRENT: + dev_dbg(dev, " C_OVER_CURRENT\n"); + /* Clears the driver's overcurrent Change flag */ + spin_lock_irqsave(&usb->lock, flags); + usb->port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + break; + default: + dev_dbg(dev, " UNKNOWN\n"); + return -EINVAL; + } + break; + case GetHubDescriptor: + dev_dbg(dev, "GetHubDescriptor\n"); + desc = (struct usb_hub_descriptor *)buf; + desc->bDescLength = 9; + desc->bDescriptorType = 0x29; + desc->bNbrPorts = 1; + desc->wHubCharacteristics = cpu_to_le16(0x08); + desc->bPwrOn2PwrGood = 1; + desc->bHubContrCurrent = 0; + desc->u.hs.DeviceRemovable[0] = 0; + desc->u.hs.DeviceRemovable[1] = 0xff; + break; + case GetHubStatus: + dev_dbg(dev, "GetHubStatus\n"); + *(__le32 *)buf = 0; + break; + case GetPortStatus: + dev_dbg(dev, "GetPortStatus\n"); + if (wIndex != 1) { + dev_dbg(dev, " INVALID\n"); + return -EINVAL; + } + + spin_lock_irqsave(&usb->lock, flags); + usb_port_status = cvmx_usb_get_status(usb); + spin_unlock_irqrestore(&usb->lock, flags); + port_status = 0; + + if (usb_port_status.connect_change) { + port_status |= (1 << USB_PORT_FEAT_C_CONNECTION); + dev_dbg(dev, " C_CONNECTION\n"); + } + + if (usb_port_status.port_enabled) { + port_status |= (1 << USB_PORT_FEAT_C_ENABLE); + dev_dbg(dev, " C_ENABLE\n"); + } + + if (usb_port_status.connected) { + port_status |= (1 << USB_PORT_FEAT_CONNECTION); + dev_dbg(dev, " CONNECTION\n"); + } + + if (usb_port_status.port_enabled) { + port_status |= (1 << USB_PORT_FEAT_ENABLE); + dev_dbg(dev, " ENABLE\n"); + } + + if (usb_port_status.port_over_current) { + port_status |= (1 << USB_PORT_FEAT_OVER_CURRENT); + dev_dbg(dev, " OVER_CURRENT\n"); + } + + if (usb_port_status.port_powered) { + port_status |= (1 << USB_PORT_FEAT_POWER); + dev_dbg(dev, " POWER\n"); + } + + if (usb_port_status.port_speed == CVMX_USB_SPEED_HIGH) { + port_status |= USB_PORT_STAT_HIGH_SPEED; + dev_dbg(dev, " HIGHSPEED\n"); + } else if (usb_port_status.port_speed == CVMX_USB_SPEED_LOW) { + port_status |= (1 << USB_PORT_FEAT_LOWSPEED); + dev_dbg(dev, " LOWSPEED\n"); + } + + *((__le32 *)buf) = cpu_to_le32(port_status); + break; + case SetHubFeature: + dev_dbg(dev, "SetHubFeature\n"); + /* No HUB features supported */ + break; + case SetPortFeature: + dev_dbg(dev, "SetPortFeature\n"); + if (wIndex != 1) { + dev_dbg(dev, " INVALID\n"); + return -EINVAL; + } + + switch (wValue) { + case USB_PORT_FEAT_SUSPEND: + dev_dbg(dev, " SUSPEND\n"); + return -EINVAL; + case USB_PORT_FEAT_POWER: + dev_dbg(dev, " POWER\n"); + /* + * Program the port power bit to drive VBUS on the USB. + */ + spin_lock_irqsave(&usb->lock, flags); + USB_SET_FIELD32(CVMX_USBCX_HPRT(usb->index), + cvmx_usbcx_hprt, prtpwr, 1); + spin_unlock_irqrestore(&usb->lock, flags); + return 0; + case USB_PORT_FEAT_RESET: + dev_dbg(dev, " RESET\n"); + spin_lock_irqsave(&usb->lock, flags); + cvmx_usb_reset_port(usb); + spin_unlock_irqrestore(&usb->lock, flags); + return 0; + case USB_PORT_FEAT_INDICATOR: + dev_dbg(dev, " INDICATOR\n"); + /* Not supported */ + break; + default: + dev_dbg(dev, " UNKNOWN\n"); + return -EINVAL; + } + break; + default: + dev_dbg(dev, "Unknown root hub request\n"); + return -EINVAL; + } + return 0; +} + +static const struct hc_driver octeon_hc_driver = { + .description = "Octeon USB", + .product_desc = "Octeon Host Controller", + .hcd_priv_size = sizeof(struct octeon_hcd), + .irq = octeon_usb_irq, + .flags = HCD_MEMORY | HCD_DMA | HCD_USB2, + .start = octeon_usb_start, + .stop = octeon_usb_stop, + .urb_enqueue = octeon_usb_urb_enqueue, + .urb_dequeue = octeon_usb_urb_dequeue, + .endpoint_disable = octeon_usb_endpoint_disable, + .get_frame_number = octeon_usb_get_frame_number, + .hub_status_data = octeon_usb_hub_status_data, + .hub_control = octeon_usb_hub_control, + .map_urb_for_dma = octeon_map_urb_for_dma, + .unmap_urb_for_dma = octeon_unmap_urb_for_dma, +}; + +static int octeon_usb_probe(struct platform_device *pdev) +{ + int status; + int initialize_flags; + int usb_num; + struct resource *res_mem; + struct device_node *usbn_node; + int irq = platform_get_irq(pdev, 0); + struct device *dev = &pdev->dev; + struct octeon_hcd *usb; + struct usb_hcd *hcd; + u32 clock_rate = 48000000; + bool is_crystal_clock = false; + const char *clock_type; + int i; + + if (!dev->of_node) { + dev_err(dev, "Error: empty of_node\n"); + return -ENXIO; + } + usbn_node = dev->of_node->parent; + + i = of_property_read_u32(usbn_node, + "clock-frequency", &clock_rate); + if (i) + i = of_property_read_u32(usbn_node, + "refclk-frequency", &clock_rate); + if (i) { + dev_err(dev, "No USBN \"clock-frequency\"\n"); + return -ENXIO; + } + switch (clock_rate) { + case 12000000: + initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_12MHZ; + break; + case 24000000: + initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_24MHZ; + break; + case 48000000: + initialize_flags = CVMX_USB_INITIALIZE_FLAGS_CLOCK_48MHZ; + break; + default: + dev_err(dev, "Illegal USBN \"clock-frequency\" %u\n", + clock_rate); + return -ENXIO; + } + + i = of_property_read_string(usbn_node, + "cavium,refclk-type", &clock_type); + if (i) + i = of_property_read_string(usbn_node, + "refclk-type", &clock_type); + + if (!i && strcmp("crystal", clock_type) == 0) + is_crystal_clock = true; + + if (is_crystal_clock) + initialize_flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_XI; + else + initialize_flags |= CVMX_USB_INITIALIZE_FLAGS_CLOCK_XO_GND; + + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res_mem) { + dev_err(dev, "found no memory resource\n"); + return -ENXIO; + } + usb_num = (res_mem->start >> 44) & 1; + + if (irq < 0) { + /* Defective device tree, but we know how to fix it. */ + irq_hw_number_t hwirq = usb_num ? (1 << 6) + 17 : 56; + + irq = irq_create_mapping(NULL, hwirq); + } + + /* + * Set the DMA mask to 64bits so we get buffers already translated for + * DMA. + */ + i = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (i) + return i; + + /* + * Only cn52XX and cn56XX have DWC_OTG USB hardware and the + * IOB priority registers. Under heavy network load USB + * hardware can be starved by the IOB causing a crash. Give + * it a priority boost if it has been waiting more than 400 + * cycles to avoid this situation. + * + * Testing indicates that a cnt_val of 8192 is not sufficient, + * but no failures are seen with 4096. We choose a value of + * 400 to give a safety factor of 10. + */ + if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN56XX)) { + union cvmx_iob_n2c_l2c_pri_cnt pri_cnt; + + pri_cnt.u64 = 0; + pri_cnt.s.cnt_enb = 1; + pri_cnt.s.cnt_val = 400; + cvmx_write_csr(CVMX_IOB_N2C_L2C_PRI_CNT, pri_cnt.u64); + } + + hcd = usb_create_hcd(&octeon_hc_driver, dev, dev_name(dev)); + if (!hcd) { + dev_dbg(dev, "Failed to allocate memory for HCD\n"); + return -1; + } + hcd->uses_new_polling = 1; + usb = (struct octeon_hcd *)hcd->hcd_priv; + + spin_lock_init(&usb->lock); + + usb->init_flags = initialize_flags; + + /* Initialize the USB state structure */ + usb->index = usb_num; + INIT_LIST_HEAD(&usb->idle_pipes); + for (i = 0; i < ARRAY_SIZE(usb->active_pipes); i++) + INIT_LIST_HEAD(&usb->active_pipes[i]); + + /* Due to an errata, CN31XX doesn't support DMA */ + if (OCTEON_IS_MODEL(OCTEON_CN31XX)) { + usb->init_flags |= CVMX_USB_INITIALIZE_FLAGS_NO_DMA; + /* Only use one channel with non DMA */ + usb->idle_hardware_channels = 0x1; + } else if (OCTEON_IS_MODEL(OCTEON_CN5XXX)) { + /* CN5XXX have an errata with channel 3 */ + usb->idle_hardware_channels = 0xf7; + } else { + usb->idle_hardware_channels = 0xff; + } + + status = cvmx_usb_initialize(dev, usb); + if (status) { + dev_dbg(dev, "USB initialization failed with %d\n", status); + usb_put_hcd(hcd); + return -1; + } + + status = usb_add_hcd(hcd, irq, 0); + if (status) { + dev_dbg(dev, "USB add HCD failed with %d\n", status); + usb_put_hcd(hcd); + return -1; + } + device_wakeup_enable(hcd->self.controller); + + dev_info(dev, "Registered HCD for port %d on irq %d\n", usb_num, irq); + + return 0; +} + +static int octeon_usb_remove(struct platform_device *pdev) +{ + int status; + struct device *dev = &pdev->dev; + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct octeon_hcd *usb = hcd_to_octeon(hcd); + unsigned long flags; + + usb_remove_hcd(hcd); + spin_lock_irqsave(&usb->lock, flags); + status = cvmx_usb_shutdown(usb); + spin_unlock_irqrestore(&usb->lock, flags); + if (status) + dev_dbg(dev, "USB shutdown failed with %d\n", status); + + usb_put_hcd(hcd); + + return 0; +} + +static const struct of_device_id octeon_usb_match[] = { + { + .compatible = "cavium,octeon-5750-usbc", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, octeon_usb_match); + +static struct platform_driver octeon_usb_driver = { + .driver = { + .name = "octeon-hcd", + .of_match_table = octeon_usb_match, + }, + .probe = octeon_usb_probe, + .remove = octeon_usb_remove, +}; + +static int __init octeon_usb_driver_init(void) +{ + if (usb_disabled()) + return 0; + + return platform_driver_register(&octeon_usb_driver); +} +module_init(octeon_usb_driver_init); + +static void __exit octeon_usb_driver_exit(void) +{ + if (usb_disabled()) + return; + + platform_driver_unregister(&octeon_usb_driver); +} +module_exit(octeon_usb_driver_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Cavium, Inc. <support@cavium.com>"); +MODULE_DESCRIPTION("Cavium Inc. OCTEON USB Host driver."); diff --git a/drivers/staging/octeon-usb/octeon-hcd.h b/drivers/staging/octeon-usb/octeon-hcd.h new file mode 100644 index 000000000000..9ed619c93a4e --- /dev/null +++ b/drivers/staging/octeon-usb/octeon-hcd.h @@ -0,0 +1,1847 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Octeon HCD hardware register definitions. + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * Some parts of the code were originally released under BSD license: + * + * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * * Neither the name of Cavium Networks nor the names of + * its contributors may be used to endorse or promote products + * derived from this software without specific prior written + * permission. + * + * This Software, including technical data, may be subject to U.S. export + * control laws, including the U.S. Export Administration Act and its associated + * regulations, and may be subject to export or import regulations in other + * countries. + * + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" + * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR + * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO + * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION + * OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM + * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, + * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF + * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR + * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. + */ + +#ifndef __OCTEON_HCD_H__ +#define __OCTEON_HCD_H__ + +#include <asm/bitfield.h> + +#define CVMX_USBCXBASE 0x00016F0010000000ull +#define CVMX_USBCXREG1(reg, bid) \ + (CVMX_ADD_IO_SEG(CVMX_USBCXBASE | reg) + \ + ((bid) & 1) * 0x100000000000ull) +#define CVMX_USBCXREG2(reg, bid, off) \ + (CVMX_ADD_IO_SEG(CVMX_USBCXBASE | reg) + \ + (((off) & 7) + ((bid) & 1) * 0x8000000000ull) * 32) + +#define CVMX_USBCX_GAHBCFG(bid) CVMX_USBCXREG1(0x008, bid) +#define CVMX_USBCX_GHWCFG3(bid) CVMX_USBCXREG1(0x04c, bid) +#define CVMX_USBCX_GINTMSK(bid) CVMX_USBCXREG1(0x018, bid) +#define CVMX_USBCX_GINTSTS(bid) CVMX_USBCXREG1(0x014, bid) +#define CVMX_USBCX_GNPTXFSIZ(bid) CVMX_USBCXREG1(0x028, bid) +#define CVMX_USBCX_GNPTXSTS(bid) CVMX_USBCXREG1(0x02c, bid) +#define CVMX_USBCX_GOTGCTL(bid) CVMX_USBCXREG1(0x000, bid) +#define CVMX_USBCX_GRSTCTL(bid) CVMX_USBCXREG1(0x010, bid) +#define CVMX_USBCX_GRXFSIZ(bid) CVMX_USBCXREG1(0x024, bid) +#define CVMX_USBCX_GRXSTSPH(bid) CVMX_USBCXREG1(0x020, bid) +#define CVMX_USBCX_GUSBCFG(bid) CVMX_USBCXREG1(0x00c, bid) +#define CVMX_USBCX_HAINT(bid) CVMX_USBCXREG1(0x414, bid) +#define CVMX_USBCX_HAINTMSK(bid) CVMX_USBCXREG1(0x418, bid) +#define CVMX_USBCX_HCCHARX(off, bid) CVMX_USBCXREG2(0x500, bid, off) +#define CVMX_USBCX_HCFG(bid) CVMX_USBCXREG1(0x400, bid) +#define CVMX_USBCX_HCINTMSKX(off, bid) CVMX_USBCXREG2(0x50c, bid, off) +#define CVMX_USBCX_HCINTX(off, bid) CVMX_USBCXREG2(0x508, bid, off) +#define CVMX_USBCX_HCSPLTX(off, bid) CVMX_USBCXREG2(0x504, bid, off) +#define CVMX_USBCX_HCTSIZX(off, bid) CVMX_USBCXREG2(0x510, bid, off) +#define CVMX_USBCX_HFIR(bid) CVMX_USBCXREG1(0x404, bid) +#define CVMX_USBCX_HFNUM(bid) CVMX_USBCXREG1(0x408, bid) +#define CVMX_USBCX_HPRT(bid) CVMX_USBCXREG1(0x440, bid) +#define CVMX_USBCX_HPTXFSIZ(bid) CVMX_USBCXREG1(0x100, bid) +#define CVMX_USBCX_HPTXSTS(bid) CVMX_USBCXREG1(0x410, bid) + +#define CVMX_USBNXBID1(bid) (((bid) & 1) * 0x10000000ull) +#define CVMX_USBNXBID2(bid) (((bid) & 1) * 0x100000000000ull) + +#define CVMX_USBNXREG1(reg, bid) \ + (CVMX_ADD_IO_SEG(0x0001180068000000ull | reg) + CVMX_USBNXBID1(bid)) +#define CVMX_USBNXREG2(reg, bid) \ + (CVMX_ADD_IO_SEG(0x00016F0000000000ull | reg) + CVMX_USBNXBID2(bid)) + +#define CVMX_USBNX_CLK_CTL(bid) CVMX_USBNXREG1(0x10, bid) +#define CVMX_USBNX_DMA0_INB_CHN0(bid) CVMX_USBNXREG2(0x818, bid) +#define CVMX_USBNX_DMA0_OUTB_CHN0(bid) CVMX_USBNXREG2(0x858, bid) +#define CVMX_USBNX_USBP_CTL_STATUS(bid) CVMX_USBNXREG1(0x18, bid) + +/** + * cvmx_usbc#_gahbcfg + * + * Core AHB Configuration Register (GAHBCFG) + * + * This register can be used to configure the core after power-on or a change in + * mode of operation. This register mainly contains AHB system-related + * configuration parameters. The AHB is the processor interface to the O2P USB + * core. In general, software need not know about this interface except to + * program the values as specified. + * + * The application must program this register as part of the O2P USB core + * initialization. Do not change this register after the initial programming. + */ +union cvmx_usbcx_gahbcfg { + u32 u32; + /** + * struct cvmx_usbcx_gahbcfg_s + * @ptxfemplvl: Periodic TxFIFO Empty Level (PTxFEmpLvl) + * Software should set this bit to 0x1. + * Indicates when the Periodic TxFIFO Empty Interrupt bit in the + * Core Interrupt register (GINTSTS.PTxFEmp) is triggered. This + * bit is used only in Slave mode. + * * 1'b0: GINTSTS.PTxFEmp interrupt indicates that the Periodic + * TxFIFO is half empty + * * 1'b1: GINTSTS.PTxFEmp interrupt indicates that the Periodic + * TxFIFO is completely empty + * @nptxfemplvl: Non-Periodic TxFIFO Empty Level (NPTxFEmpLvl) + * Software should set this bit to 0x1. + * Indicates when the Non-Periodic TxFIFO Empty Interrupt bit in + * the Core Interrupt register (GINTSTS.NPTxFEmp) is triggered. + * This bit is used only in Slave mode. + * * 1'b0: GINTSTS.NPTxFEmp interrupt indicates that the Non- + * Periodic TxFIFO is half empty + * * 1'b1: GINTSTS.NPTxFEmp interrupt indicates that the Non- + * Periodic TxFIFO is completely empty + * @dmaen: DMA Enable (DMAEn) + * * 1'b0: Core operates in Slave mode + * * 1'b1: Core operates in a DMA mode + * @hbstlen: Burst Length/Type (HBstLen) + * This field has not effect and should be left as 0x0. + * @glblintrmsk: Global Interrupt Mask (GlblIntrMsk) + * Software should set this field to 0x1. + * The application uses this bit to mask or unmask the interrupt + * line assertion to itself. Irrespective of this bit's setting, + * the interrupt status registers are updated by the core. + * * 1'b0: Mask the interrupt assertion to the application. + * * 1'b1: Unmask the interrupt assertion to the application. + */ + struct cvmx_usbcx_gahbcfg_s { + __BITFIELD_FIELD(u32 reserved_9_31 : 23, + __BITFIELD_FIELD(u32 ptxfemplvl : 1, + __BITFIELD_FIELD(u32 nptxfemplvl : 1, + __BITFIELD_FIELD(u32 reserved_6_6 : 1, + __BITFIELD_FIELD(u32 dmaen : 1, + __BITFIELD_FIELD(u32 hbstlen : 4, + __BITFIELD_FIELD(u32 glblintrmsk : 1, + ;))))))) + } s; +}; + +/** + * cvmx_usbc#_ghwcfg3 + * + * User HW Config3 Register (GHWCFG3) + * + * This register contains the configuration options of the O2P USB core. + */ +union cvmx_usbcx_ghwcfg3 { + u32 u32; + /** + * struct cvmx_usbcx_ghwcfg3_s + * @dfifodepth: DFIFO Depth (DfifoDepth) + * This value is in terms of 32-bit words. + * * Minimum value is 32 + * * Maximum value is 32768 + * @ahbphysync: AHB and PHY Synchronous (AhbPhySync) + * Indicates whether AHB and PHY clocks are synchronous to + * each other. + * * 1'b0: No + * * 1'b1: Yes + * This bit is tied to 1. + * @rsttype: Reset Style for Clocked always Blocks in RTL (RstType) + * * 1'b0: Asynchronous reset is used in the core + * * 1'b1: Synchronous reset is used in the core + * @optfeature: Optional Features Removed (OptFeature) + * Indicates whether the User ID register, GPIO interface ports, + * and SOF toggle and counter ports were removed for gate count + * optimization. + * @vendor_control_interface_support: Vendor Control Interface Support + * * 1'b0: Vendor Control Interface is not available on the core. + * * 1'b1: Vendor Control Interface is available. + * @i2c_selection: I2C Selection + * * 1'b0: I2C Interface is not available on the core. + * * 1'b1: I2C Interface is available on the core. + * @otgen: OTG Function Enabled (OtgEn) + * The application uses this bit to indicate the O2P USB core's + * OTG capabilities. + * * 1'b0: Not OTG capable + * * 1'b1: OTG Capable + * @pktsizewidth: Width of Packet Size Counters (PktSizeWidth) + * * 3'b000: 4 bits + * * 3'b001: 5 bits + * * 3'b010: 6 bits + * * 3'b011: 7 bits + * * 3'b100: 8 bits + * * 3'b101: 9 bits + * * 3'b110: 10 bits + * * Others: Reserved + * @xfersizewidth: Width of Transfer Size Counters (XferSizeWidth) + * * 4'b0000: 11 bits + * * 4'b0001: 12 bits + * - ... + * * 4'b1000: 19 bits + * * Others: Reserved + */ + struct cvmx_usbcx_ghwcfg3_s { + __BITFIELD_FIELD(u32 dfifodepth : 16, + __BITFIELD_FIELD(u32 reserved_13_15 : 3, + __BITFIELD_FIELD(u32 ahbphysync : 1, + __BITFIELD_FIELD(u32 rsttype : 1, + __BITFIELD_FIELD(u32 optfeature : 1, + __BITFIELD_FIELD(u32 vendor_control_interface_support : 1, + __BITFIELD_FIELD(u32 i2c_selection : 1, + __BITFIELD_FIELD(u32 otgen : 1, + __BITFIELD_FIELD(u32 pktsizewidth : 3, + __BITFIELD_FIELD(u32 xfersizewidth : 4, + ;)))))))))) + } s; +}; + +/** + * cvmx_usbc#_gintmsk + * + * Core Interrupt Mask Register (GINTMSK) + * + * This register works with the Core Interrupt register to interrupt the + * application. When an interrupt bit is masked, the interrupt associated with + * that bit will not be generated. However, the Core Interrupt (GINTSTS) + * register bit corresponding to that interrupt will still be set. + * Mask interrupt: 1'b0, Unmask interrupt: 1'b1 + */ +union cvmx_usbcx_gintmsk { + u32 u32; + /** + * struct cvmx_usbcx_gintmsk_s + * @wkupintmsk: Resume/Remote Wakeup Detected Interrupt Mask + * (WkUpIntMsk) + * @sessreqintmsk: Session Request/New Session Detected Interrupt Mask + * (SessReqIntMsk) + * @disconnintmsk: Disconnect Detected Interrupt Mask (DisconnIntMsk) + * @conidstschngmsk: Connector ID Status Change Mask (ConIDStsChngMsk) + * @ptxfempmsk: Periodic TxFIFO Empty Mask (PTxFEmpMsk) + * @hchintmsk: Host Channels Interrupt Mask (HChIntMsk) + * @prtintmsk: Host Port Interrupt Mask (PrtIntMsk) + * @fetsuspmsk: Data Fetch Suspended Mask (FetSuspMsk) + * @incomplpmsk: Incomplete Periodic Transfer Mask (incomplPMsk) + * Incomplete Isochronous OUT Transfer Mask + * (incompISOOUTMsk) + * @incompisoinmsk: Incomplete Isochronous IN Transfer Mask + * (incompISOINMsk) + * @oepintmsk: OUT Endpoints Interrupt Mask (OEPIntMsk) + * @inepintmsk: IN Endpoints Interrupt Mask (INEPIntMsk) + * @epmismsk: Endpoint Mismatch Interrupt Mask (EPMisMsk) + * @eopfmsk: End of Periodic Frame Interrupt Mask (EOPFMsk) + * @isooutdropmsk: Isochronous OUT Packet Dropped Interrupt Mask + * (ISOOutDropMsk) + * @enumdonemsk: Enumeration Done Mask (EnumDoneMsk) + * @usbrstmsk: USB Reset Mask (USBRstMsk) + * @usbsuspmsk: USB Suspend Mask (USBSuspMsk) + * @erlysuspmsk: Early Suspend Mask (ErlySuspMsk) + * @i2cint: I2C Interrupt Mask (I2CINT) + * @ulpickintmsk: ULPI Carkit Interrupt Mask (ULPICKINTMsk) + * I2C Carkit Interrupt Mask (I2CCKINTMsk) + * @goutnakeffmsk: Global OUT NAK Effective Mask (GOUTNakEffMsk) + * @ginnakeffmsk: Global Non-Periodic IN NAK Effective Mask + * (GINNakEffMsk) + * @nptxfempmsk: Non-Periodic TxFIFO Empty Mask (NPTxFEmpMsk) + * @rxflvlmsk: Receive FIFO Non-Empty Mask (RxFLvlMsk) + * @sofmsk: Start of (micro)Frame Mask (SofMsk) + * @otgintmsk: OTG Interrupt Mask (OTGIntMsk) + * @modemismsk: Mode Mismatch Interrupt Mask (ModeMisMsk) + */ + struct cvmx_usbcx_gintmsk_s { + __BITFIELD_FIELD(u32 wkupintmsk : 1, + __BITFIELD_FIELD(u32 sessreqintmsk : 1, + __BITFIELD_FIELD(u32 disconnintmsk : 1, + __BITFIELD_FIELD(u32 conidstschngmsk : 1, + __BITFIELD_FIELD(u32 reserved_27_27 : 1, + __BITFIELD_FIELD(u32 ptxfempmsk : 1, + __BITFIELD_FIELD(u32 hchintmsk : 1, + __BITFIELD_FIELD(u32 prtintmsk : 1, + __BITFIELD_FIELD(u32 reserved_23_23 : 1, + __BITFIELD_FIELD(u32 fetsuspmsk : 1, + __BITFIELD_FIELD(u32 incomplpmsk : 1, + __BITFIELD_FIELD(u32 incompisoinmsk : 1, + __BITFIELD_FIELD(u32 oepintmsk : 1, + __BITFIELD_FIELD(u32 inepintmsk : 1, + __BITFIELD_FIELD(u32 epmismsk : 1, + __BITFIELD_FIELD(u32 reserved_16_16 : 1, + __BITFIELD_FIELD(u32 eopfmsk : 1, + __BITFIELD_FIELD(u32 isooutdropmsk : 1, + __BITFIELD_FIELD(u32 enumdonemsk : 1, + __BITFIELD_FIELD(u32 usbrstmsk : 1, + __BITFIELD_FIELD(u32 usbsuspmsk : 1, + __BITFIELD_FIELD(u32 erlysuspmsk : 1, + __BITFIELD_FIELD(u32 i2cint : 1, + __BITFIELD_FIELD(u32 ulpickintmsk : 1, + __BITFIELD_FIELD(u32 goutnakeffmsk : 1, + __BITFIELD_FIELD(u32 ginnakeffmsk : 1, + __BITFIELD_FIELD(u32 nptxfempmsk : 1, + __BITFIELD_FIELD(u32 rxflvlmsk : 1, + __BITFIELD_FIELD(u32 sofmsk : 1, + __BITFIELD_FIELD(u32 otgintmsk : 1, + __BITFIELD_FIELD(u32 modemismsk : 1, + __BITFIELD_FIELD(u32 reserved_0_0 : 1, + ;)))))))))))))))))))))))))))))))) + } s; +}; + +/** + * cvmx_usbc#_gintsts + * + * Core Interrupt Register (GINTSTS) + * + * This register interrupts the application for system-level events in the + * current mode of operation (Device mode or Host mode). It is shown in + * Interrupt. Some of the bits in this register are valid only in Host mode, + * while others are valid in Device mode only. This register also indicates the + * current mode of operation. In order to clear the interrupt status bits of + * type R_SS_WC, the application must write 1'b1 into the bit. The FIFO status + * interrupts are read only; once software reads from or writes to the FIFO + * while servicing these interrupts, FIFO interrupt conditions are cleared + * automatically. + */ +union cvmx_usbcx_gintsts { + u32 u32; + /** + * struct cvmx_usbcx_gintsts_s + * @wkupint: Resume/Remote Wakeup Detected Interrupt (WkUpInt) + * In Device mode, this interrupt is asserted when a resume is + * detected on the USB. In Host mode, this interrupt is asserted + * when a remote wakeup is detected on the USB. + * For more information on how to use this interrupt, see "Partial + * Power-Down and Clock Gating Programming Model" on + * page 353. + * @sessreqint: Session Request/New Session Detected Interrupt + * (SessReqInt) + * In Host mode, this interrupt is asserted when a session request + * is detected from the device. In Device mode, this interrupt is + * asserted when the utmiotg_bvalid signal goes high. + * For more information on how to use this interrupt, see "Partial + * Power-Down and Clock Gating Programming Model" on + * page 353. + * @disconnint: Disconnect Detected Interrupt (DisconnInt) + * Asserted when a device disconnect is detected. + * @conidstschng: Connector ID Status Change (ConIDStsChng) + * The core sets this bit when there is a change in connector ID + * status. + * @ptxfemp: Periodic TxFIFO Empty (PTxFEmp) + * Asserted when the Periodic Transmit FIFO is either half or + * completely empty and there is space for at least one entry to be + * written in the Periodic Request Queue. The half or completely + * empty status is determined by the Periodic TxFIFO Empty Level + * bit in the Core AHB Configuration register + * (GAHBCFG.PTxFEmpLvl). + * @hchint: Host Channels Interrupt (HChInt) + * The core sets this bit to indicate that an interrupt is pending + * on one of the channels of the core (in Host mode). The + * application must read the Host All Channels Interrupt (HAINT) + * register to determine the exact number of the channel on which + * the interrupt occurred, and then read the corresponding Host + * Channel-n Interrupt (HCINTn) register to determine the exact + * cause of the interrupt. The application must clear the + * appropriate status bit in the HCINTn register to clear this bit. + * @prtint: Host Port Interrupt (PrtInt) + * The core sets this bit to indicate a change in port status of + * one of the O2P USB core ports in Host mode. The application must + * read the Host Port Control and Status (HPRT) register to + * determine the exact event that caused this interrupt. The + * application must clear the appropriate status bit in the Host + * Port Control and Status register to clear this bit. + * @fetsusp: Data Fetch Suspended (FetSusp) + * This interrupt is valid only in DMA mode. This interrupt + * indicates that the core has stopped fetching data for IN + * endpoints due to the unavailability of TxFIFO space or Request + * Queue space. This interrupt is used by the application for an + * endpoint mismatch algorithm. + * @incomplp: Incomplete Periodic Transfer (incomplP) + * In Host mode, the core sets this interrupt bit when there are + * incomplete periodic transactions still pending which are + * scheduled for the current microframe. + * Incomplete Isochronous OUT Transfer (incompISOOUT) + * The Device mode, the core sets this interrupt to indicate that + * there is at least one isochronous OUT endpoint on which the + * transfer is not completed in the current microframe. This + * interrupt is asserted along with the End of Periodic Frame + * Interrupt (EOPF) bit in this register. + * @incompisoin: Incomplete Isochronous IN Transfer (incompISOIN) + * The core sets this interrupt to indicate that there is at least + * one isochronous IN endpoint on which the transfer is not + * completed in the current microframe. This interrupt is asserted + * along with the End of Periodic Frame Interrupt (EOPF) bit in + * this register. + * @oepint: OUT Endpoints Interrupt (OEPInt) + * The core sets this bit to indicate that an interrupt is pending + * on one of the OUT endpoints of the core (in Device mode). The + * application must read the Device All Endpoints Interrupt + * (DAINT) register to determine the exact number of the OUT + * endpoint on which the interrupt occurred, and then read the + * corresponding Device OUT Endpoint-n Interrupt (DOEPINTn) + * register to determine the exact cause of the interrupt. The + * application must clear the appropriate status bit in the + * corresponding DOEPINTn register to clear this bit. + * @iepint: IN Endpoints Interrupt (IEPInt) + * The core sets this bit to indicate that an interrupt is pending + * on one of the IN endpoints of the core (in Device mode). The + * application must read the Device All Endpoints Interrupt + * (DAINT) register to determine the exact number of the IN + * endpoint on which the interrupt occurred, and then read the + * corresponding Device IN Endpoint-n Interrupt (DIEPINTn) + * register to determine the exact cause of the interrupt. The + * application must clear the appropriate status bit in the + * corresponding DIEPINTn register to clear this bit. + * @epmis: Endpoint Mismatch Interrupt (EPMis) + * Indicates that an IN token has been received for a non-periodic + * endpoint, but the data for another endpoint is present in the + * top of the Non-Periodic Transmit FIFO and the IN endpoint + * mismatch count programmed by the application has expired. + * @eopf: End of Periodic Frame Interrupt (EOPF) + * Indicates that the period specified in the Periodic Frame + * Interval field of the Device Configuration register + * (DCFG.PerFrInt) has been reached in the current microframe. + * @isooutdrop: Isochronous OUT Packet Dropped Interrupt (ISOOutDrop) + * The core sets this bit when it fails to write an isochronous OUT + * packet into the RxFIFO because the RxFIFO doesn't have + * enough space to accommodate a maximum packet size packet + * for the isochronous OUT endpoint. + * @enumdone: Enumeration Done (EnumDone) + * The core sets this bit to indicate that speed enumeration is + * complete. The application must read the Device Status (DSTS) + * register to obtain the enumerated speed. + * @usbrst: USB Reset (USBRst) + * The core sets this bit to indicate that a reset is detected on + * the USB. + * @usbsusp: USB Suspend (USBSusp) + * The core sets this bit to indicate that a suspend was detected + * on the USB. The core enters the Suspended state when there + * is no activity on the phy_line_state_i signal for an extended + * period of time. + * @erlysusp: Early Suspend (ErlySusp) + * The core sets this bit to indicate that an Idle state has been + * detected on the USB for 3 ms. + * @i2cint: I2C Interrupt (I2CINT) + * This bit is always 0x0. + * @ulpickint: ULPI Carkit Interrupt (ULPICKINT) + * This bit is always 0x0. + * @goutnakeff: Global OUT NAK Effective (GOUTNakEff) + * Indicates that the Set Global OUT NAK bit in the Device Control + * register (DCTL.SGOUTNak), set by the application, has taken + * effect in the core. This bit can be cleared by writing the Clear + * Global OUT NAK bit in the Device Control register + * (DCTL.CGOUTNak). + * @ginnakeff: Global IN Non-Periodic NAK Effective (GINNakEff) + * Indicates that the Set Global Non-Periodic IN NAK bit in the + * Device Control register (DCTL.SGNPInNak), set by the + * application, has taken effect in the core. That is, the core has + * sampled the Global IN NAK bit set by the application. This bit + * can be cleared by clearing the Clear Global Non-Periodic IN + * NAK bit in the Device Control register (DCTL.CGNPInNak). + * This interrupt does not necessarily mean that a NAK handshake + * is sent out on the USB. The STALL bit takes precedence over + * the NAK bit. + * @nptxfemp: Non-Periodic TxFIFO Empty (NPTxFEmp) + * This interrupt is asserted when the Non-Periodic TxFIFO is + * either half or completely empty, and there is space for at least + * one entry to be written to the Non-Periodic Transmit Request + * Queue. The half or completely empty status is determined by + * the Non-Periodic TxFIFO Empty Level bit in the Core AHB + * Configuration register (GAHBCFG.NPTxFEmpLvl). + * @rxflvl: RxFIFO Non-Empty (RxFLvl) + * Indicates that there is at least one packet pending to be read + * from the RxFIFO. + * @sof: Start of (micro)Frame (Sof) + * In Host mode, the core sets this bit to indicate that an SOF + * (FS), micro-SOF (HS), or Keep-Alive (LS) is transmitted on the + * USB. The application must write a 1 to this bit to clear the + * interrupt. + * In Device mode, in the core sets this bit to indicate that an + * SOF token has been received on the USB. The application can read + * the Device Status register to get the current (micro)frame + * number. This interrupt is seen only when the core is operating + * at either HS or FS. + * @otgint: OTG Interrupt (OTGInt) + * The core sets this bit to indicate an OTG protocol event. The + * application must read the OTG Interrupt Status (GOTGINT) + * register to determine the exact event that caused this + * interrupt. The application must clear the appropriate status bit + * in the GOTGINT register to clear this bit. + * @modemis: Mode Mismatch Interrupt (ModeMis) + * The core sets this bit when the application is trying to access: + * * A Host mode register, when the core is operating in Device + * mode + * * A Device mode register, when the core is operating in Host + * mode + * The register access is completed on the AHB with an OKAY + * response, but is ignored by the core internally and doesn't + * affect the operation of the core. + * @curmod: Current Mode of Operation (CurMod) + * Indicates the current mode of operation. + * * 1'b0: Device mode + * * 1'b1: Host mode + */ + struct cvmx_usbcx_gintsts_s { + __BITFIELD_FIELD(u32 wkupint : 1, + __BITFIELD_FIELD(u32 sessreqint : 1, + __BITFIELD_FIELD(u32 disconnint : 1, + __BITFIELD_FIELD(u32 conidstschng : 1, + __BITFIELD_FIELD(u32 reserved_27_27 : 1, + __BITFIELD_FIELD(u32 ptxfemp : 1, + __BITFIELD_FIELD(u32 hchint : 1, + __BITFIELD_FIELD(u32 prtint : 1, + __BITFIELD_FIELD(u32 reserved_23_23 : 1, + __BITFIELD_FIELD(u32 fetsusp : 1, + __BITFIELD_FIELD(u32 incomplp : 1, + __BITFIELD_FIELD(u32 incompisoin : 1, + __BITFIELD_FIELD(u32 oepint : 1, + __BITFIELD_FIELD(u32 iepint : 1, + __BITFIELD_FIELD(u32 epmis : 1, + __BITFIELD_FIELD(u32 reserved_16_16 : 1, + __BITFIELD_FIELD(u32 eopf : 1, + __BITFIELD_FIELD(u32 isooutdrop : 1, + __BITFIELD_FIELD(u32 enumdone : 1, + __BITFIELD_FIELD(u32 usbrst : 1, + __BITFIELD_FIELD(u32 usbsusp : 1, + __BITFIELD_FIELD(u32 erlysusp : 1, + __BITFIELD_FIELD(u32 i2cint : 1, + __BITFIELD_FIELD(u32 ulpickint : 1, + __BITFIELD_FIELD(u32 goutnakeff : 1, + __BITFIELD_FIELD(u32 ginnakeff : 1, + __BITFIELD_FIELD(u32 nptxfemp : 1, + __BITFIELD_FIELD(u32 rxflvl : 1, + __BITFIELD_FIELD(u32 sof : 1, + __BITFIELD_FIELD(u32 otgint : 1, + __BITFIELD_FIELD(u32 modemis : 1, + __BITFIELD_FIELD(u32 curmod : 1, + ;)))))))))))))))))))))))))))))))) + } s; +}; + +/** + * cvmx_usbc#_gnptxfsiz + * + * Non-Periodic Transmit FIFO Size Register (GNPTXFSIZ) + * + * The application can program the RAM size and the memory start address for the + * Non-Periodic TxFIFO. + */ +union cvmx_usbcx_gnptxfsiz { + u32 u32; + /** + * struct cvmx_usbcx_gnptxfsiz_s + * @nptxfdep: Non-Periodic TxFIFO Depth (NPTxFDep) + * This value is in terms of 32-bit words. + * Minimum value is 16 + * Maximum value is 32768 + * @nptxfstaddr: Non-Periodic Transmit RAM Start Address (NPTxFStAddr) + * This field contains the memory start address for Non-Periodic + * Transmit FIFO RAM. + */ + struct cvmx_usbcx_gnptxfsiz_s { + __BITFIELD_FIELD(u32 nptxfdep : 16, + __BITFIELD_FIELD(u32 nptxfstaddr : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_gnptxsts + * + * Non-Periodic Transmit FIFO/Queue Status Register (GNPTXSTS) + * + * This read-only register contains the free space information for the + * Non-Periodic TxFIFO and the Non-Periodic Transmit Request Queue. + */ +union cvmx_usbcx_gnptxsts { + u32 u32; + /** + * struct cvmx_usbcx_gnptxsts_s + * @nptxqtop: Top of the Non-Periodic Transmit Request Queue (NPTxQTop) + * Entry in the Non-Periodic Tx Request Queue that is currently + * being processed by the MAC. + * * Bits [30:27]: Channel/endpoint number + * * Bits [26:25]: + * - 2'b00: IN/OUT token + * - 2'b01: Zero-length transmit packet (device IN/host OUT) + * - 2'b10: PING/CSPLIT token + * - 2'b11: Channel halt command + * * Bit [24]: Terminate (last entry for selected channel/endpoint) + * @nptxqspcavail: Non-Periodic Transmit Request Queue Space Available + * (NPTxQSpcAvail) + * Indicates the amount of free space available in the Non- + * Periodic Transmit Request Queue. This queue holds both IN + * and OUT requests in Host mode. Device mode has only IN + * requests. + * * 8'h0: Non-Periodic Transmit Request Queue is full + * * 8'h1: 1 location available + * * 8'h2: 2 locations available + * * n: n locations available (0..8) + * * Others: Reserved + * @nptxfspcavail: Non-Periodic TxFIFO Space Avail (NPTxFSpcAvail) + * Indicates the amount of free space available in the Non- + * Periodic TxFIFO. + * Values are in terms of 32-bit words. + * * 16'h0: Non-Periodic TxFIFO is full + * * 16'h1: 1 word available + * * 16'h2: 2 words available + * * 16'hn: n words available (where 0..32768) + * * 16'h8000: 32768 words available + * * Others: Reserved + */ + struct cvmx_usbcx_gnptxsts_s { + __BITFIELD_FIELD(u32 reserved_31_31 : 1, + __BITFIELD_FIELD(u32 nptxqtop : 7, + __BITFIELD_FIELD(u32 nptxqspcavail : 8, + __BITFIELD_FIELD(u32 nptxfspcavail : 16, + ;)))) + } s; +}; + +/** + * cvmx_usbc#_grstctl + * + * Core Reset Register (GRSTCTL) + * + * The application uses this register to reset various hardware features inside + * the core. + */ +union cvmx_usbcx_grstctl { + u32 u32; + /** + * struct cvmx_usbcx_grstctl_s + * @ahbidle: AHB Master Idle (AHBIdle) + * Indicates that the AHB Master State Machine is in the IDLE + * condition. + * @dmareq: DMA Request Signal (DMAReq) + * Indicates that the DMA request is in progress. Used for debug. + * @txfnum: TxFIFO Number (TxFNum) + * This is the FIFO number that must be flushed using the TxFIFO + * Flush bit. This field must not be changed until the core clears + * the TxFIFO Flush bit. + * * 5'h0: Non-Periodic TxFIFO flush + * * 5'h1: Periodic TxFIFO 1 flush in Device mode or Periodic + * TxFIFO flush in Host mode + * * 5'h2: Periodic TxFIFO 2 flush in Device mode + * - ... + * * 5'hF: Periodic TxFIFO 15 flush in Device mode + * * 5'h10: Flush all the Periodic and Non-Periodic TxFIFOs in the + * core + * @txfflsh: TxFIFO Flush (TxFFlsh) + * This bit selectively flushes a single or all transmit FIFOs, but + * cannot do so if the core is in the midst of a transaction. + * The application must only write this bit after checking that the + * core is neither writing to the TxFIFO nor reading from the + * TxFIFO. + * The application must wait until the core clears this bit before + * performing any operations. This bit takes 8 clocks (of phy_clk + * or hclk, whichever is slower) to clear. + * @rxfflsh: RxFIFO Flush (RxFFlsh) + * The application can flush the entire RxFIFO using this bit, but + * must first ensure that the core is not in the middle of a + * transaction. + * The application must only write to this bit after checking that + * the core is neither reading from the RxFIFO nor writing to the + * RxFIFO. + * The application must wait until the bit is cleared before + * performing any other operations. This bit will take 8 clocks + * (slowest of PHY or AHB clock) to clear. + * @intknqflsh: IN Token Sequence Learning Queue Flush (INTknQFlsh) + * The application writes this bit to flush the IN Token Sequence + * Learning Queue. + * @frmcntrrst: Host Frame Counter Reset (FrmCntrRst) + * The application writes this bit to reset the (micro)frame number + * counter inside the core. When the (micro)frame counter is reset, + * the subsequent SOF sent out by the core will have a + * (micro)frame number of 0. + * @hsftrst: HClk Soft Reset (HSftRst) + * The application uses this bit to flush the control logic in the + * AHB Clock domain. Only AHB Clock Domain pipelines are reset. + * * FIFOs are not flushed with this bit. + * * All state machines in the AHB clock domain are reset to the + * Idle state after terminating the transactions on the AHB, + * following the protocol. + * * CSR control bits used by the AHB clock domain state + * machines are cleared. + * * To clear this interrupt, status mask bits that control the + * interrupt status and are generated by the AHB clock domain + * state machine are cleared. + * * Because interrupt status bits are not cleared, the application + * can get the status of any core events that occurred after it set + * this bit. + * This is a self-clearing bit that the core clears after all + * necessary logic is reset in the core. This may take several + * clocks, depending on the core's current state. + * @csftrst: Core Soft Reset (CSftRst) + * Resets the hclk and phy_clock domains as follows: + * * Clears the interrupts and all the CSR registers except the + * following register bits: + * - PCGCCTL.RstPdwnModule + * - PCGCCTL.GateHclk + * - PCGCCTL.PwrClmp + * - PCGCCTL.StopPPhyLPwrClkSelclk + * - GUSBCFG.PhyLPwrClkSel + * - GUSBCFG.DDRSel + * - GUSBCFG.PHYSel + * - GUSBCFG.FSIntf + * - GUSBCFG.ULPI_UTMI_Sel + * - GUSBCFG.PHYIf + * - HCFG.FSLSPclkSel + * - DCFG.DevSpd + * * All module state machines (except the AHB Slave Unit) are + * reset to the IDLE state, and all the transmit FIFOs and the + * receive FIFO are flushed. + * * Any transactions on the AHB Master are terminated as soon + * as possible, after gracefully completing the last data phase of + * an AHB transfer. Any transactions on the USB are terminated + * immediately. + * The application can write to this bit any time it wants to reset + * the core. This is a self-clearing bit and the core clears this + * bit after all the necessary logic is reset in the core, which + * may take several clocks, depending on the current state of the + * core. Once this bit is cleared software should wait at least 3 + * PHY clocks before doing any access to the PHY domain + * (synchronization delay). Software should also should check that + * bit 31 of this register is 1 (AHB Master is IDLE) before + * starting any operation. + * Typically software reset is used during software development + * and also when you dynamically change the PHY selection bits + * in the USB configuration registers listed above. When you + * change the PHY, the corresponding clock for the PHY is + * selected and used in the PHY domain. Once a new clock is + * selected, the PHY domain has to be reset for proper operation. + */ + struct cvmx_usbcx_grstctl_s { + __BITFIELD_FIELD(u32 ahbidle : 1, + __BITFIELD_FIELD(u32 dmareq : 1, + __BITFIELD_FIELD(u32 reserved_11_29 : 19, + __BITFIELD_FIELD(u32 txfnum : 5, + __BITFIELD_FIELD(u32 txfflsh : 1, + __BITFIELD_FIELD(u32 rxfflsh : 1, + __BITFIELD_FIELD(u32 intknqflsh : 1, + __BITFIELD_FIELD(u32 frmcntrrst : 1, + __BITFIELD_FIELD(u32 hsftrst : 1, + __BITFIELD_FIELD(u32 csftrst : 1, + ;)))))))))) + } s; +}; + +/** + * cvmx_usbc#_grxfsiz + * + * Receive FIFO Size Register (GRXFSIZ) + * + * The application can program the RAM size that must be allocated to the + * RxFIFO. + */ +union cvmx_usbcx_grxfsiz { + u32 u32; + /** + * struct cvmx_usbcx_grxfsiz_s + * @rxfdep: RxFIFO Depth (RxFDep) + * This value is in terms of 32-bit words. + * * Minimum value is 16 + * * Maximum value is 32768 + */ + struct cvmx_usbcx_grxfsiz_s { + __BITFIELD_FIELD(u32 reserved_16_31 : 16, + __BITFIELD_FIELD(u32 rxfdep : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_grxstsph + * + * Receive Status Read and Pop Register, Host Mode (GRXSTSPH) + * + * A read to the Receive Status Read and Pop register returns and additionally + * pops the top data entry out of the RxFIFO. + * This Description is only valid when the core is in Host Mode. For Device Mode + * use USBC_GRXSTSPD instead. + * NOTE: GRXSTSPH and GRXSTSPD are physically the same register and share the + * same offset in the O2P USB core. The offset difference shown in this + * document is for software clarity and is actually ignored by the + * hardware. + */ +union cvmx_usbcx_grxstsph { + u32 u32; + /** + * struct cvmx_usbcx_grxstsph_s + * @pktsts: Packet Status (PktSts) + * Indicates the status of the received packet + * * 4'b0010: IN data packet received + * * 4'b0011: IN transfer completed (triggers an interrupt) + * * 4'b0101: Data toggle error (triggers an interrupt) + * * 4'b0111: Channel halted (triggers an interrupt) + * * Others: Reserved + * @dpid: Data PID (DPID) + * * 2'b00: DATA0 + * * 2'b10: DATA1 + * * 2'b01: DATA2 + * * 2'b11: MDATA + * @bcnt: Byte Count (BCnt) + * Indicates the byte count of the received IN data packet + * @chnum: Channel Number (ChNum) + * Indicates the channel number to which the current received + * packet belongs. + */ + struct cvmx_usbcx_grxstsph_s { + __BITFIELD_FIELD(u32 reserved_21_31 : 11, + __BITFIELD_FIELD(u32 pktsts : 4, + __BITFIELD_FIELD(u32 dpid : 2, + __BITFIELD_FIELD(u32 bcnt : 11, + __BITFIELD_FIELD(u32 chnum : 4, + ;))))) + } s; +}; + +/** + * cvmx_usbc#_gusbcfg + * + * Core USB Configuration Register (GUSBCFG) + * + * This register can be used to configure the core after power-on or a changing + * to Host mode or Device mode. It contains USB and USB-PHY related + * configuration parameters. The application must program this register before + * starting any transactions on either the AHB or the USB. Do not make changes + * to this register after the initial programming. + */ +union cvmx_usbcx_gusbcfg { + u32 u32; + /** + * struct cvmx_usbcx_gusbcfg_s + * @otgi2csel: UTMIFS or I2C Interface Select (OtgI2CSel) + * This bit is always 0x0. + * @phylpwrclksel: PHY Low-Power Clock Select (PhyLPwrClkSel) + * Software should set this bit to 0x0. + * Selects either 480-MHz or 48-MHz (low-power) PHY mode. In + * FS and LS modes, the PHY can usually operate on a 48-MHz + * clock to save power. + * * 1'b0: 480-MHz Internal PLL clock + * * 1'b1: 48-MHz External Clock + * In 480 MHz mode, the UTMI interface operates at either 60 or + * 30-MHz, depending upon whether 8- or 16-bit data width is + * selected. In 48-MHz mode, the UTMI interface operates at 48 + * MHz in FS mode and at either 48 or 6 MHz in LS mode + * (depending on the PHY vendor). + * This bit drives the utmi_fsls_low_power core output signal, and + * is valid only for UTMI+ PHYs. + * @usbtrdtim: USB Turnaround Time (USBTrdTim) + * Sets the turnaround time in PHY clocks. + * Specifies the response time for a MAC request to the Packet + * FIFO Controller (PFC) to fetch data from the DFIFO (SPRAM). + * This must be programmed to 0x5. + * @hnpcap: HNP-Capable (HNPCap) + * This bit is always 0x0. + * @srpcap: SRP-Capable (SRPCap) + * This bit is always 0x0. + * @ddrsel: ULPI DDR Select (DDRSel) + * Software should set this bit to 0x0. + * @physel: USB 2.0 High-Speed PHY or USB 1.1 Full-Speed Serial + * Software should set this bit to 0x0. + * @fsintf: Full-Speed Serial Interface Select (FSIntf) + * Software should set this bit to 0x0. + * @ulpi_utmi_sel: ULPI or UTMI+ Select (ULPI_UTMI_Sel) + * This bit is always 0x0. + * @phyif: PHY Interface (PHYIf) + * This bit is always 0x1. + * @toutcal: HS/FS Timeout Calibration (TOutCal) + * The number of PHY clocks that the application programs in this + * field is added to the high-speed/full-speed interpacket timeout + * duration in the core to account for any additional delays + * introduced by the PHY. This may be required, since the delay + * introduced by the PHY in generating the linestate condition may + * vary from one PHY to another. + * The USB standard timeout value for high-speed operation is + * 736 to 816 (inclusive) bit times. The USB standard timeout + * value for full-speed operation is 16 to 18 (inclusive) bit + * times. The application must program this field based on the + * speed of enumeration. The number of bit times added per PHY + * clock are: + * High-speed operation: + * * One 30-MHz PHY clock = 16 bit times + * * One 60-MHz PHY clock = 8 bit times + * Full-speed operation: + * * One 30-MHz PHY clock = 0.4 bit times + * * One 60-MHz PHY clock = 0.2 bit times + * * One 48-MHz PHY clock = 0.25 bit times + */ + struct cvmx_usbcx_gusbcfg_s { + __BITFIELD_FIELD(u32 reserved_17_31 : 15, + __BITFIELD_FIELD(u32 otgi2csel : 1, + __BITFIELD_FIELD(u32 phylpwrclksel : 1, + __BITFIELD_FIELD(u32 reserved_14_14 : 1, + __BITFIELD_FIELD(u32 usbtrdtim : 4, + __BITFIELD_FIELD(u32 hnpcap : 1, + __BITFIELD_FIELD(u32 srpcap : 1, + __BITFIELD_FIELD(u32 ddrsel : 1, + __BITFIELD_FIELD(u32 physel : 1, + __BITFIELD_FIELD(u32 fsintf : 1, + __BITFIELD_FIELD(u32 ulpi_utmi_sel : 1, + __BITFIELD_FIELD(u32 phyif : 1, + __BITFIELD_FIELD(u32 toutcal : 3, + ;))))))))))))) + } s; +}; + +/** + * cvmx_usbc#_haint + * + * Host All Channels Interrupt Register (HAINT) + * + * When a significant event occurs on a channel, the Host All Channels Interrupt + * register interrupts the application using the Host Channels Interrupt bit of + * the Core Interrupt register (GINTSTS.HChInt). This is shown in Interrupt. + * There is one interrupt bit per channel, up to a maximum of 16 bits. Bits in + * this register are set and cleared when the application sets and clears bits + * in the corresponding Host Channel-n Interrupt register. + */ +union cvmx_usbcx_haint { + u32 u32; + /** + * struct cvmx_usbcx_haint_s + * @haint: Channel Interrupts (HAINT) + * One bit per channel: Bit 0 for Channel 0, bit 15 for Channel 15 + */ + struct cvmx_usbcx_haint_s { + __BITFIELD_FIELD(u32 reserved_16_31 : 16, + __BITFIELD_FIELD(u32 haint : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_haintmsk + * + * Host All Channels Interrupt Mask Register (HAINTMSK) + * + * The Host All Channel Interrupt Mask register works with the Host All Channel + * Interrupt register to interrupt the application when an event occurs on a + * channel. There is one interrupt mask bit per channel, up to a maximum of 16 + * bits. + * Mask interrupt: 1'b0 Unmask interrupt: 1'b1 + */ +union cvmx_usbcx_haintmsk { + u32 u32; + /** + * struct cvmx_usbcx_haintmsk_s + * @haintmsk: Channel Interrupt Mask (HAINTMsk) + * One bit per channel: Bit 0 for channel 0, bit 15 for channel 15 + */ + struct cvmx_usbcx_haintmsk_s { + __BITFIELD_FIELD(u32 reserved_16_31 : 16, + __BITFIELD_FIELD(u32 haintmsk : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_hcchar# + * + * Host Channel-n Characteristics Register (HCCHAR) + * + */ +union cvmx_usbcx_hccharx { + u32 u32; + /** + * struct cvmx_usbcx_hccharx_s + * @chena: Channel Enable (ChEna) + * This field is set by the application and cleared by the OTG + * host. + * * 1'b0: Channel disabled + * * 1'b1: Channel enabled + * @chdis: Channel Disable (ChDis) + * The application sets this bit to stop transmitting/receiving + * data on a channel, even before the transfer for that channel is + * complete. The application must wait for the Channel Disabled + * interrupt before treating the channel as disabled. + * @oddfrm: Odd Frame (OddFrm) + * This field is set (reset) by the application to indicate that + * the OTG host must perform a transfer in an odd (micro)frame. + * This field is applicable for only periodic (isochronous and + * interrupt) transactions. + * * 1'b0: Even (micro)frame + * * 1'b1: Odd (micro)frame + * @devaddr: Device Address (DevAddr) + * This field selects the specific device serving as the data + * source or sink. + * @ec: Multi Count (MC) / Error Count (EC) + * When the Split Enable bit of the Host Channel-n Split Control + * register (HCSPLTn.SpltEna) is reset (1'b0), this field indicates + * to the host the number of transactions that should be executed + * per microframe for this endpoint. + * * 2'b00: Reserved. This field yields undefined results. + * * 2'b01: 1 transaction + * * 2'b10: 2 transactions to be issued for this endpoint per + * microframe + * * 2'b11: 3 transactions to be issued for this endpoint per + * microframe + * When HCSPLTn.SpltEna is set (1'b1), this field indicates the + * number of immediate retries to be performed for a periodic split + * transactions on transaction errors. This field must be set to at + * least 2'b01. + * @eptype: Endpoint Type (EPType) + * Indicates the transfer type selected. + * * 2'b00: Control + * * 2'b01: Isochronous + * * 2'b10: Bulk + * * 2'b11: Interrupt + * @lspddev: Low-Speed Device (LSpdDev) + * This field is set by the application to indicate that this + * channel is communicating to a low-speed device. + * @epdir: Endpoint Direction (EPDir) + * Indicates whether the transaction is IN or OUT. + * * 1'b0: OUT + * * 1'b1: IN + * @epnum: Endpoint Number (EPNum) + * Indicates the endpoint number on the device serving as the + * data source or sink. + * @mps: Maximum Packet Size (MPS) + * Indicates the maximum packet size of the associated endpoint. + */ + struct cvmx_usbcx_hccharx_s { + __BITFIELD_FIELD(u32 chena : 1, + __BITFIELD_FIELD(u32 chdis : 1, + __BITFIELD_FIELD(u32 oddfrm : 1, + __BITFIELD_FIELD(u32 devaddr : 7, + __BITFIELD_FIELD(u32 ec : 2, + __BITFIELD_FIELD(u32 eptype : 2, + __BITFIELD_FIELD(u32 lspddev : 1, + __BITFIELD_FIELD(u32 reserved_16_16 : 1, + __BITFIELD_FIELD(u32 epdir : 1, + __BITFIELD_FIELD(u32 epnum : 4, + __BITFIELD_FIELD(u32 mps : 11, + ;))))))))))) + } s; +}; + +/** + * cvmx_usbc#_hcfg + * + * Host Configuration Register (HCFG) + * + * This register configures the core after power-on. Do not make changes to this + * register after initializing the host. + */ +union cvmx_usbcx_hcfg { + u32 u32; + /** + * struct cvmx_usbcx_hcfg_s + * @fslssupp: FS- and LS-Only Support (FSLSSupp) + * The application uses this bit to control the core's enumeration + * speed. Using this bit, the application can make the core + * enumerate as a FS host, even if the connected device supports + * HS traffic. Do not make changes to this field after initial + * programming. + * * 1'b0: HS/FS/LS, based on the maximum speed supported by + * the connected device + * * 1'b1: FS/LS-only, even if the connected device can support HS + * @fslspclksel: FS/LS PHY Clock Select (FSLSPclkSel) + * When the core is in FS Host mode + * * 2'b00: PHY clock is running at 30/60 MHz + * * 2'b01: PHY clock is running at 48 MHz + * * Others: Reserved + * When the core is in LS Host mode + * * 2'b00: PHY clock is running at 30/60 MHz. When the + * UTMI+/ULPI PHY Low Power mode is not selected, use + * 30/60 MHz. + * * 2'b01: PHY clock is running at 48 MHz. When the UTMI+ + * PHY Low Power mode is selected, use 48MHz if the PHY + * supplies a 48 MHz clock during LS mode. + * * 2'b10: PHY clock is running at 6 MHz. In USB 1.1 FS mode, + * use 6 MHz when the UTMI+ PHY Low Power mode is + * selected and the PHY supplies a 6 MHz clock during LS + * mode. If you select a 6 MHz clock during LS mode, you must + * do a soft reset. + * * 2'b11: Reserved + */ + struct cvmx_usbcx_hcfg_s { + __BITFIELD_FIELD(u32 reserved_3_31 : 29, + __BITFIELD_FIELD(u32 fslssupp : 1, + __BITFIELD_FIELD(u32 fslspclksel : 2, + ;))) + } s; +}; + +/** + * cvmx_usbc#_hcint# + * + * Host Channel-n Interrupt Register (HCINT) + * + * This register indicates the status of a channel with respect to USB- and + * AHB-related events. The application must read this register when the Host + * Channels Interrupt bit of the Core Interrupt register (GINTSTS.HChInt) is + * set. Before the application can read this register, it must first read + * the Host All Channels Interrupt (HAINT) register to get the exact channel + * number for the Host Channel-n Interrupt register. The application must clear + * the appropriate bit in this register to clear the corresponding bits in the + * HAINT and GINTSTS registers. + */ +union cvmx_usbcx_hcintx { + u32 u32; + /** + * struct cvmx_usbcx_hcintx_s + * @datatglerr: Data Toggle Error (DataTglErr) + * @frmovrun: Frame Overrun (FrmOvrun) + * @bblerr: Babble Error (BblErr) + * @xacterr: Transaction Error (XactErr) + * @nyet: NYET Response Received Interrupt (NYET) + * @ack: ACK Response Received Interrupt (ACK) + * @nak: NAK Response Received Interrupt (NAK) + * @stall: STALL Response Received Interrupt (STALL) + * @ahberr: This bit is always 0x0. + * @chhltd: Channel Halted (ChHltd) + * Indicates the transfer completed abnormally either because of + * any USB transaction error or in response to disable request by + * the application. + * @xfercompl: Transfer Completed (XferCompl) + * Transfer completed normally without any errors. + */ + struct cvmx_usbcx_hcintx_s { + __BITFIELD_FIELD(u32 reserved_11_31 : 21, + __BITFIELD_FIELD(u32 datatglerr : 1, + __BITFIELD_FIELD(u32 frmovrun : 1, + __BITFIELD_FIELD(u32 bblerr : 1, + __BITFIELD_FIELD(u32 xacterr : 1, + __BITFIELD_FIELD(u32 nyet : 1, + __BITFIELD_FIELD(u32 ack : 1, + __BITFIELD_FIELD(u32 nak : 1, + __BITFIELD_FIELD(u32 stall : 1, + __BITFIELD_FIELD(u32 ahberr : 1, + __BITFIELD_FIELD(u32 chhltd : 1, + __BITFIELD_FIELD(u32 xfercompl : 1, + ;)))))))))))) + } s; +}; + +/** + * cvmx_usbc#_hcintmsk# + * + * Host Channel-n Interrupt Mask Register (HCINTMSKn) + * + * This register reflects the mask for each channel status described in the + * previous section. + * Mask interrupt: 1'b0 Unmask interrupt: 1'b1 + */ +union cvmx_usbcx_hcintmskx { + u32 u32; + /** + * struct cvmx_usbcx_hcintmskx_s + * @datatglerrmsk: Data Toggle Error Mask (DataTglErrMsk) + * @frmovrunmsk: Frame Overrun Mask (FrmOvrunMsk) + * @bblerrmsk: Babble Error Mask (BblErrMsk) + * @xacterrmsk: Transaction Error Mask (XactErrMsk) + * @nyetmsk: NYET Response Received Interrupt Mask (NyetMsk) + * @ackmsk: ACK Response Received Interrupt Mask (AckMsk) + * @nakmsk: NAK Response Received Interrupt Mask (NakMsk) + * @stallmsk: STALL Response Received Interrupt Mask (StallMsk) + * @ahberrmsk: AHB Error Mask (AHBErrMsk) + * @chhltdmsk: Channel Halted Mask (ChHltdMsk) + * @xfercomplmsk: Transfer Completed Mask (XferComplMsk) + */ + struct cvmx_usbcx_hcintmskx_s { + __BITFIELD_FIELD(u32 reserved_11_31 : 21, + __BITFIELD_FIELD(u32 datatglerrmsk : 1, + __BITFIELD_FIELD(u32 frmovrunmsk : 1, + __BITFIELD_FIELD(u32 bblerrmsk : 1, + __BITFIELD_FIELD(u32 xacterrmsk : 1, + __BITFIELD_FIELD(u32 nyetmsk : 1, + __BITFIELD_FIELD(u32 ackmsk : 1, + __BITFIELD_FIELD(u32 nakmsk : 1, + __BITFIELD_FIELD(u32 stallmsk : 1, + __BITFIELD_FIELD(u32 ahberrmsk : 1, + __BITFIELD_FIELD(u32 chhltdmsk : 1, + __BITFIELD_FIELD(u32 xfercomplmsk : 1, + ;)))))))))))) + } s; +}; + +/** + * cvmx_usbc#_hcsplt# + * + * Host Channel-n Split Control Register (HCSPLT) + * + */ +union cvmx_usbcx_hcspltx { + u32 u32; + /** + * struct cvmx_usbcx_hcspltx_s + * @spltena: Split Enable (SpltEna) + * The application sets this field to indicate that this channel is + * enabled to perform split transactions. + * @compsplt: Do Complete Split (CompSplt) + * The application sets this field to request the OTG host to + * perform a complete split transaction. + * @xactpos: Transaction Position (XactPos) + * This field is used to determine whether to send all, first, + * middle, or last payloads with each OUT transaction. + * * 2'b11: All. This is the entire data payload is of this + * transaction (which is less than or equal to 188 bytes). + * * 2'b10: Begin. This is the first data payload of this + * transaction (which is larger than 188 bytes). + * * 2'b00: Mid. This is the middle payload of this transaction + * (which is larger than 188 bytes). + * * 2'b01: End. This is the last payload of this transaction + * (which is larger than 188 bytes). + * @hubaddr: Hub Address (HubAddr) + * This field holds the device address of the transaction + * translator's hub. + * @prtaddr: Port Address (PrtAddr) + * This field is the port number of the recipient transaction + * translator. + */ + struct cvmx_usbcx_hcspltx_s { + __BITFIELD_FIELD(u32 spltena : 1, + __BITFIELD_FIELD(u32 reserved_17_30 : 14, + __BITFIELD_FIELD(u32 compsplt : 1, + __BITFIELD_FIELD(u32 xactpos : 2, + __BITFIELD_FIELD(u32 hubaddr : 7, + __BITFIELD_FIELD(u32 prtaddr : 7, + ;)))))) + } s; +}; + +/** + * cvmx_usbc#_hctsiz# + * + * Host Channel-n Transfer Size Register (HCTSIZ) + * + */ +union cvmx_usbcx_hctsizx { + u32 u32; + /** + * struct cvmx_usbcx_hctsizx_s + * @dopng: Do Ping (DoPng) + * Setting this field to 1 directs the host to do PING protocol. + * @pid: PID (Pid) + * The application programs this field with the type of PID to use + * for the initial transaction. The host will maintain this field + * for the rest of the transfer. + * * 2'b00: DATA0 + * * 2'b01: DATA2 + * * 2'b10: DATA1 + * * 2'b11: MDATA (non-control)/SETUP (control) + * @pktcnt: Packet Count (PktCnt) + * This field is programmed by the application with the expected + * number of packets to be transmitted (OUT) or received (IN). + * The host decrements this count on every successful + * transmission or reception of an OUT/IN packet. Once this count + * reaches zero, the application is interrupted to indicate normal + * completion. + * @xfersize: Transfer Size (XferSize) + * For an OUT, this field is the number of data bytes the host will + * send during the transfer. + * For an IN, this field is the buffer size that the application + * has reserved for the transfer. The application is expected to + * program this field as an integer multiple of the maximum packet + * size for IN transactions (periodic and non-periodic). + */ + struct cvmx_usbcx_hctsizx_s { + __BITFIELD_FIELD(u32 dopng : 1, + __BITFIELD_FIELD(u32 pid : 2, + __BITFIELD_FIELD(u32 pktcnt : 10, + __BITFIELD_FIELD(u32 xfersize : 19, + ;)))) + } s; +}; + +/** + * cvmx_usbc#_hfir + * + * Host Frame Interval Register (HFIR) + * + * This register stores the frame interval information for the current speed to + * which the O2P USB core has enumerated. + */ +union cvmx_usbcx_hfir { + u32 u32; + /** + * struct cvmx_usbcx_hfir_s + * @frint: Frame Interval (FrInt) + * The value that the application programs to this field specifies + * the interval between two consecutive SOFs (FS) or micro- + * SOFs (HS) or Keep-Alive tokens (HS). This field contains the + * number of PHY clocks that constitute the required frame + * interval. The default value set in this field for a FS operation + * when the PHY clock frequency is 60 MHz. The application can + * write a value to this register only after the Port Enable bit of + * the Host Port Control and Status register (HPRT.PrtEnaPort) + * has been set. If no value is programmed, the core calculates + * the value based on the PHY clock specified in the FS/LS PHY + * Clock Select field of the Host Configuration register + * (HCFG.FSLSPclkSel). Do not change the value of this field + * after the initial configuration. + * * 125 us (PHY clock frequency for HS) + * * 1 ms (PHY clock frequency for FS/LS) + */ + struct cvmx_usbcx_hfir_s { + __BITFIELD_FIELD(u32 reserved_16_31 : 16, + __BITFIELD_FIELD(u32 frint : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_hfnum + * + * Host Frame Number/Frame Time Remaining Register (HFNUM) + * + * This register indicates the current frame number. + * It also indicates the time remaining (in terms of the number of PHY clocks) + * in the current (micro)frame. + */ +union cvmx_usbcx_hfnum { + u32 u32; + /** + * struct cvmx_usbcx_hfnum_s + * @frrem: Frame Time Remaining (FrRem) + * Indicates the amount of time remaining in the current + * microframe (HS) or frame (FS/LS), in terms of PHY clocks. + * This field decrements on each PHY clock. When it reaches + * zero, this field is reloaded with the value in the Frame + * Interval register and a new SOF is transmitted on the USB. + * @frnum: Frame Number (FrNum) + * This field increments when a new SOF is transmitted on the + * USB, and is reset to 0 when it reaches 16'h3FFF. + */ + struct cvmx_usbcx_hfnum_s { + __BITFIELD_FIELD(u32 frrem : 16, + __BITFIELD_FIELD(u32 frnum : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_hprt + * + * Host Port Control and Status Register (HPRT) + * + * This register is available in both Host and Device modes. + * Currently, the OTG Host supports only one port. + * A single register holds USB port-related information such as USB reset, + * enable, suspend, resume, connect status, and test mode for each port. The + * R_SS_WC bits in this register can trigger an interrupt to the application + * through the Host Port Interrupt bit of the Core Interrupt register + * (GINTSTS.PrtInt). On a Port Interrupt, the application must read this + * register and clear the bit that caused the interrupt. For the R_SS_WC bits, + * the application must write a 1 to the bit to clear the interrupt. + */ +union cvmx_usbcx_hprt { + u32 u32; + /** + * struct cvmx_usbcx_hprt_s + * @prtspd: Port Speed (PrtSpd) + * Indicates the speed of the device attached to this port. + * * 2'b00: High speed + * * 2'b01: Full speed + * * 2'b10: Low speed + * * 2'b11: Reserved + * @prttstctl: Port Test Control (PrtTstCtl) + * The application writes a nonzero value to this field to put + * the port into a Test mode, and the corresponding pattern is + * signaled on the port. + * * 4'b0000: Test mode disabled + * * 4'b0001: Test_J mode + * * 4'b0010: Test_K mode + * * 4'b0011: Test_SE0_NAK mode + * * 4'b0100: Test_Packet mode + * * 4'b0101: Test_Force_Enable + * * Others: Reserved + * PrtSpd must be zero (i.e. the interface must be in high-speed + * mode) to use the PrtTstCtl test modes. + * @prtpwr: Port Power (PrtPwr) + * The application uses this field to control power to this port, + * and the core clears this bit on an overcurrent condition. + * * 1'b0: Power off + * * 1'b1: Power on + * @prtlnsts: Port Line Status (PrtLnSts) + * Indicates the current logic level USB data lines + * * Bit [10]: Logic level of D- + * * Bit [11]: Logic level of D+ + * @prtrst: Port Reset (PrtRst) + * When the application sets this bit, a reset sequence is + * started on this port. The application must time the reset + * period and clear this bit after the reset sequence is + * complete. + * * 1'b0: Port not in reset + * * 1'b1: Port in reset + * The application must leave this bit set for at least a + * minimum duration mentioned below to start a reset on the + * port. The application can leave it set for another 10 ms in + * addition to the required minimum duration, before clearing + * the bit, even though there is no maximum limit set by the + * USB standard. + * * High speed: 50 ms + * * Full speed/Low speed: 10 ms + * @prtsusp: Port Suspend (PrtSusp) + * The application sets this bit to put this port in Suspend + * mode. The core only stops sending SOFs when this is set. + * To stop the PHY clock, the application must set the Port + * Clock Stop bit, which will assert the suspend input pin of + * the PHY. + * The read value of this bit reflects the current suspend + * status of the port. This bit is cleared by the core after a + * remote wakeup signal is detected or the application sets + * the Port Reset bit or Port Resume bit in this register or the + * Resume/Remote Wakeup Detected Interrupt bit or + * Disconnect Detected Interrupt bit in the Core Interrupt + * register (GINTSTS.WkUpInt or GINTSTS.DisconnInt, + * respectively). + * * 1'b0: Port not in Suspend mode + * * 1'b1: Port in Suspend mode + * @prtres: Port Resume (PrtRes) + * The application sets this bit to drive resume signaling on + * the port. The core continues to drive the resume signal + * until the application clears this bit. + * If the core detects a USB remote wakeup sequence, as + * indicated by the Port Resume/Remote Wakeup Detected + * Interrupt bit of the Core Interrupt register + * (GINTSTS.WkUpInt), the core starts driving resume + * signaling without application intervention and clears this bit + * when it detects a disconnect condition. The read value of + * this bit indicates whether the core is currently driving + * resume signaling. + * * 1'b0: No resume driven + * * 1'b1: Resume driven + * @prtovrcurrchng: Port Overcurrent Change (PrtOvrCurrChng) + * The core sets this bit when the status of the Port + * Overcurrent Active bit (bit 4) in this register changes. + * @prtovrcurract: Port Overcurrent Active (PrtOvrCurrAct) + * Indicates the overcurrent condition of the port. + * * 1'b0: No overcurrent condition + * * 1'b1: Overcurrent condition + * @prtenchng: Port Enable/Disable Change (PrtEnChng) + * The core sets this bit when the status of the Port Enable bit + * [2] of this register changes. + * @prtena: Port Enable (PrtEna) + * A port is enabled only by the core after a reset sequence, + * and is disabled by an overcurrent condition, a disconnect + * condition, or by the application clearing this bit. The + * application cannot set this bit by a register write. It can only + * clear it to disable the port. This bit does not trigger any + * interrupt to the application. + * * 1'b0: Port disabled + * * 1'b1: Port enabled + * @prtconndet: Port Connect Detected (PrtConnDet) + * The core sets this bit when a device connection is detected + * to trigger an interrupt to the application using the Host Port + * Interrupt bit of the Core Interrupt register (GINTSTS.PrtInt). + * The application must write a 1 to this bit to clear the + * interrupt. + * @prtconnsts: Port Connect Status (PrtConnSts) + * * 0: No device is attached to the port. + * * 1: A device is attached to the port. + */ + struct cvmx_usbcx_hprt_s { + __BITFIELD_FIELD(u32 reserved_19_31 : 13, + __BITFIELD_FIELD(u32 prtspd : 2, + __BITFIELD_FIELD(u32 prttstctl : 4, + __BITFIELD_FIELD(u32 prtpwr : 1, + __BITFIELD_FIELD(u32 prtlnsts : 2, + __BITFIELD_FIELD(u32 reserved_9_9 : 1, + __BITFIELD_FIELD(u32 prtrst : 1, + __BITFIELD_FIELD(u32 prtsusp : 1, + __BITFIELD_FIELD(u32 prtres : 1, + __BITFIELD_FIELD(u32 prtovrcurrchng : 1, + __BITFIELD_FIELD(u32 prtovrcurract : 1, + __BITFIELD_FIELD(u32 prtenchng : 1, + __BITFIELD_FIELD(u32 prtena : 1, + __BITFIELD_FIELD(u32 prtconndet : 1, + __BITFIELD_FIELD(u32 prtconnsts : 1, + ;))))))))))))))) + } s; +}; + +/** + * cvmx_usbc#_hptxfsiz + * + * Host Periodic Transmit FIFO Size Register (HPTXFSIZ) + * + * This register holds the size and the memory start address of the Periodic + * TxFIFO, as shown in Figures 310 and 311. + */ +union cvmx_usbcx_hptxfsiz { + u32 u32; + /** + * struct cvmx_usbcx_hptxfsiz_s + * @ptxfsize: Host Periodic TxFIFO Depth (PTxFSize) + * This value is in terms of 32-bit words. + * * Minimum value is 16 + * * Maximum value is 32768 + * @ptxfstaddr: Host Periodic TxFIFO Start Address (PTxFStAddr) + */ + struct cvmx_usbcx_hptxfsiz_s { + __BITFIELD_FIELD(u32 ptxfsize : 16, + __BITFIELD_FIELD(u32 ptxfstaddr : 16, + ;)) + } s; +}; + +/** + * cvmx_usbc#_hptxsts + * + * Host Periodic Transmit FIFO/Queue Status Register (HPTXSTS) + * + * This read-only register contains the free space information for the Periodic + * TxFIFO and the Periodic Transmit Request Queue + */ +union cvmx_usbcx_hptxsts { + u32 u32; + /** + * struct cvmx_usbcx_hptxsts_s + * @ptxqtop: Top of the Periodic Transmit Request Queue (PTxQTop) + * This indicates the entry in the Periodic Tx Request Queue that + * is currently being processes by the MAC. + * This register is used for debugging. + * * Bit [31]: Odd/Even (micro)frame + * - 1'b0: send in even (micro)frame + * - 1'b1: send in odd (micro)frame + * * Bits [30:27]: Channel/endpoint number + * * Bits [26:25]: Type + * - 2'b00: IN/OUT + * - 2'b01: Zero-length packet + * - 2'b10: CSPLIT + * - 2'b11: Disable channel command + * * Bit [24]: Terminate (last entry for the selected + * channel/endpoint) + * @ptxqspcavail: Periodic Transmit Request Queue Space Available + * (PTxQSpcAvail) + * Indicates the number of free locations available to be written + * in the Periodic Transmit Request Queue. This queue holds both + * IN and OUT requests. + * * 8'h0: Periodic Transmit Request Queue is full + * * 8'h1: 1 location available + * * 8'h2: 2 locations available + * * n: n locations available (0..8) + * * Others: Reserved + * @ptxfspcavail: Periodic Transmit Data FIFO Space Available + * (PTxFSpcAvail) + * Indicates the number of free locations available to be written + * to in the Periodic TxFIFO. + * Values are in terms of 32-bit words + * * 16'h0: Periodic TxFIFO is full + * * 16'h1: 1 word available + * * 16'h2: 2 words available + * * 16'hn: n words available (where 0..32768) + * * 16'h8000: 32768 words available + * * Others: Reserved + */ + struct cvmx_usbcx_hptxsts_s { + __BITFIELD_FIELD(u32 ptxqtop : 8, + __BITFIELD_FIELD(u32 ptxqspcavail : 8, + __BITFIELD_FIELD(u32 ptxfspcavail : 16, + ;))) + } s; +}; + +/** + * cvmx_usbn#_clk_ctl + * + * USBN_CLK_CTL = USBN's Clock Control + * + * This register is used to control the frequency of the hclk and the + * hreset and phy_rst signals. + */ +union cvmx_usbnx_clk_ctl { + u64 u64; + /** + * struct cvmx_usbnx_clk_ctl_s + * @divide2: The 'hclk' used by the USB subsystem is derived + * from the eclk. + * Also see the field DIVIDE. DIVIDE2<1> must currently + * be zero because it is not implemented, so the maximum + * ratio of eclk/hclk is currently 16. + * The actual divide number for hclk is: + * (DIVIDE2 + 1) * (DIVIDE + 1) + * @hclk_rst: When this field is '0' the HCLK-DIVIDER used to + * generate the hclk in the USB Subsystem is held + * in reset. This bit must be set to '0' before + * changing the value os DIVIDE in this register. + * The reset to the HCLK_DIVIDERis also asserted + * when core reset is asserted. + * @p_x_on: Force USB-PHY on during suspend. + * '1' USB-PHY XO block is powered-down during + * suspend. + * '0' USB-PHY XO block is powered-up during + * suspend. + * The value of this field must be set while POR is + * active. + * @p_rtype: PHY reference clock type + * On CN50XX/CN52XX/CN56XX the values are: + * '0' The USB-PHY uses a 12MHz crystal as a clock source + * at the USB_XO and USB_XI pins. + * '1' Reserved. + * '2' The USB_PHY uses 12/24/48MHz 2.5V board clock at the + * USB_XO pin. USB_XI should be tied to ground in this + * case. + * '3' Reserved. + * On CN3xxx bits 14 and 15 are p_xenbn and p_rclk and values are: + * '0' Reserved. + * '1' Reserved. + * '2' The PHY PLL uses the XO block output as a reference. + * The XO block uses an external clock supplied on the + * XO pin. USB_XI should be tied to ground for this + * usage. + * '3' The XO block uses the clock from a crystal. + * @p_com_on: '0' Force USB-PHY XO Bias, Bandgap and PLL to + * remain powered in Suspend Mode. + * '1' The USB-PHY XO Bias, Bandgap and PLL are + * powered down in suspend mode. + * The value of this field must be set while POR is + * active. + * @p_c_sel: Phy clock speed select. + * Selects the reference clock / crystal frequency. + * '11': Reserved + * '10': 48 MHz (reserved when a crystal is used) + * '01': 24 MHz (reserved when a crystal is used) + * '00': 12 MHz + * The value of this field must be set while POR is + * active. + * NOTE: if a crystal is used as a reference clock, + * this field must be set to 12 MHz. + * @cdiv_byp: Used to enable the bypass input to the USB_CLK_DIV. + * @sd_mode: Scaledown mode for the USBC. Control timing events + * in the USBC, for normal operation this must be '0'. + * @s_bist: Starts bist on the hclk memories, during the '0' + * to '1' transition. + * @por: Power On Reset for the PHY. + * Resets all the PHYS registers and state machines. + * @enable: When '1' allows the generation of the hclk. When + * '0' the hclk will not be generated. SEE DIVIDE + * field of this register. + * @prst: When this field is '0' the reset associated with + * the phy_clk functionality in the USB Subsystem is + * help in reset. This bit should not be set to '1' + * until the time it takes 6 clocks (hclk or phy_clk, + * whichever is slower) has passed. Under normal + * operation once this bit is set to '1' it should not + * be set to '0'. + * @hrst: When this field is '0' the reset associated with + * the hclk functioanlity in the USB Subsystem is + * held in reset.This bit should not be set to '1' + * until 12ms after phy_clk is stable. Under normal + * operation, once this bit is set to '1' it should + * not be set to '0'. + * @divide: The frequency of 'hclk' used by the USB subsystem + * is the eclk frequency divided by the value of + * (DIVIDE2 + 1) * (DIVIDE + 1), also see the field + * DIVIDE2 of this register. + * The hclk frequency should be less than 125Mhz. + * After writing a value to this field the SW should + * read the field for the value written. + * The ENABLE field of this register should not be set + * until AFTER this field is set and then read. + */ + struct cvmx_usbnx_clk_ctl_s { + __BITFIELD_FIELD(u64 reserved_20_63 : 44, + __BITFIELD_FIELD(u64 divide2 : 2, + __BITFIELD_FIELD(u64 hclk_rst : 1, + __BITFIELD_FIELD(u64 p_x_on : 1, + __BITFIELD_FIELD(u64 p_rtype : 2, + __BITFIELD_FIELD(u64 p_com_on : 1, + __BITFIELD_FIELD(u64 p_c_sel : 2, + __BITFIELD_FIELD(u64 cdiv_byp : 1, + __BITFIELD_FIELD(u64 sd_mode : 2, + __BITFIELD_FIELD(u64 s_bist : 1, + __BITFIELD_FIELD(u64 por : 1, + __BITFIELD_FIELD(u64 enable : 1, + __BITFIELD_FIELD(u64 prst : 1, + __BITFIELD_FIELD(u64 hrst : 1, + __BITFIELD_FIELD(u64 divide : 3, + ;))))))))))))))) + } s; +}; + +/** + * cvmx_usbn#_usbp_ctl_status + * + * USBN_USBP_CTL_STATUS = USBP Control And Status Register + * + * Contains general control and status information for the USBN block. + */ +union cvmx_usbnx_usbp_ctl_status { + u64 u64; + /** + * struct cvmx_usbnx_usbp_ctl_status_s + * @txrisetune: HS Transmitter Rise/Fall Time Adjustment + * @txvreftune: HS DC Voltage Level Adjustment + * @txfslstune: FS/LS Source Impedance Adjustment + * @txhsxvtune: Transmitter High-Speed Crossover Adjustment + * @sqrxtune: Squelch Threshold Adjustment + * @compdistune: Disconnect Threshold Adjustment + * @otgtune: VBUS Valid Threshold Adjustment + * @otgdisable: OTG Block Disable + * @portreset: Per_Port Reset + * @drvvbus: Drive VBUS + * @lsbist: Low-Speed BIST Enable. + * @fsbist: Full-Speed BIST Enable. + * @hsbist: High-Speed BIST Enable. + * @bist_done: PHY Bist Done. + * Asserted at the end of the PHY BIST sequence. + * @bist_err: PHY Bist Error. + * Indicates an internal error was detected during + * the BIST sequence. + * @tdata_out: PHY Test Data Out. + * Presents either internally generated signals or + * test register contents, based upon the value of + * test_data_out_sel. + * @siddq: Drives the USBP (USB-PHY) SIDDQ input. + * Normally should be set to zero. + * When customers have no intent to use USB PHY + * interface, they should: + * - still provide 3.3V to USB_VDD33, and + * - tie USB_REXT to 3.3V supply, and + * - set USBN*_USBP_CTL_STATUS[SIDDQ]=1 + * @txpreemphasistune: HS Transmitter Pre-Emphasis Enable + * @dma_bmode: When set to 1 the L2C DMA address will be updated + * with byte-counts between packets. When set to 0 + * the L2C DMA address is incremented to the next + * 4-byte aligned address after adding byte-count. + * @usbc_end: Bigendian input to the USB Core. This should be + * set to '0' for operation. + * @usbp_bist: PHY, This is cleared '0' to run BIST on the USBP. + * @tclk: PHY Test Clock, used to load TDATA_IN to the USBP. + * @dp_pulld: PHY DP_PULLDOWN input to the USB-PHY. + * This signal enables the pull-down resistance on + * the D+ line. '1' pull down-resistance is connected + * to D+/ '0' pull down resistance is not connected + * to D+. When an A/B device is acting as a host + * (downstream-facing port), dp_pulldown and + * dm_pulldown are enabled. This must not toggle + * during normal operation. + * @dm_pulld: PHY DM_PULLDOWN input to the USB-PHY. + * This signal enables the pull-down resistance on + * the D- line. '1' pull down-resistance is connected + * to D-. '0' pull down resistance is not connected + * to D-. When an A/B device is acting as a host + * (downstream-facing port), dp_pulldown and + * dm_pulldown are enabled. This must not toggle + * during normal operation. + * @hst_mode: When '0' the USB is acting as HOST, when '1' + * USB is acting as device. This field needs to be + * set while the USB is in reset. + * @tuning: Transmitter Tuning for High-Speed Operation. + * Tunes the current supply and rise/fall output + * times for high-speed operation. + * [20:19] == 11: Current supply increased + * approximately 9% + * [20:19] == 10: Current supply increased + * approximately 4.5% + * [20:19] == 01: Design default. + * [20:19] == 00: Current supply decreased + * approximately 4.5% + * [22:21] == 11: Rise and fall times are increased. + * [22:21] == 10: Design default. + * [22:21] == 01: Rise and fall times are decreased. + * [22:21] == 00: Rise and fall times are decreased + * further as compared to the 01 setting. + * @tx_bs_enh: Transmit Bit Stuffing on [15:8]. + * Enables or disables bit stuffing on data[15:8] + * when bit-stuffing is enabled. + * @tx_bs_en: Transmit Bit Stuffing on [7:0]. + * Enables or disables bit stuffing on data[7:0] + * when bit-stuffing is enabled. + * @loop_enb: PHY Loopback Test Enable. + * '1': During data transmission the receive is + * enabled. + * '0': During data transmission the receive is + * disabled. + * Must be '0' for normal operation. + * @vtest_enb: Analog Test Pin Enable. + * '1' The PHY's analog_test pin is enabled for the + * input and output of applicable analog test signals. + * '0' THe analog_test pin is disabled. + * @bist_enb: Built-In Self Test Enable. + * Used to activate BIST in the PHY. + * @tdata_sel: Test Data Out Select. + * '1' test_data_out[3:0] (PHY) register contents + * are output. '0' internally generated signals are + * output. + * @taddr_in: Mode Address for Test Interface. + * Specifies the register address for writing to or + * reading from the PHY test interface register. + * @tdata_in: Internal Testing Register Input Data and Select + * This is a test bus. Data is present on [3:0], + * and its corresponding select (enable) is present + * on bits [7:4]. + * @ate_reset: Reset input from automatic test equipment. + * This is a test signal. When the USB Core is + * powered up (not in Susned Mode), an automatic + * tester can use this to disable phy_clock and + * free_clk, then re-enable them with an aligned + * phase. + * '1': The phy_clk and free_clk outputs are + * disabled. "0": The phy_clock and free_clk outputs + * are available within a specific period after the + * de-assertion. + */ + struct cvmx_usbnx_usbp_ctl_status_s { + __BITFIELD_FIELD(u64 txrisetune : 1, + __BITFIELD_FIELD(u64 txvreftune : 4, + __BITFIELD_FIELD(u64 txfslstune : 4, + __BITFIELD_FIELD(u64 txhsxvtune : 2, + __BITFIELD_FIELD(u64 sqrxtune : 3, + __BITFIELD_FIELD(u64 compdistune : 3, + __BITFIELD_FIELD(u64 otgtune : 3, + __BITFIELD_FIELD(u64 otgdisable : 1, + __BITFIELD_FIELD(u64 portreset : 1, + __BITFIELD_FIELD(u64 drvvbus : 1, + __BITFIELD_FIELD(u64 lsbist : 1, + __BITFIELD_FIELD(u64 fsbist : 1, + __BITFIELD_FIELD(u64 hsbist : 1, + __BITFIELD_FIELD(u64 bist_done : 1, + __BITFIELD_FIELD(u64 bist_err : 1, + __BITFIELD_FIELD(u64 tdata_out : 4, + __BITFIELD_FIELD(u64 siddq : 1, + __BITFIELD_FIELD(u64 txpreemphasistune : 1, + __BITFIELD_FIELD(u64 dma_bmode : 1, + __BITFIELD_FIELD(u64 usbc_end : 1, + __BITFIELD_FIELD(u64 usbp_bist : 1, + __BITFIELD_FIELD(u64 tclk : 1, + __BITFIELD_FIELD(u64 dp_pulld : 1, + __BITFIELD_FIELD(u64 dm_pulld : 1, + __BITFIELD_FIELD(u64 hst_mode : 1, + __BITFIELD_FIELD(u64 tuning : 4, + __BITFIELD_FIELD(u64 tx_bs_enh : 1, + __BITFIELD_FIELD(u64 tx_bs_en : 1, + __BITFIELD_FIELD(u64 loop_enb : 1, + __BITFIELD_FIELD(u64 vtest_enb : 1, + __BITFIELD_FIELD(u64 bist_enb : 1, + __BITFIELD_FIELD(u64 tdata_sel : 1, + __BITFIELD_FIELD(u64 taddr_in : 4, + __BITFIELD_FIELD(u64 tdata_in : 8, + __BITFIELD_FIELD(u64 ate_reset : 1, + ;))))))))))))))))))))))))))))))))))) + } s; +}; + +#endif /* __OCTEON_HCD_H__ */ diff --git a/drivers/staging/octeon/Kconfig b/drivers/staging/octeon/Kconfig new file mode 100644 index 000000000000..5319909eb2f6 --- /dev/null +++ b/drivers/staging/octeon/Kconfig @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 +config OCTEON_ETHERNET + tristate "Cavium Networks Octeon Ethernet support" + depends on CAVIUM_OCTEON_SOC || COMPILE_TEST + depends on NETDEVICES + select PHYLIB + select MDIO_OCTEON + help + This driver supports the builtin ethernet ports on Cavium + Networks' products in the Octeon family. This driver supports the + CN3XXX and CN5XXX Octeon processors. + + To compile this driver as a module, choose M here. The module + will be called octeon-ethernet. + diff --git a/drivers/staging/octeon/Makefile b/drivers/staging/octeon/Makefile new file mode 100644 index 000000000000..3887cf5f1e84 --- /dev/null +++ b/drivers/staging/octeon/Makefile @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2005-2009 Cavium Networks +# + +# +# Makefile for Cavium OCTEON on-board ethernet driver +# + +obj-${CONFIG_OCTEON_ETHERNET} := octeon-ethernet.o + +octeon-ethernet-y := ethernet.o +octeon-ethernet-y += ethernet-mdio.o +octeon-ethernet-y += ethernet-mem.o +octeon-ethernet-y += ethernet-rgmii.o +octeon-ethernet-y += ethernet-rx.o +octeon-ethernet-y += ethernet-sgmii.o +octeon-ethernet-y += ethernet-spi.o +octeon-ethernet-y += ethernet-tx.o diff --git a/drivers/staging/octeon/TODO b/drivers/staging/octeon/TODO new file mode 100644 index 000000000000..67a0a1f6b922 --- /dev/null +++ b/drivers/staging/octeon/TODO @@ -0,0 +1,9 @@ +This driver is functional and supports Ethernet on OCTEON+/OCTEON2/OCTEON3 +chips at least up to CN7030. + +TODO: + - general code review and clean up + - make driver self-contained instead of being split between staging and + arch/mips/cavium-octeon. + +Contact: Aaro Koskinen <aaro.koskinen@iki.fi> diff --git a/drivers/staging/octeon/ethernet-defines.h b/drivers/staging/octeon/ethernet-defines.h new file mode 100644 index 000000000000..ef9e767b0e2e --- /dev/null +++ b/drivers/staging/octeon/ethernet-defines.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +/* + * A few defines are used to control the operation of this driver: + * USE_ASYNC_IOBDMA + * Use asynchronous IO access to hardware. This uses Octeon's asynchronous + * IOBDMAs to issue IO accesses without stalling. Set this to zero + * to disable this. Note that IOBDMAs require CVMSEG. + * REUSE_SKBUFFS_WITHOUT_FREE + * Allows the TX path to free an skbuff into the FPA hardware pool. This + * can significantly improve performance for forwarding and bridging, but + * may be somewhat dangerous. Checks are made, but if any buffer is reused + * without the proper Linux cleanup, the networking stack may have very + * bizarre bugs. + */ +#ifndef __ETHERNET_DEFINES_H__ +#define __ETHERNET_DEFINES_H__ + +#ifdef CONFIG_NETFILTER +#define REUSE_SKBUFFS_WITHOUT_FREE 0 +#else +#define REUSE_SKBUFFS_WITHOUT_FREE 1 +#endif + +#define USE_ASYNC_IOBDMA (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0) + +/* Maximum number of SKBs to try to free per xmit packet. */ +#define MAX_OUT_QUEUE_DEPTH 1000 + +#define FAU_TOTAL_TX_TO_CLEAN (CVMX_FAU_REG_END - sizeof(u32)) +#define FAU_NUM_PACKET_BUFFERS_TO_FREE (FAU_TOTAL_TX_TO_CLEAN - sizeof(u32)) + +#define TOTAL_NUMBER_OF_PORTS (CVMX_PIP_NUM_INPUT_PORTS + 1) + +#endif /* __ETHERNET_DEFINES_H__ */ diff --git a/drivers/staging/octeon/ethernet-mdio.c b/drivers/staging/octeon/ethernet-mdio.c new file mode 100644 index 000000000000..c798672d61b2 --- /dev/null +++ b/drivers/staging/octeon/ethernet-mdio.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/kernel.h> +#include <linux/ethtool.h> +#include <linux/phy.h> +#include <linux/ratelimit.h> +#include <linux/of_mdio.h> +#include <generated/utsrelease.h> +#include <net/dst.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-mdio.h" +#include "ethernet-util.h" + +static void cvm_oct_get_drvinfo(struct net_device *dev, + struct ethtool_drvinfo *info) +{ + strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); + strlcpy(info->version, UTS_RELEASE, sizeof(info->version)); + strlcpy(info->bus_info, "Builtin", sizeof(info->bus_info)); +} + +static int cvm_oct_nway_reset(struct net_device *dev) +{ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + + if (dev->phydev) + return phy_start_aneg(dev->phydev); + + return -EINVAL; +} + +const struct ethtool_ops cvm_oct_ethtool_ops = { + .get_drvinfo = cvm_oct_get_drvinfo, + .nway_reset = cvm_oct_nway_reset, + .get_link = ethtool_op_get_link, + .get_link_ksettings = phy_ethtool_get_link_ksettings, + .set_link_ksettings = phy_ethtool_set_link_ksettings, +}; + +/** + * cvm_oct_ioctl - IOCTL support for PHY control + * @dev: Device to change + * @rq: the request + * @cmd: the command + * + * Returns Zero on success + */ +int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) +{ + if (!netif_running(dev)) + return -EINVAL; + + if (!dev->phydev) + return -EINVAL; + + return phy_mii_ioctl(dev->phydev, rq, cmd); +} + +void cvm_oct_note_carrier(struct octeon_ethernet *priv, + union cvmx_helper_link_info li) +{ + if (li.s.link_up) { + pr_notice_ratelimited("%s: %u Mbps %s duplex, port %d, queue %d\n", + netdev_name(priv->netdev), li.s.speed, + (li.s.full_duplex) ? "Full" : "Half", + priv->port, priv->queue); + } else { + pr_notice_ratelimited("%s: Link down\n", + netdev_name(priv->netdev)); + } +} + +void cvm_oct_adjust_link(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + union cvmx_helper_link_info link_info; + + link_info.u64 = 0; + link_info.s.link_up = dev->phydev->link ? 1 : 0; + link_info.s.full_duplex = dev->phydev->duplex ? 1 : 0; + link_info.s.speed = dev->phydev->speed; + priv->link_info = link_info.u64; + + /* + * The polling task need to know about link status changes. + */ + if (priv->poll) + priv->poll(dev); + + if (priv->last_link != dev->phydev->link) { + priv->last_link = dev->phydev->link; + cvmx_helper_link_set(priv->port, link_info); + cvm_oct_note_carrier(priv, link_info); + } +} + +int cvm_oct_common_stop(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + int interface = INTERFACE(priv->port); + union cvmx_helper_link_info link_info; + union cvmx_gmxx_prtx_cfg gmx_cfg; + int index = INDEX(priv->port); + + gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); + gmx_cfg.s.en = 0; + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64); + + priv->poll = NULL; + + if (dev->phydev) + phy_disconnect(dev->phydev); + + if (priv->last_link) { + link_info.u64 = 0; + priv->last_link = 0; + + cvmx_helper_link_set(priv->port, link_info); + cvm_oct_note_carrier(priv, link_info); + } + return 0; +} + +/** + * cvm_oct_phy_setup_device - setup the PHY + * + * @dev: Device to setup + * + * Returns Zero on success, negative on failure + */ +int cvm_oct_phy_setup_device(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + struct device_node *phy_node; + struct phy_device *phydev = NULL; + + if (!priv->of_node) + goto no_phy; + + phy_node = of_parse_phandle(priv->of_node, "phy-handle", 0); + if (!phy_node && of_phy_is_fixed_link(priv->of_node)) { + int rc; + + rc = of_phy_register_fixed_link(priv->of_node); + if (rc) + return rc; + + phy_node = of_node_get(priv->of_node); + } + if (!phy_node) + goto no_phy; + + phydev = of_phy_connect(dev, phy_node, cvm_oct_adjust_link, 0, + priv->phy_mode); + of_node_put(phy_node); + + if (!phydev) + return -ENODEV; + + priv->last_link = 0; + phy_start(phydev); + + return 0; +no_phy: + /* If there is no phy, assume a direct MAC connection and that + * the link is up. + */ + netif_carrier_on(dev); + return 0; +} diff --git a/drivers/staging/octeon/ethernet-mdio.h b/drivers/staging/octeon/ethernet-mdio.h new file mode 100644 index 000000000000..e3771d48c49b --- /dev/null +++ b/drivers/staging/octeon/ethernet-mdio.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/ip.h> +#include <linux/string.h> +#include <linux/ethtool.h> +#include <linux/seq_file.h> +#include <linux/proc_fs.h> +#include <net/dst.h> +#ifdef CONFIG_XFRM +#include <linux/xfrm.h> +#include <net/xfrm.h> +#endif /* CONFIG_XFRM */ + +extern const struct ethtool_ops cvm_oct_ethtool_ops; + +void octeon_mdiobus_force_mod_depencency(void); + +int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); +int cvm_oct_phy_setup_device(struct net_device *dev); diff --git a/drivers/staging/octeon/ethernet-mem.c b/drivers/staging/octeon/ethernet-mem.c new file mode 100644 index 000000000000..532594957ebc --- /dev/null +++ b/drivers/staging/octeon/ethernet-mem.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2010 Cavium Networks + */ + +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/slab.h> + +#include "octeon-ethernet.h" +#include "ethernet-mem.h" +#include "ethernet-defines.h" + +/** + * cvm_oct_fill_hw_skbuff - fill the supplied hardware pool with skbuffs + * @pool: Pool to allocate an skbuff for + * @size: Size of the buffer needed for the pool + * @elements: Number of buffers to allocate + * + * Returns the actual number of buffers allocated. + */ +static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements) +{ + int freed = elements; + + while (freed) { + struct sk_buff *skb = dev_alloc_skb(size + 256); + + if (unlikely(!skb)) + break; + skb_reserve(skb, 256 - (((unsigned long)skb->data) & 0x7f)); + *(struct sk_buff **)(skb->data - sizeof(void *)) = skb; + cvmx_fpa_free(skb->data, pool, size / 128); + freed--; + } + return elements - freed; +} + +/** + * cvm_oct_free_hw_skbuff- free hardware pool skbuffs + * @pool: Pool to allocate an skbuff for + * @size: Size of the buffer needed for the pool + * @elements: Number of buffers to allocate + */ +static void cvm_oct_free_hw_skbuff(int pool, int size, int elements) +{ + char *memory; + + do { + memory = cvmx_fpa_alloc(pool); + if (memory) { + struct sk_buff *skb = + *(struct sk_buff **)(memory - sizeof(void *)); + elements--; + dev_kfree_skb(skb); + } + } while (memory); + + if (elements < 0) + pr_warn("Freeing of pool %u had too many skbuffs (%d)\n", + pool, elements); + else if (elements > 0) + pr_warn("Freeing of pool %u is missing %d skbuffs\n", + pool, elements); +} + +/** + * cvm_oct_fill_hw_memory - fill a hardware pool with memory. + * @pool: Pool to populate + * @size: Size of each buffer in the pool + * @elements: Number of buffers to allocate + * + * Returns the actual number of buffers allocated. + */ +static int cvm_oct_fill_hw_memory(int pool, int size, int elements) +{ + char *memory; + char *fpa; + int freed = elements; + + while (freed) { + /* + * FPA memory must be 128 byte aligned. Since we are + * aligning we need to save the original pointer so we + * can feed it to kfree when the memory is returned to + * the kernel. + * + * We allocate an extra 256 bytes to allow for + * alignment and space for the original pointer saved + * just before the block. + */ + memory = kmalloc(size + 256, GFP_ATOMIC); + if (unlikely(!memory)) { + pr_warn("Unable to allocate %u bytes for FPA pool %d\n", + elements * size, pool); + break; + } + fpa = (char *)(((unsigned long)memory + 256) & ~0x7fUL); + *((char **)fpa - 1) = memory; + cvmx_fpa_free(fpa, pool, 0); + freed--; + } + return elements - freed; +} + +/** + * cvm_oct_free_hw_memory - Free memory allocated by cvm_oct_fill_hw_memory + * @pool: FPA pool to free + * @size: Size of each buffer in the pool + * @elements: Number of buffers that should be in the pool + */ +static void cvm_oct_free_hw_memory(int pool, int size, int elements) +{ + char *memory; + char *fpa; + + do { + fpa = cvmx_fpa_alloc(pool); + if (fpa) { + elements--; + fpa = (char *)phys_to_virt(cvmx_ptr_to_phys(fpa)); + memory = *((char **)fpa - 1); + kfree(memory); + } + } while (fpa); + + if (elements < 0) + pr_warn("Freeing of pool %u had too many buffers (%d)\n", + pool, elements); + else if (elements > 0) + pr_warn("Warning: Freeing of pool %u is missing %d buffers\n", + pool, elements); +} + +int cvm_oct_mem_fill_fpa(int pool, int size, int elements) +{ + int freed; + + if (pool == CVMX_FPA_PACKET_POOL) + freed = cvm_oct_fill_hw_skbuff(pool, size, elements); + else + freed = cvm_oct_fill_hw_memory(pool, size, elements); + return freed; +} + +void cvm_oct_mem_empty_fpa(int pool, int size, int elements) +{ + if (pool == CVMX_FPA_PACKET_POOL) + cvm_oct_free_hw_skbuff(pool, size, elements); + else + cvm_oct_free_hw_memory(pool, size, elements); +} diff --git a/drivers/staging/octeon/ethernet-mem.h b/drivers/staging/octeon/ethernet-mem.h new file mode 100644 index 000000000000..692dcdb7154d --- /dev/null +++ b/drivers/staging/octeon/ethernet-mem.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +int cvm_oct_mem_fill_fpa(int pool, int size, int elements); +void cvm_oct_mem_empty_fpa(int pool, int size, int elements); diff --git a/drivers/staging/octeon/ethernet-rgmii.c b/drivers/staging/octeon/ethernet-rgmii.c new file mode 100644 index 000000000000..0c4fac31540a --- /dev/null +++ b/drivers/staging/octeon/ethernet-rgmii.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/interrupt.h> +#include <linux/phy.h> +#include <linux/ratelimit.h> +#include <net/dst.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-util.h" +#include "ethernet-mdio.h" + +static DEFINE_SPINLOCK(global_register_lock); + +static void cvm_oct_set_hw_preamble(struct octeon_ethernet *priv, bool enable) +{ + union cvmx_gmxx_rxx_frm_ctl gmxx_rxx_frm_ctl; + union cvmx_ipd_sub_port_fcs ipd_sub_port_fcs; + union cvmx_gmxx_rxx_int_reg gmxx_rxx_int_reg; + int interface = INTERFACE(priv->port); + int index = INDEX(priv->port); + + /* Set preamble checking. */ + gmxx_rxx_frm_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL(index, + interface)); + gmxx_rxx_frm_ctl.s.pre_chk = enable; + cvmx_write_csr(CVMX_GMXX_RXX_FRM_CTL(index, interface), + gmxx_rxx_frm_ctl.u64); + + /* Set FCS stripping. */ + ipd_sub_port_fcs.u64 = cvmx_read_csr(CVMX_IPD_SUB_PORT_FCS); + if (enable) + ipd_sub_port_fcs.s.port_bit |= 1ull << priv->port; + else + ipd_sub_port_fcs.s.port_bit &= + 0xffffffffull ^ (1ull << priv->port); + cvmx_write_csr(CVMX_IPD_SUB_PORT_FCS, ipd_sub_port_fcs.u64); + + /* Clear any error bits. */ + gmxx_rxx_int_reg.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(index, + interface)); + cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(index, interface), + gmxx_rxx_int_reg.u64); +} + +static void cvm_oct_check_preamble_errors(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + union cvmx_helper_link_info link_info; + unsigned long flags; + + link_info.u64 = priv->link_info; + + /* + * Take the global register lock since we are going to + * touch registers that affect more than one port. + */ + spin_lock_irqsave(&global_register_lock, flags); + + if (link_info.s.speed == 10 && priv->last_speed == 10) { + /* + * Read the GMXX_RXX_INT_REG[PCTERR] bit and see if we are + * getting preamble errors. + */ + int interface = INTERFACE(priv->port); + int index = INDEX(priv->port); + union cvmx_gmxx_rxx_int_reg gmxx_rxx_int_reg; + + gmxx_rxx_int_reg.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_REG + (index, interface)); + if (gmxx_rxx_int_reg.s.pcterr) { + /* + * We are getting preamble errors at 10Mbps. Most + * likely the PHY is giving us packets with misaligned + * preambles. In order to get these packets we need to + * disable preamble checking and do it in software. + */ + cvm_oct_set_hw_preamble(priv, false); + printk_ratelimited("%s: Using 10Mbps with software preamble removal\n", + dev->name); + } + } else { + /* + * Since the 10Mbps preamble workaround is allowed we need to + * enable preamble checking, FCS stripping, and clear error + * bits on every speed change. If errors occur during 10Mbps + * operation the above code will change this stuff + */ + if (priv->last_speed != link_info.s.speed) + cvm_oct_set_hw_preamble(priv, true); + priv->last_speed = link_info.s.speed; + } + spin_unlock_irqrestore(&global_register_lock, flags); +} + +static void cvm_oct_rgmii_poll(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + union cvmx_helper_link_info link_info; + bool status_change; + + link_info = cvmx_helper_link_get(priv->port); + if (priv->link_info != link_info.u64 && + cvmx_helper_link_set(priv->port, link_info)) + link_info.u64 = priv->link_info; + status_change = priv->link_info != link_info.u64; + priv->link_info = link_info.u64; + + cvm_oct_check_preamble_errors(dev); + + if (likely(!status_change)) + return; + + /* Tell core. */ + if (link_info.s.link_up) { + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + } else if (netif_carrier_ok(dev)) { + netif_carrier_off(dev); + } + cvm_oct_note_carrier(priv, link_info); +} + +int cvm_oct_rgmii_open(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + int ret; + + ret = cvm_oct_common_open(dev, cvm_oct_rgmii_poll); + if (ret) + return ret; + + if (dev->phydev) { + /* + * In phydev mode, we need still periodic polling for the + * preamble error checking, and we also need to call this + * function on every link state change. + * + * Only true RGMII ports need to be polled. In GMII mode, port + * 0 is really a RGMII port. + */ + if ((priv->imode == CVMX_HELPER_INTERFACE_MODE_GMII && + priv->port == 0) || + (priv->imode == CVMX_HELPER_INTERFACE_MODE_RGMII)) { + priv->poll = cvm_oct_check_preamble_errors; + cvm_oct_check_preamble_errors(dev); + } + } + + return 0; +} diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c new file mode 100644 index 000000000000..2c16230f993c --- /dev/null +++ b/drivers/staging/octeon/ethernet-rx.c @@ -0,0 +1,538 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2010 Cavium Networks + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/cache.h> +#include <linux/cpumask.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/ip.h> +#include <linux/string.h> +#include <linux/prefetch.h> +#include <linux/ratelimit.h> +#include <linux/smp.h> +#include <linux/interrupt.h> +#include <net/dst.h> +#ifdef CONFIG_XFRM +#include <linux/xfrm.h> +#include <net/xfrm.h> +#endif /* CONFIG_XFRM */ + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-mem.h" +#include "ethernet-rx.h" +#include "ethernet-util.h" + +static atomic_t oct_rx_ready = ATOMIC_INIT(0); + +static struct oct_rx_group { + int irq; + int group; + struct napi_struct napi; +} oct_rx_group[16]; + +/** + * cvm_oct_do_interrupt - interrupt handler. + * @irq: Interrupt number. + * @napi_id: Cookie to identify the NAPI instance. + * + * The interrupt occurs whenever the POW has packets in our group. + * + */ +static irqreturn_t cvm_oct_do_interrupt(int irq, void *napi_id) +{ + /* Disable the IRQ and start napi_poll. */ + disable_irq_nosync(irq); + napi_schedule(napi_id); + + return IRQ_HANDLED; +} + +/** + * cvm_oct_check_rcv_error - process receive errors + * @work: Work queue entry pointing to the packet. + * + * Returns Non-zero if the packet can be dropped, zero otherwise. + */ +static inline int cvm_oct_check_rcv_error(struct cvmx_wqe *work) +{ + int port; + + if (octeon_has_feature(OCTEON_FEATURE_PKND)) + port = work->word0.pip.cn68xx.pknd; + else + port = work->word1.cn38xx.ipprt; + + if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64)) { + /* + * Ignore length errors on min size packets. Some + * equipment incorrectly pads packets to 64+4FCS + * instead of 60+4FCS. Note these packets still get + * counted as frame errors. + */ + } else if (work->word2.snoip.err_code == 5 || + work->word2.snoip.err_code == 7) { + /* + * We received a packet with either an alignment error + * or a FCS error. This may be signalling that we are + * running 10Mbps with GMXX_RXX_FRM_CTL[PRE_CHK] + * off. If this is the case we need to parse the + * packet to determine if we can remove a non spec + * preamble and generate a correct packet. + */ + int interface = cvmx_helper_get_interface_num(port); + int index = cvmx_helper_get_interface_index_num(port); + union cvmx_gmxx_rxx_frm_ctl gmxx_rxx_frm_ctl; + + gmxx_rxx_frm_ctl.u64 = + cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL(index, interface)); + if (gmxx_rxx_frm_ctl.s.pre_chk == 0) { + u8 *ptr = + cvmx_phys_to_ptr(work->packet_ptr.s.addr); + int i = 0; + + while (i < work->word1.len - 1) { + if (*ptr != 0x55) + break; + ptr++; + i++; + } + + if (*ptr == 0xd5) { + /* Port received 0xd5 preamble */ + work->packet_ptr.s.addr += i + 1; + work->word1.len -= i + 5; + } else if ((*ptr & 0xf) == 0xd) { + /* Port received 0xd preamble */ + work->packet_ptr.s.addr += i; + work->word1.len -= i + 4; + for (i = 0; i < work->word1.len; i++) { + *ptr = + ((*ptr & 0xf0) >> 4) | + ((*(ptr + 1) & 0xf) << 4); + ptr++; + } + } else { + printk_ratelimited("Port %d unknown preamble, packet dropped\n", + port); + cvm_oct_free_work(work); + return 1; + } + } + } else { + printk_ratelimited("Port %d receive error code %d, packet dropped\n", + port, work->word2.snoip.err_code); + cvm_oct_free_work(work); + return 1; + } + + return 0; +} + +static void copy_segments_to_skb(struct cvmx_wqe *work, struct sk_buff *skb) +{ + int segments = work->word2.s.bufs; + union cvmx_buf_ptr segment_ptr = work->packet_ptr; + int len = work->word1.len; + int segment_size; + + while (segments--) { + union cvmx_buf_ptr next_ptr; + + next_ptr = *(union cvmx_buf_ptr *) + cvmx_phys_to_ptr(segment_ptr.s.addr - 8); + + /* + * Octeon Errata PKI-100: The segment size is wrong. + * + * Until it is fixed, calculate the segment size based on + * the packet pool buffer size. + * When it is fixed, the following line should be replaced + * with this one: + * int segment_size = segment_ptr.s.size; + */ + segment_size = + CVMX_FPA_PACKET_POOL_SIZE - + (segment_ptr.s.addr - + (((segment_ptr.s.addr >> 7) - + segment_ptr.s.back) << 7)); + + /* Don't copy more than what is left in the packet */ + if (segment_size > len) + segment_size = len; + + /* Copy the data into the packet */ + skb_put_data(skb, cvmx_phys_to_ptr(segment_ptr.s.addr), + segment_size); + len -= segment_size; + segment_ptr = next_ptr; + } +} + +static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget) +{ + const int coreid = cvmx_get_core_num(); + u64 old_group_mask; + u64 old_scratch; + int rx_count = 0; + int did_work_request = 0; + int packet_not_copied; + + /* Prefetch cvm_oct_device since we know we need it soon */ + prefetch(cvm_oct_device); + + if (USE_ASYNC_IOBDMA) { + /* Save scratch in case userspace is using it */ + CVMX_SYNCIOBDMA; + old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH); + } + + /* Only allow work for our group (and preserve priorities) */ + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) { + old_group_mask = cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid)); + cvmx_write_csr(CVMX_SSO_PPX_GRP_MSK(coreid), + BIT(rx_group->group)); + cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid)); /* Flush */ + } else { + old_group_mask = cvmx_read_csr(CVMX_POW_PP_GRP_MSKX(coreid)); + cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), + (old_group_mask & ~0xFFFFull) | + BIT(rx_group->group)); + } + + if (USE_ASYNC_IOBDMA) { + cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); + did_work_request = 1; + } + + while (rx_count < budget) { + struct sk_buff *skb = NULL; + struct sk_buff **pskb = NULL; + int skb_in_hw; + struct cvmx_wqe *work; + int port; + + if (USE_ASYNC_IOBDMA && did_work_request) + work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH); + else + work = cvmx_pow_work_request_sync(CVMX_POW_NO_WAIT); + + prefetch(work); + did_work_request = 0; + if (!work) { + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) { + cvmx_write_csr(CVMX_SSO_WQ_IQ_DIS, + BIT(rx_group->group)); + cvmx_write_csr(CVMX_SSO_WQ_INT, + BIT(rx_group->group)); + } else { + union cvmx_pow_wq_int wq_int; + + wq_int.u64 = 0; + wq_int.s.iq_dis = BIT(rx_group->group); + wq_int.s.wq_int = BIT(rx_group->group); + cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64); + } + break; + } + pskb = (struct sk_buff **) + (cvm_oct_get_buffer_ptr(work->packet_ptr) - + sizeof(void *)); + prefetch(pskb); + + if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) { + cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH, + CVMX_POW_NO_WAIT); + did_work_request = 1; + } + rx_count++; + + skb_in_hw = work->word2.s.bufs == 1; + if (likely(skb_in_hw)) { + skb = *pskb; + prefetch(&skb->head); + prefetch(&skb->len); + } + + if (octeon_has_feature(OCTEON_FEATURE_PKND)) + port = work->word0.pip.cn68xx.pknd; + else + port = work->word1.cn38xx.ipprt; + + prefetch(cvm_oct_device[port]); + + /* Immediately throw away all packets with receive errors */ + if (unlikely(work->word2.snoip.rcv_error)) { + if (cvm_oct_check_rcv_error(work)) + continue; + } + + /* + * We can only use the zero copy path if skbuffs are + * in the FPA pool and the packet fits in a single + * buffer. + */ + if (likely(skb_in_hw)) { + skb->data = skb->head + work->packet_ptr.s.addr - + cvmx_ptr_to_phys(skb->head); + prefetch(skb->data); + skb->len = work->word1.len; + skb_set_tail_pointer(skb, skb->len); + packet_not_copied = 1; + } else { + /* + * We have to copy the packet. First allocate + * an skbuff for it. + */ + skb = dev_alloc_skb(work->word1.len); + if (!skb) { + cvm_oct_free_work(work); + continue; + } + + /* + * Check if we've received a packet that was + * entirely stored in the work entry. + */ + if (unlikely(work->word2.s.bufs == 0)) { + u8 *ptr = work->packet_data; + + if (likely(!work->word2.s.not_IP)) { + /* + * The beginning of the packet + * moves for IP packets. + */ + if (work->word2.s.is_v6) + ptr += 2; + else + ptr += 6; + } + skb_put_data(skb, ptr, work->word1.len); + /* No packet buffers to free */ + } else { + copy_segments_to_skb(work, skb); + } + packet_not_copied = 0; + } + if (likely((port < TOTAL_NUMBER_OF_PORTS) && + cvm_oct_device[port])) { + struct net_device *dev = cvm_oct_device[port]; + + /* + * Only accept packets for devices that are + * currently up. + */ + if (likely(dev->flags & IFF_UP)) { + skb->protocol = eth_type_trans(skb, dev); + skb->dev = dev; + + if (unlikely(work->word2.s.not_IP || + work->word2.s.IP_exc || + work->word2.s.L4_error || + !work->word2.s.tcp_or_udp)) + skb->ip_summed = CHECKSUM_NONE; + else + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* Increment RX stats for virtual ports */ + if (port >= CVMX_PIP_NUM_INPUT_PORTS) { + dev->stats.rx_packets++; + dev->stats.rx_bytes += skb->len; + } + netif_receive_skb(skb); + } else { + /* + * Drop any packet received for a device that + * isn't up. + */ + dev->stats.rx_dropped++; + dev_kfree_skb_irq(skb); + } + } else { + /* + * Drop any packet received for a device that + * doesn't exist. + */ + printk_ratelimited("Port %d not controlled by Linux, packet dropped\n", + port); + dev_kfree_skb_irq(skb); + } + /* + * Check to see if the skbuff and work share the same + * packet buffer. + */ + if (likely(packet_not_copied)) { + /* + * This buffer needs to be replaced, increment + * the number of buffers we need to free by + * one. + */ + cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, + 1); + + cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1); + } else { + cvm_oct_free_work(work); + } + } + /* Restore the original POW group mask */ + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) { + cvmx_write_csr(CVMX_SSO_PPX_GRP_MSK(coreid), old_group_mask); + cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid)); /* Flush */ + } else { + cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask); + } + + if (USE_ASYNC_IOBDMA) { + /* Restore the scratch area */ + cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch); + } + cvm_oct_rx_refill_pool(0); + + return rx_count; +} + +/** + * cvm_oct_napi_poll - the NAPI poll function. + * @napi: The NAPI instance. + * @budget: Maximum number of packets to receive. + * + * Returns the number of packets processed. + */ +static int cvm_oct_napi_poll(struct napi_struct *napi, int budget) +{ + struct oct_rx_group *rx_group = container_of(napi, struct oct_rx_group, + napi); + int rx_count; + + rx_count = cvm_oct_poll(rx_group, budget); + + if (rx_count < budget) { + /* No more work */ + napi_complete_done(napi, rx_count); + enable_irq(rx_group->irq); + } + return rx_count; +} + +#ifdef CONFIG_NET_POLL_CONTROLLER +/** + * cvm_oct_poll_controller - poll for receive packets + * device. + * + * @dev: Device to poll. Unused + */ +void cvm_oct_poll_controller(struct net_device *dev) +{ + int i; + + if (!atomic_read(&oct_rx_ready)) + return; + + for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) { + if (!(pow_receive_groups & BIT(i))) + continue; + + cvm_oct_poll(&oct_rx_group[i], 16); + } +} +#endif + +void cvm_oct_rx_initialize(void) +{ + int i; + struct net_device *dev_for_napi = NULL; + + for (i = 0; i < TOTAL_NUMBER_OF_PORTS; i++) { + if (cvm_oct_device[i]) { + dev_for_napi = cvm_oct_device[i]; + break; + } + } + + if (!dev_for_napi) + panic("No net_devices were allocated."); + + for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) { + int ret; + + if (!(pow_receive_groups & BIT(i))) + continue; + + netif_napi_add(dev_for_napi, &oct_rx_group[i].napi, + cvm_oct_napi_poll, rx_napi_weight); + napi_enable(&oct_rx_group[i].napi); + + oct_rx_group[i].irq = OCTEON_IRQ_WORKQ0 + i; + oct_rx_group[i].group = i; + + /* Register an IRQ handler to receive POW interrupts */ + ret = request_irq(oct_rx_group[i].irq, cvm_oct_do_interrupt, 0, + "Ethernet", &oct_rx_group[i].napi); + if (ret) + panic("Could not acquire Ethernet IRQ %d\n", + oct_rx_group[i].irq); + + disable_irq_nosync(oct_rx_group[i].irq); + + /* Enable POW interrupt when our port has at least one packet */ + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) { + union cvmx_sso_wq_int_thrx int_thr; + union cvmx_pow_wq_int_pc int_pc; + + int_thr.u64 = 0; + int_thr.s.tc_en = 1; + int_thr.s.tc_thr = 1; + cvmx_write_csr(CVMX_SSO_WQ_INT_THRX(i), int_thr.u64); + + int_pc.u64 = 0; + int_pc.s.pc_thr = 5; + cvmx_write_csr(CVMX_SSO_WQ_INT_PC, int_pc.u64); + } else { + union cvmx_pow_wq_int_thrx int_thr; + union cvmx_pow_wq_int_pc int_pc; + + int_thr.u64 = 0; + int_thr.s.tc_en = 1; + int_thr.s.tc_thr = 1; + cvmx_write_csr(CVMX_POW_WQ_INT_THRX(i), int_thr.u64); + + int_pc.u64 = 0; + int_pc.s.pc_thr = 5; + cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64); + } + + /* Schedule NAPI now. This will indirectly enable the + * interrupt. + */ + napi_schedule(&oct_rx_group[i].napi); + } + atomic_inc(&oct_rx_ready); +} + +void cvm_oct_rx_shutdown(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) { + if (!(pow_receive_groups & BIT(i))) + continue; + + /* Disable POW interrupt */ + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) + cvmx_write_csr(CVMX_SSO_WQ_INT_THRX(i), 0); + else + cvmx_write_csr(CVMX_POW_WQ_INT_THRX(i), 0); + + /* Free the interrupt handler */ + free_irq(oct_rx_group[i].irq, cvm_oct_device); + + netif_napi_del(&oct_rx_group[i].napi); + } +} diff --git a/drivers/staging/octeon/ethernet-rx.h b/drivers/staging/octeon/ethernet-rx.h new file mode 100644 index 000000000000..ff6482fa20d6 --- /dev/null +++ b/drivers/staging/octeon/ethernet-rx.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +void cvm_oct_poll_controller(struct net_device *dev); +void cvm_oct_rx_initialize(void); +void cvm_oct_rx_shutdown(void); + +static inline void cvm_oct_rx_refill_pool(int fill_threshold) +{ + int number_to_free; + int num_freed; + /* Refill the packet buffer pool */ + number_to_free = + cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); + + if (number_to_free > fill_threshold) { + cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, + -number_to_free); + num_freed = cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL, + CVMX_FPA_PACKET_POOL_SIZE, + number_to_free); + if (num_freed != number_to_free) { + cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, + number_to_free - num_freed); + } + } +} diff --git a/drivers/staging/octeon/ethernet-sgmii.c b/drivers/staging/octeon/ethernet-sgmii.c new file mode 100644 index 000000000000..d7fbd9159302 --- /dev/null +++ b/drivers/staging/octeon/ethernet-sgmii.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/phy.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/ratelimit.h> +#include <net/dst.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-util.h" +#include "ethernet-mdio.h" + +int cvm_oct_sgmii_open(struct net_device *dev) +{ + return cvm_oct_common_open(dev, cvm_oct_link_poll); +} + +int cvm_oct_sgmii_init(struct net_device *dev) +{ + cvm_oct_common_init(dev); + + /* FIXME: Need autoneg logic */ + return 0; +} diff --git a/drivers/staging/octeon/ethernet-spi.c b/drivers/staging/octeon/ethernet-spi.c new file mode 100644 index 000000000000..c582403e6a1f --- /dev/null +++ b/drivers/staging/octeon/ethernet-spi.c @@ -0,0 +1,226 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/interrupt.h> +#include <net/dst.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-util.h" + +static int number_spi_ports; +static int need_retrain[2] = { 0, 0 }; + +static void cvm_oct_spxx_int_pr(union cvmx_spxx_int_reg spx_int_reg, int index) +{ + if (spx_int_reg.s.spf) + pr_err("SPI%d: SRX Spi4 interface down\n", index); + if (spx_int_reg.s.calerr) + pr_err("SPI%d: SRX Spi4 Calendar table parity error\n", index); + if (spx_int_reg.s.syncerr) + pr_err("SPI%d: SRX Consecutive Spi4 DIP4 errors have exceeded SPX_ERR_CTL[ERRCNT]\n", + index); + if (spx_int_reg.s.diperr) + pr_err("SPI%d: SRX Spi4 DIP4 error\n", index); + if (spx_int_reg.s.tpaovr) + pr_err("SPI%d: SRX Selected port has hit TPA overflow\n", + index); + if (spx_int_reg.s.rsverr) + pr_err("SPI%d: SRX Spi4 reserved control word detected\n", + index); + if (spx_int_reg.s.drwnng) + pr_err("SPI%d: SRX Spi4 receive FIFO drowning/overflow\n", + index); + if (spx_int_reg.s.clserr) + pr_err("SPI%d: SRX Spi4 packet closed on non-16B alignment without EOP\n", + index); + if (spx_int_reg.s.spiovr) + pr_err("SPI%d: SRX Spi4 async FIFO overflow\n", index); + if (spx_int_reg.s.abnorm) + pr_err("SPI%d: SRX Abnormal packet termination (ERR bit)\n", + index); + if (spx_int_reg.s.prtnxa) + pr_err("SPI%d: SRX Port out of range\n", index); +} + +static void cvm_oct_stxx_int_pr(union cvmx_stxx_int_reg stx_int_reg, int index) +{ + if (stx_int_reg.s.syncerr) + pr_err("SPI%d: STX Interface encountered a fatal error\n", + index); + if (stx_int_reg.s.frmerr) + pr_err("SPI%d: STX FRMCNT has exceeded STX_DIP_CNT[MAXFRM]\n", + index); + if (stx_int_reg.s.unxfrm) + pr_err("SPI%d: STX Unexpected framing sequence\n", index); + if (stx_int_reg.s.nosync) + pr_err("SPI%d: STX ERRCNT has exceeded STX_DIP_CNT[MAXDIP]\n", + index); + if (stx_int_reg.s.diperr) + pr_err("SPI%d: STX DIP2 error on the Spi4 Status channel\n", + index); + if (stx_int_reg.s.datovr) + pr_err("SPI%d: STX Spi4 FIFO overflow error\n", index); + if (stx_int_reg.s.ovrbst) + pr_err("SPI%d: STX Transmit packet burst too big\n", index); + if (stx_int_reg.s.calpar1) + pr_err("SPI%d: STX Calendar Table Parity Error Bank%d\n", + index, 1); + if (stx_int_reg.s.calpar0) + pr_err("SPI%d: STX Calendar Table Parity Error Bank%d\n", + index, 0); +} + +static irqreturn_t cvm_oct_spi_spx_int(int index) +{ + union cvmx_spxx_int_reg spx_int_reg; + union cvmx_stxx_int_reg stx_int_reg; + + spx_int_reg.u64 = cvmx_read_csr(CVMX_SPXX_INT_REG(index)); + cvmx_write_csr(CVMX_SPXX_INT_REG(index), spx_int_reg.u64); + if (!need_retrain[index]) { + spx_int_reg.u64 &= cvmx_read_csr(CVMX_SPXX_INT_MSK(index)); + cvm_oct_spxx_int_pr(spx_int_reg, index); + } + + stx_int_reg.u64 = cvmx_read_csr(CVMX_STXX_INT_REG(index)); + cvmx_write_csr(CVMX_STXX_INT_REG(index), stx_int_reg.u64); + if (!need_retrain[index]) { + stx_int_reg.u64 &= cvmx_read_csr(CVMX_STXX_INT_MSK(index)); + cvm_oct_stxx_int_pr(stx_int_reg, index); + } + + cvmx_write_csr(CVMX_SPXX_INT_MSK(index), 0); + cvmx_write_csr(CVMX_STXX_INT_MSK(index), 0); + need_retrain[index] = 1; + + return IRQ_HANDLED; +} + +static irqreturn_t cvm_oct_spi_rml_interrupt(int cpl, void *dev_id) +{ + irqreturn_t return_status = IRQ_NONE; + union cvmx_npi_rsl_int_blocks rsl_int_blocks; + + /* Check and see if this interrupt was caused by the GMX block */ + rsl_int_blocks.u64 = cvmx_read_csr(CVMX_NPI_RSL_INT_BLOCKS); + if (rsl_int_blocks.s.spx1) /* 19 - SPX1_INT_REG & STX1_INT_REG */ + return_status = cvm_oct_spi_spx_int(1); + + if (rsl_int_blocks.s.spx0) /* 18 - SPX0_INT_REG & STX0_INT_REG */ + return_status = cvm_oct_spi_spx_int(0); + + return return_status; +} + +static void cvm_oct_spi_enable_error_reporting(int interface) +{ + union cvmx_spxx_int_msk spxx_int_msk; + union cvmx_stxx_int_msk stxx_int_msk; + + spxx_int_msk.u64 = cvmx_read_csr(CVMX_SPXX_INT_MSK(interface)); + spxx_int_msk.s.calerr = 1; + spxx_int_msk.s.syncerr = 1; + spxx_int_msk.s.diperr = 1; + spxx_int_msk.s.tpaovr = 1; + spxx_int_msk.s.rsverr = 1; + spxx_int_msk.s.drwnng = 1; + spxx_int_msk.s.clserr = 1; + spxx_int_msk.s.spiovr = 1; + spxx_int_msk.s.abnorm = 1; + spxx_int_msk.s.prtnxa = 1; + cvmx_write_csr(CVMX_SPXX_INT_MSK(interface), spxx_int_msk.u64); + + stxx_int_msk.u64 = cvmx_read_csr(CVMX_STXX_INT_MSK(interface)); + stxx_int_msk.s.frmerr = 1; + stxx_int_msk.s.unxfrm = 1; + stxx_int_msk.s.nosync = 1; + stxx_int_msk.s.diperr = 1; + stxx_int_msk.s.datovr = 1; + stxx_int_msk.s.ovrbst = 1; + stxx_int_msk.s.calpar1 = 1; + stxx_int_msk.s.calpar0 = 1; + cvmx_write_csr(CVMX_STXX_INT_MSK(interface), stxx_int_msk.u64); +} + +static void cvm_oct_spi_poll(struct net_device *dev) +{ + static int spi4000_port; + struct octeon_ethernet *priv = netdev_priv(dev); + int interface; + + for (interface = 0; interface < 2; interface++) { + if ((priv->port == interface * 16) && need_retrain[interface]) { + if (cvmx_spi_restart_interface + (interface, CVMX_SPI_MODE_DUPLEX, 10) == 0) { + need_retrain[interface] = 0; + cvm_oct_spi_enable_error_reporting(interface); + } + } + + /* + * The SPI4000 TWSI interface is very slow. In order + * not to bring the system to a crawl, we only poll a + * single port every second. This means negotiation + * speed changes take up to 10 seconds, but at least + * we don't waste absurd amounts of time waiting for + * TWSI. + */ + if (priv->port == spi4000_port) { + /* + * This function does nothing if it is called on an + * interface without a SPI4000. + */ + cvmx_spi4000_check_speed(interface, priv->port); + /* + * Normal ordering increments. By decrementing + * we only match once per iteration. + */ + spi4000_port--; + if (spi4000_port < 0) + spi4000_port = 10; + } + } +} + +int cvm_oct_spi_init(struct net_device *dev) +{ + int r; + struct octeon_ethernet *priv = netdev_priv(dev); + + if (number_spi_ports == 0) { + r = request_irq(OCTEON_IRQ_RML, cvm_oct_spi_rml_interrupt, + IRQF_SHARED, "SPI", &number_spi_ports); + if (r) + return r; + } + number_spi_ports++; + + if ((priv->port == 0) || (priv->port == 16)) { + cvm_oct_spi_enable_error_reporting(INTERFACE(priv->port)); + priv->poll = cvm_oct_spi_poll; + } + cvm_oct_common_init(dev); + return 0; +} + +void cvm_oct_spi_uninit(struct net_device *dev) +{ + int interface; + + cvm_oct_common_uninit(dev); + number_spi_ports--; + if (number_spi_ports == 0) { + for (interface = 0; interface < 2; interface++) { + cvmx_write_csr(CVMX_SPXX_INT_MSK(interface), 0); + cvmx_write_csr(CVMX_STXX_INT_MSK(interface), 0); + } + free_irq(OCTEON_IRQ_RML, &number_spi_ports); + } +} diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c new file mode 100644 index 000000000000..b334cf89794e --- /dev/null +++ b/drivers/staging/octeon/ethernet-tx.c @@ -0,0 +1,717 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2010 Cavium Networks + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/ip.h> +#include <linux/ratelimit.h> +#include <linux/string.h> +#include <linux/interrupt.h> +#include <net/dst.h> +#ifdef CONFIG_XFRM +#include <linux/xfrm.h> +#include <net/xfrm.h> +#endif /* CONFIG_XFRM */ + +#include <linux/atomic.h> +#include <net/sch_generic.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-tx.h" +#include "ethernet-util.h" + +#define CVM_OCT_SKB_CB(skb) ((u64 *)((skb)->cb)) + +/* + * You can define GET_SKBUFF_QOS() to override how the skbuff output + * function determines which output queue is used. The default + * implementation always uses the base queue for the port. If, for + * example, you wanted to use the skb->priority field, define + * GET_SKBUFF_QOS as: #define GET_SKBUFF_QOS(skb) ((skb)->priority) + */ +#ifndef GET_SKBUFF_QOS +#define GET_SKBUFF_QOS(skb) 0 +#endif + +static void cvm_oct_tx_do_cleanup(unsigned long arg); +static DECLARE_TASKLET(cvm_oct_tx_cleanup_tasklet, cvm_oct_tx_do_cleanup, 0); + +/* Maximum number of SKBs to try to free per xmit packet. */ +#define MAX_SKB_TO_FREE (MAX_OUT_QUEUE_DEPTH * 2) + +static inline int cvm_oct_adjust_skb_to_free(int skb_to_free, int fau) +{ + int undo; + + undo = skb_to_free > 0 ? MAX_SKB_TO_FREE : skb_to_free + + MAX_SKB_TO_FREE; + if (undo > 0) + cvmx_fau_atomic_add32(fau, -undo); + skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ? MAX_SKB_TO_FREE : + -skb_to_free; + return skb_to_free; +} + +static void cvm_oct_kick_tx_poll_watchdog(void) +{ + union cvmx_ciu_timx ciu_timx; + + ciu_timx.u64 = 0; + ciu_timx.s.one_shot = 1; + ciu_timx.s.len = cvm_oct_tx_poll_interval; + cvmx_write_csr(CVMX_CIU_TIMX(1), ciu_timx.u64); +} + +static void cvm_oct_free_tx_skbs(struct net_device *dev) +{ + int skb_to_free; + int qos, queues_per_port; + int total_freed = 0; + int total_remaining = 0; + unsigned long flags; + struct octeon_ethernet *priv = netdev_priv(dev); + + queues_per_port = cvmx_pko_get_num_queues(priv->port); + /* Drain any pending packets in the free list */ + for (qos = 0; qos < queues_per_port; qos++) { + if (skb_queue_len(&priv->tx_free_list[qos]) == 0) + continue; + skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4, + MAX_SKB_TO_FREE); + skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, + priv->fau + qos * 4); + total_freed += skb_to_free; + if (skb_to_free > 0) { + struct sk_buff *to_free_list = NULL; + + spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags); + while (skb_to_free > 0) { + struct sk_buff *t; + + t = __skb_dequeue(&priv->tx_free_list[qos]); + t->next = to_free_list; + to_free_list = t; + skb_to_free--; + } + spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, + flags); + /* Do the actual freeing outside of the lock. */ + while (to_free_list) { + struct sk_buff *t = to_free_list; + + to_free_list = to_free_list->next; + dev_kfree_skb_any(t); + } + } + total_remaining += skb_queue_len(&priv->tx_free_list[qos]); + } + if (total_remaining < MAX_OUT_QUEUE_DEPTH && netif_queue_stopped(dev)) + netif_wake_queue(dev); + if (total_remaining) + cvm_oct_kick_tx_poll_watchdog(); +} + +/** + * cvm_oct_xmit - transmit a packet + * @skb: Packet to send + * @dev: Device info structure + * + * Returns Always returns NETDEV_TX_OK + */ +int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev) +{ + union cvmx_pko_command_word0 pko_command; + union cvmx_buf_ptr hw_buffer; + u64 old_scratch; + u64 old_scratch2; + int qos; + int i; + enum {QUEUE_CORE, QUEUE_HW, QUEUE_DROP} queue_type; + struct octeon_ethernet *priv = netdev_priv(dev); + struct sk_buff *to_free_list; + int skb_to_free; + int buffers_to_free; + u32 total_to_clean; + unsigned long flags; +#if REUSE_SKBUFFS_WITHOUT_FREE + unsigned char *fpa_head; +#endif + + /* + * Prefetch the private data structure. It is larger than the + * one cache line. + */ + prefetch(priv); + + /* + * The check on CVMX_PKO_QUEUES_PER_PORT_* is designed to + * completely remove "qos" in the event neither interface + * supports multiple queues per port. + */ + if ((CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 > 1) || + (CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 > 1)) { + qos = GET_SKBUFF_QOS(skb); + if (qos <= 0) + qos = 0; + else if (qos >= cvmx_pko_get_num_queues(priv->port)) + qos = 0; + } else { + qos = 0; + } + + if (USE_ASYNC_IOBDMA) { + /* Save scratch in case userspace is using it */ + CVMX_SYNCIOBDMA; + old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH); + old_scratch2 = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8); + + /* + * Fetch and increment the number of packets to be + * freed. + */ + cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH + 8, + FAU_NUM_PACKET_BUFFERS_TO_FREE, + 0); + cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH, + priv->fau + qos * 4, + MAX_SKB_TO_FREE); + } + + /* + * We have space for 6 segment pointers, If there will be more + * than that, we must linearize. + */ + if (unlikely(skb_shinfo(skb)->nr_frags > 5)) { + if (unlikely(__skb_linearize(skb))) { + queue_type = QUEUE_DROP; + if (USE_ASYNC_IOBDMA) { + /* + * Get the number of skbuffs in use + * by the hardware + */ + CVMX_SYNCIOBDMA; + skb_to_free = + cvmx_scratch_read64(CVMX_SCR_SCRATCH); + } else { + /* + * Get the number of skbuffs in use + * by the hardware + */ + skb_to_free = + cvmx_fau_fetch_and_add32(priv->fau + + qos * 4, + MAX_SKB_TO_FREE); + } + skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, + priv->fau + + qos * 4); + spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags); + goto skip_xmit; + } + } + + /* + * The CN3XXX series of parts has an errata (GMX-401) which + * causes the GMX block to hang if a collision occurs towards + * the end of a <68 byte packet. As a workaround for this, we + * pad packets to be 68 bytes whenever we are in half duplex + * mode. We don't handle the case of having a small packet but + * no room to add the padding. The kernel should always give + * us at least a cache line + */ + if ((skb->len < 64) && OCTEON_IS_MODEL(OCTEON_CN3XXX)) { + union cvmx_gmxx_prtx_cfg gmx_prt_cfg; + int interface = INTERFACE(priv->port); + int index = INDEX(priv->port); + + if (interface < 2) { + /* We only need to pad packet in half duplex mode */ + gmx_prt_cfg.u64 = + cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); + if (gmx_prt_cfg.s.duplex == 0) { + int add_bytes = 64 - skb->len; + + if ((skb_tail_pointer(skb) + add_bytes) <= + skb_end_pointer(skb)) + __skb_put_zero(skb, add_bytes); + } + } + } + + /* Build the PKO command */ + pko_command.u64 = 0; +#ifdef __LITTLE_ENDIAN + pko_command.s.le = 1; +#endif + pko_command.s.n2 = 1; /* Don't pollute L2 with the outgoing packet */ + pko_command.s.segs = 1; + pko_command.s.total_bytes = skb->len; + pko_command.s.size0 = CVMX_FAU_OP_SIZE_32; + pko_command.s.subone0 = 1; + + pko_command.s.dontfree = 1; + + /* Build the PKO buffer pointer */ + hw_buffer.u64 = 0; + if (skb_shinfo(skb)->nr_frags == 0) { + hw_buffer.s.addr = XKPHYS_TO_PHYS((uintptr_t)skb->data); + hw_buffer.s.pool = 0; + hw_buffer.s.size = skb->len; + } else { + hw_buffer.s.addr = XKPHYS_TO_PHYS((uintptr_t)skb->data); + hw_buffer.s.pool = 0; + hw_buffer.s.size = skb_headlen(skb); + CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64; + for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { + skb_frag_t *fs = skb_shinfo(skb)->frags + i; + + hw_buffer.s.addr = + XKPHYS_TO_PHYS((uintptr_t)skb_frag_address(fs)); + hw_buffer.s.size = skb_frag_size(fs); + CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64; + } + hw_buffer.s.addr = + XKPHYS_TO_PHYS((uintptr_t)CVM_OCT_SKB_CB(skb)); + hw_buffer.s.size = skb_shinfo(skb)->nr_frags + 1; + pko_command.s.segs = skb_shinfo(skb)->nr_frags + 1; + pko_command.s.gather = 1; + goto dont_put_skbuff_in_hw; + } + + /* + * See if we can put this skb in the FPA pool. Any strange + * behavior from the Linux networking stack will most likely + * be caused by a bug in the following code. If some field is + * in use by the network stack and gets carried over when a + * buffer is reused, bad things may happen. If in doubt and + * you dont need the absolute best performance, disable the + * define REUSE_SKBUFFS_WITHOUT_FREE. The reuse of buffers has + * shown a 25% increase in performance under some loads. + */ +#if REUSE_SKBUFFS_WITHOUT_FREE + fpa_head = skb->head + 256 - ((unsigned long)skb->head & 0x7f); + if (unlikely(skb->data < fpa_head)) { + /* TX buffer beginning can't meet FPA alignment constraints */ + goto dont_put_skbuff_in_hw; + } + if (unlikely + ((skb_end_pointer(skb) - fpa_head) < CVMX_FPA_PACKET_POOL_SIZE)) { + /* TX buffer isn't large enough for the FPA */ + goto dont_put_skbuff_in_hw; + } + if (unlikely(skb_shared(skb))) { + /* TX buffer sharing data with someone else */ + goto dont_put_skbuff_in_hw; + } + if (unlikely(skb_cloned(skb))) { + /* TX buffer has been cloned */ + goto dont_put_skbuff_in_hw; + } + if (unlikely(skb_header_cloned(skb))) { + /* TX buffer header has been cloned */ + goto dont_put_skbuff_in_hw; + } + if (unlikely(skb->destructor)) { + /* TX buffer has a destructor */ + goto dont_put_skbuff_in_hw; + } + if (unlikely(skb_shinfo(skb)->nr_frags)) { + /* TX buffer has fragments */ + goto dont_put_skbuff_in_hw; + } + if (unlikely + (skb->truesize != + sizeof(*skb) + skb_end_offset(skb))) { + /* TX buffer truesize has been changed */ + goto dont_put_skbuff_in_hw; + } + + /* + * We can use this buffer in the FPA. We don't need the FAU + * update anymore + */ + pko_command.s.dontfree = 0; + + hw_buffer.s.back = ((unsigned long)skb->data >> 7) - + ((unsigned long)fpa_head >> 7); + + *(struct sk_buff **)(fpa_head - sizeof(void *)) = skb; + + /* + * The skbuff will be reused without ever being freed. We must + * cleanup a bunch of core things. + */ + dst_release(skb_dst(skb)); + skb_dst_set(skb, NULL); + skb_ext_reset(skb); + nf_reset_ct(skb); + +#ifdef CONFIG_NET_SCHED + skb->tc_index = 0; + skb_reset_tc(skb); +#endif /* CONFIG_NET_SCHED */ +#endif /* REUSE_SKBUFFS_WITHOUT_FREE */ + +dont_put_skbuff_in_hw: + + /* Check if we can use the hardware checksumming */ + if ((skb->protocol == htons(ETH_P_IP)) && + (ip_hdr(skb)->version == 4) && + (ip_hdr(skb)->ihl == 5) && + ((ip_hdr(skb)->frag_off == 0) || + (ip_hdr(skb)->frag_off == htons(1 << 14))) && + ((ip_hdr(skb)->protocol == IPPROTO_TCP) || + (ip_hdr(skb)->protocol == IPPROTO_UDP))) { + /* Use hardware checksum calc */ + pko_command.s.ipoffp1 = skb_network_offset(skb) + 1; + } + + if (USE_ASYNC_IOBDMA) { + /* Get the number of skbuffs in use by the hardware */ + CVMX_SYNCIOBDMA; + skb_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH); + buffers_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8); + } else { + /* Get the number of skbuffs in use by the hardware */ + skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4, + MAX_SKB_TO_FREE); + buffers_to_free = + cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); + } + + skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, + priv->fau + qos * 4); + + /* + * If we're sending faster than the receive can free them then + * don't do the HW free. + */ + if ((buffers_to_free < -100) && !pko_command.s.dontfree) + pko_command.s.dontfree = 1; + + if (pko_command.s.dontfree) { + queue_type = QUEUE_CORE; + pko_command.s.reg0 = priv->fau + qos * 4; + } else { + queue_type = QUEUE_HW; + } + if (USE_ASYNC_IOBDMA) + cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH, + FAU_TOTAL_TX_TO_CLEAN, 1); + + spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags); + + /* Drop this packet if we have too many already queued to the HW */ + if (unlikely(skb_queue_len(&priv->tx_free_list[qos]) >= + MAX_OUT_QUEUE_DEPTH)) { + if (dev->tx_queue_len != 0) { + /* Drop the lock when notifying the core. */ + spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, + flags); + netif_stop_queue(dev); + spin_lock_irqsave(&priv->tx_free_list[qos].lock, + flags); + } else { + /* If not using normal queueing. */ + queue_type = QUEUE_DROP; + goto skip_xmit; + } + } + + cvmx_pko_send_packet_prepare(priv->port, priv->queue + qos, + CVMX_PKO_LOCK_NONE); + + /* Send the packet to the output queue */ + if (unlikely(cvmx_pko_send_packet_finish(priv->port, + priv->queue + qos, + pko_command, hw_buffer, + CVMX_PKO_LOCK_NONE))) { + printk_ratelimited("%s: Failed to send the packet\n", + dev->name); + queue_type = QUEUE_DROP; + } +skip_xmit: + to_free_list = NULL; + + switch (queue_type) { + case QUEUE_DROP: + skb->next = to_free_list; + to_free_list = skb; + dev->stats.tx_dropped++; + break; + case QUEUE_HW: + cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, -1); + break; + case QUEUE_CORE: + __skb_queue_tail(&priv->tx_free_list[qos], skb); + break; + default: + BUG(); + } + + while (skb_to_free > 0) { + struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]); + + t->next = to_free_list; + to_free_list = t; + skb_to_free--; + } + + spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags); + + /* Do the actual freeing outside of the lock. */ + while (to_free_list) { + struct sk_buff *t = to_free_list; + + to_free_list = to_free_list->next; + dev_kfree_skb_any(t); + } + + if (USE_ASYNC_IOBDMA) { + CVMX_SYNCIOBDMA; + total_to_clean = cvmx_scratch_read64(CVMX_SCR_SCRATCH); + /* Restore the scratch area */ + cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch); + cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2); + } else { + total_to_clean = + cvmx_fau_fetch_and_add32(FAU_TOTAL_TX_TO_CLEAN, 1); + } + + if (total_to_clean & 0x3ff) { + /* + * Schedule the cleanup tasklet every 1024 packets for + * the pathological case of high traffic on one port + * delaying clean up of packets on a different port + * that is blocked waiting for the cleanup. + */ + tasklet_schedule(&cvm_oct_tx_cleanup_tasklet); + } + + cvm_oct_kick_tx_poll_watchdog(); + + return NETDEV_TX_OK; +} + +/** + * cvm_oct_xmit_pow - transmit a packet to the POW + * @skb: Packet to send + * @dev: Device info structure + + * Returns Always returns zero + */ +int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + void *packet_buffer; + void *copy_location; + + /* Get a work queue entry */ + struct cvmx_wqe *work = cvmx_fpa_alloc(CVMX_FPA_WQE_POOL); + + if (unlikely(!work)) { + printk_ratelimited("%s: Failed to allocate a work queue entry\n", + dev->name); + dev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return 0; + } + + /* Get a packet buffer */ + packet_buffer = cvmx_fpa_alloc(CVMX_FPA_PACKET_POOL); + if (unlikely(!packet_buffer)) { + printk_ratelimited("%s: Failed to allocate a packet buffer\n", + dev->name); + cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1); + dev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return 0; + } + + /* + * Calculate where we need to copy the data to. We need to + * leave 8 bytes for a next pointer (unused). We also need to + * include any configure skip. Then we need to align the IP + * packet src and dest into the same 64bit word. The below + * calculation may add a little extra, but that doesn't + * hurt. + */ + copy_location = packet_buffer + sizeof(u64); + copy_location += ((CVMX_HELPER_FIRST_MBUFF_SKIP + 7) & 0xfff8) + 6; + + /* + * We have to copy the packet since whoever processes this + * packet will free it to a hardware pool. We can't use the + * trick of counting outstanding packets like in + * cvm_oct_xmit. + */ + memcpy(copy_location, skb->data, skb->len); + + /* + * Fill in some of the work queue fields. We may need to add + * more if the software at the other end needs them. + */ + if (!OCTEON_IS_MODEL(OCTEON_CN68XX)) + work->word0.pip.cn38xx.hw_chksum = skb->csum; + work->word1.len = skb->len; + cvmx_wqe_set_port(work, priv->port); + cvmx_wqe_set_qos(work, priv->port & 0x7); + cvmx_wqe_set_grp(work, pow_send_group); + work->word1.tag_type = CVMX_HELPER_INPUT_TAG_TYPE; + work->word1.tag = pow_send_group; /* FIXME */ + /* Default to zero. Sets of zero later are commented out */ + work->word2.u64 = 0; + work->word2.s.bufs = 1; + work->packet_ptr.u64 = 0; + work->packet_ptr.s.addr = cvmx_ptr_to_phys(copy_location); + work->packet_ptr.s.pool = CVMX_FPA_PACKET_POOL; + work->packet_ptr.s.size = CVMX_FPA_PACKET_POOL_SIZE; + work->packet_ptr.s.back = (copy_location - packet_buffer) >> 7; + + if (skb->protocol == htons(ETH_P_IP)) { + work->word2.s.ip_offset = 14; +#if 0 + work->word2.s.vlan_valid = 0; /* FIXME */ + work->word2.s.vlan_cfi = 0; /* FIXME */ + work->word2.s.vlan_id = 0; /* FIXME */ + work->word2.s.dec_ipcomp = 0; /* FIXME */ +#endif + work->word2.s.tcp_or_udp = + (ip_hdr(skb)->protocol == IPPROTO_TCP) || + (ip_hdr(skb)->protocol == IPPROTO_UDP); +#if 0 + /* FIXME */ + work->word2.s.dec_ipsec = 0; + /* We only support IPv4 right now */ + work->word2.s.is_v6 = 0; + /* Hardware would set to zero */ + work->word2.s.software = 0; + /* No error, packet is internal */ + work->word2.s.L4_error = 0; +#endif + work->word2.s.is_frag = !((ip_hdr(skb)->frag_off == 0) || + (ip_hdr(skb)->frag_off == + cpu_to_be16(1 << 14))); +#if 0 + /* Assume Linux is sending a good packet */ + work->word2.s.IP_exc = 0; +#endif + work->word2.s.is_bcast = (skb->pkt_type == PACKET_BROADCAST); + work->word2.s.is_mcast = (skb->pkt_type == PACKET_MULTICAST); +#if 0 + /* This is an IP packet */ + work->word2.s.not_IP = 0; + /* No error, packet is internal */ + work->word2.s.rcv_error = 0; + /* No error, packet is internal */ + work->word2.s.err_code = 0; +#endif + + /* + * When copying the data, include 4 bytes of the + * ethernet header to align the same way hardware + * does. + */ + memcpy(work->packet_data, skb->data + 10, + sizeof(work->packet_data)); + } else { +#if 0 + work->word2.snoip.vlan_valid = 0; /* FIXME */ + work->word2.snoip.vlan_cfi = 0; /* FIXME */ + work->word2.snoip.vlan_id = 0; /* FIXME */ + work->word2.snoip.software = 0; /* Hardware would set to zero */ +#endif + work->word2.snoip.is_rarp = skb->protocol == htons(ETH_P_RARP); + work->word2.snoip.is_arp = skb->protocol == htons(ETH_P_ARP); + work->word2.snoip.is_bcast = + (skb->pkt_type == PACKET_BROADCAST); + work->word2.snoip.is_mcast = + (skb->pkt_type == PACKET_MULTICAST); + work->word2.snoip.not_IP = 1; /* IP was done up above */ +#if 0 + /* No error, packet is internal */ + work->word2.snoip.rcv_error = 0; + /* No error, packet is internal */ + work->word2.snoip.err_code = 0; +#endif + memcpy(work->packet_data, skb->data, sizeof(work->packet_data)); + } + + /* Submit the packet to the POW */ + cvmx_pow_work_submit(work, work->word1.tag, work->word1.tag_type, + cvmx_wqe_get_qos(work), cvmx_wqe_get_grp(work)); + dev->stats.tx_packets++; + dev->stats.tx_bytes += skb->len; + dev_consume_skb_any(skb); + return 0; +} + +/** + * cvm_oct_tx_shutdown_dev - free all skb that are currently queued for TX. + * @dev: Device being shutdown + * + */ +void cvm_oct_tx_shutdown_dev(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + unsigned long flags; + int qos; + + for (qos = 0; qos < 16; qos++) { + spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags); + while (skb_queue_len(&priv->tx_free_list[qos])) + dev_kfree_skb_any(__skb_dequeue + (&priv->tx_free_list[qos])); + spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags); + } +} + +static void cvm_oct_tx_do_cleanup(unsigned long arg) +{ + int port; + + for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) { + if (cvm_oct_device[port]) { + struct net_device *dev = cvm_oct_device[port]; + + cvm_oct_free_tx_skbs(dev); + } + } +} + +static irqreturn_t cvm_oct_tx_cleanup_watchdog(int cpl, void *dev_id) +{ + /* Disable the interrupt. */ + cvmx_write_csr(CVMX_CIU_TIMX(1), 0); + /* Do the work in the tasklet. */ + tasklet_schedule(&cvm_oct_tx_cleanup_tasklet); + return IRQ_HANDLED; +} + +void cvm_oct_tx_initialize(void) +{ + int i; + + /* Disable the interrupt. */ + cvmx_write_csr(CVMX_CIU_TIMX(1), 0); + /* Register an IRQ handler to receive CIU_TIMX(1) interrupts */ + i = request_irq(OCTEON_IRQ_TIMER1, + cvm_oct_tx_cleanup_watchdog, 0, + "Ethernet", cvm_oct_device); + + if (i) + panic("Could not acquire Ethernet IRQ %d\n", OCTEON_IRQ_TIMER1); +} + +void cvm_oct_tx_shutdown(void) +{ + /* Free the interrupt handler */ + free_irq(OCTEON_IRQ_TIMER1, cvm_oct_device); +} diff --git a/drivers/staging/octeon/ethernet-tx.h b/drivers/staging/octeon/ethernet-tx.h new file mode 100644 index 000000000000..78936e9b33b0 --- /dev/null +++ b/drivers/staging/octeon/ethernet-tx.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev); +int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev); +int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry, + int do_free, int qos); +void cvm_oct_tx_initialize(void); +void cvm_oct_tx_shutdown(void); +void cvm_oct_tx_shutdown_dev(struct net_device *dev); diff --git a/drivers/staging/octeon/ethernet-util.h b/drivers/staging/octeon/ethernet-util.h new file mode 100644 index 000000000000..2af83a12ca78 --- /dev/null +++ b/drivers/staging/octeon/ethernet-util.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +/** + * cvm_oct_get_buffer_ptr - convert packet data address to pointer + * @packet_ptr: Packet data hardware address + * + * Returns Packet buffer pointer + */ +static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr) +{ + return cvmx_phys_to_ptr(((packet_ptr.s.addr >> 7) - packet_ptr.s.back) + << 7); +} + +/** + * INTERFACE - convert IPD port to logical interface + * @ipd_port: Port to check + * + * Returns Logical interface + */ +static inline int INTERFACE(int ipd_port) +{ + int interface; + + if (ipd_port == CVMX_PIP_NUM_INPUT_PORTS) + return 10; + interface = cvmx_helper_get_interface_num(ipd_port); + if (interface >= 0) + return interface; + panic("Illegal ipd_port %d passed to %s\n", ipd_port, __func__); +} + +/** + * INDEX - convert IPD/PKO port number to the port's interface index + * @ipd_port: Port to check + * + * Returns Index into interface port list + */ +static inline int INDEX(int ipd_port) +{ + return cvmx_helper_get_interface_index_num(ipd_port); +} diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c new file mode 100644 index 000000000000..f42c3816ce49 --- /dev/null +++ b/drivers/staging/octeon/ethernet.c @@ -0,0 +1,992 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2007 Cavium Networks + */ + +#include <linux/platform_device.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/etherdevice.h> +#include <linux/phy.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/of_net.h> +#include <linux/if_ether.h> +#include <linux/if_vlan.h> + +#include <net/dst.h> + +#include "octeon-ethernet.h" +#include "ethernet-defines.h" +#include "ethernet-mem.h" +#include "ethernet-rx.h" +#include "ethernet-tx.h" +#include "ethernet-mdio.h" +#include "ethernet-util.h" + +#define OCTEON_MAX_MTU 65392 + +static int num_packet_buffers = 1024; +module_param(num_packet_buffers, int, 0444); +MODULE_PARM_DESC(num_packet_buffers, "\n" + "\tNumber of packet buffers to allocate and store in the\n" + "\tFPA. By default, 1024 packet buffers are used.\n"); + +static int pow_receive_group = 15; +module_param(pow_receive_group, int, 0444); +MODULE_PARM_DESC(pow_receive_group, "\n" + "\tPOW group to receive packets from. All ethernet hardware\n" + "\twill be configured to send incoming packets to this POW\n" + "\tgroup. Also any other software can submit packets to this\n" + "\tgroup for the kernel to process."); + +static int receive_group_order; +module_param(receive_group_order, int, 0444); +MODULE_PARM_DESC(receive_group_order, "\n" + "\tOrder (0..4) of receive groups to take into use. Ethernet hardware\n" + "\twill be configured to send incoming packets to multiple POW\n" + "\tgroups. pow_receive_group parameter is ignored when multiple\n" + "\tgroups are taken into use and groups are allocated starting\n" + "\tfrom 0. By default, a single group is used.\n"); + +int pow_send_group = -1; +module_param(pow_send_group, int, 0644); +MODULE_PARM_DESC(pow_send_group, "\n" + "\tPOW group to send packets to other software on. This\n" + "\tcontrols the creation of the virtual device pow0.\n" + "\talways_use_pow also depends on this value."); + +int always_use_pow; +module_param(always_use_pow, int, 0444); +MODULE_PARM_DESC(always_use_pow, "\n" + "\tWhen set, always send to the pow group. This will cause\n" + "\tpackets sent to real ethernet devices to be sent to the\n" + "\tPOW group instead of the hardware. Unless some other\n" + "\tapplication changes the config, packets will still be\n" + "\treceived from the low level hardware. Use this option\n" + "\tto allow a CVMX app to intercept all packets from the\n" + "\tlinux kernel. You must specify pow_send_group along with\n" + "\tthis option."); + +char pow_send_list[128] = ""; +module_param_string(pow_send_list, pow_send_list, sizeof(pow_send_list), 0444); +MODULE_PARM_DESC(pow_send_list, "\n" + "\tComma separated list of ethernet devices that should use the\n" + "\tPOW for transmit instead of the actual ethernet hardware. This\n" + "\tis a per port version of always_use_pow. always_use_pow takes\n" + "\tprecedence over this list. For example, setting this to\n" + "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n" + "\tusing the pow_send_group."); + +int rx_napi_weight = 32; +module_param(rx_napi_weight, int, 0444); +MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter."); + +/* Mask indicating which receive groups are in use. */ +int pow_receive_groups; + +/* + * cvm_oct_poll_queue_stopping - flag to indicate polling should stop. + * + * Set to one right before cvm_oct_poll_queue is destroyed. + */ +atomic_t cvm_oct_poll_queue_stopping = ATOMIC_INIT(0); + +/* + * Array of every ethernet device owned by this driver indexed by + * the ipd input port number. + */ +struct net_device *cvm_oct_device[TOTAL_NUMBER_OF_PORTS]; + +u64 cvm_oct_tx_poll_interval; + +static void cvm_oct_rx_refill_worker(struct work_struct *work); +static DECLARE_DELAYED_WORK(cvm_oct_rx_refill_work, cvm_oct_rx_refill_worker); + +static void cvm_oct_rx_refill_worker(struct work_struct *work) +{ + /* + * FPA 0 may have been drained, try to refill it if we need + * more than num_packet_buffers / 2, otherwise normal receive + * processing will refill it. If it were drained, no packets + * could be received so cvm_oct_napi_poll would never be + * invoked to do the refill. + */ + cvm_oct_rx_refill_pool(num_packet_buffers / 2); + + if (!atomic_read(&cvm_oct_poll_queue_stopping)) + schedule_delayed_work(&cvm_oct_rx_refill_work, HZ); +} + +static void cvm_oct_periodic_worker(struct work_struct *work) +{ + struct octeon_ethernet *priv = container_of(work, + struct octeon_ethernet, + port_periodic_work.work); + + if (priv->poll) + priv->poll(cvm_oct_device[priv->port]); + + cvm_oct_device[priv->port]->netdev_ops->ndo_get_stats + (cvm_oct_device[priv->port]); + + if (!atomic_read(&cvm_oct_poll_queue_stopping)) + schedule_delayed_work(&priv->port_periodic_work, HZ); +} + +static void cvm_oct_configure_common_hw(void) +{ + /* Setup the FPA */ + cvmx_fpa_enable(); + cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE, + num_packet_buffers); + cvm_oct_mem_fill_fpa(CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE, + num_packet_buffers); + if (CVMX_FPA_OUTPUT_BUFFER_POOL != CVMX_FPA_PACKET_POOL) + cvm_oct_mem_fill_fpa(CVMX_FPA_OUTPUT_BUFFER_POOL, + CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, 1024); + +#ifdef __LITTLE_ENDIAN + { + union cvmx_ipd_ctl_status ipd_ctl_status; + + ipd_ctl_status.u64 = cvmx_read_csr(CVMX_IPD_CTL_STATUS); + ipd_ctl_status.s.pkt_lend = 1; + ipd_ctl_status.s.wqe_lend = 1; + cvmx_write_csr(CVMX_IPD_CTL_STATUS, ipd_ctl_status.u64); + } +#endif + + cvmx_helper_setup_red(num_packet_buffers / 4, num_packet_buffers / 8); +} + +/** + * cvm_oct_free_work- Free a work queue entry + * + * @work_queue_entry: Work queue entry to free + * + * Returns Zero on success, Negative on failure. + */ +int cvm_oct_free_work(void *work_queue_entry) +{ + struct cvmx_wqe *work = work_queue_entry; + + int segments = work->word2.s.bufs; + union cvmx_buf_ptr segment_ptr = work->packet_ptr; + + while (segments--) { + union cvmx_buf_ptr next_ptr = *(union cvmx_buf_ptr *) + cvmx_phys_to_ptr(segment_ptr.s.addr - 8); + if (unlikely(!segment_ptr.s.i)) + cvmx_fpa_free(cvm_oct_get_buffer_ptr(segment_ptr), + segment_ptr.s.pool, + CVMX_FPA_PACKET_POOL_SIZE / 128); + segment_ptr = next_ptr; + } + cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1); + + return 0; +} +EXPORT_SYMBOL(cvm_oct_free_work); + +/** + * cvm_oct_common_get_stats - get the low level ethernet statistics + * @dev: Device to get the statistics from + * + * Returns Pointer to the statistics + */ +static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev) +{ + cvmx_pip_port_status_t rx_status; + cvmx_pko_port_status_t tx_status; + struct octeon_ethernet *priv = netdev_priv(dev); + + if (priv->port < CVMX_PIP_NUM_INPUT_PORTS) { + if (octeon_is_simulation()) { + /* The simulator doesn't support statistics */ + memset(&rx_status, 0, sizeof(rx_status)); + memset(&tx_status, 0, sizeof(tx_status)); + } else { + cvmx_pip_get_port_status(priv->port, 1, &rx_status); + cvmx_pko_get_port_status(priv->port, 1, &tx_status); + } + + dev->stats.rx_packets += rx_status.inb_packets; + dev->stats.tx_packets += tx_status.packets; + dev->stats.rx_bytes += rx_status.inb_octets; + dev->stats.tx_bytes += tx_status.octets; + dev->stats.multicast += rx_status.multicast_packets; + dev->stats.rx_crc_errors += rx_status.inb_errors; + dev->stats.rx_frame_errors += rx_status.fcs_align_err_packets; + dev->stats.rx_dropped += rx_status.dropped_packets; + } + + return &dev->stats; +} + +/** + * cvm_oct_common_change_mtu - change the link MTU + * @dev: Device to change + * @new_mtu: The new MTU + * + * Returns Zero on success + */ +static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + int interface = INTERFACE(priv->port); +#if IS_ENABLED(CONFIG_VLAN_8021Q) + int vlan_bytes = VLAN_HLEN; +#else + int vlan_bytes = 0; +#endif + int mtu_overhead = ETH_HLEN + ETH_FCS_LEN + vlan_bytes; + + dev->mtu = new_mtu; + + if ((interface < 2) && + (cvmx_helper_interface_get_mode(interface) != + CVMX_HELPER_INTERFACE_MODE_SPI)) { + int index = INDEX(priv->port); + /* Add ethernet header and FCS, and VLAN if configured. */ + int max_packet = new_mtu + mtu_overhead; + + if (OCTEON_IS_MODEL(OCTEON_CN3XXX) || + OCTEON_IS_MODEL(OCTEON_CN58XX)) { + /* Signal errors on packets larger than the MTU */ + cvmx_write_csr(CVMX_GMXX_RXX_FRM_MAX(index, interface), + max_packet); + } else { + /* + * Set the hardware to truncate packets larger + * than the MTU and smaller the 64 bytes. + */ + union cvmx_pip_frm_len_chkx frm_len_chk; + + frm_len_chk.u64 = 0; + frm_len_chk.s.minlen = VLAN_ETH_ZLEN; + frm_len_chk.s.maxlen = max_packet; + cvmx_write_csr(CVMX_PIP_FRM_LEN_CHKX(interface), + frm_len_chk.u64); + } + /* + * Set the hardware to truncate packets larger than + * the MTU. The jabber register must be set to a + * multiple of 8 bytes, so round up. + */ + cvmx_write_csr(CVMX_GMXX_RXX_JABBER(index, interface), + (max_packet + 7) & ~7u); + } + return 0; +} + +/** + * cvm_oct_common_set_multicast_list - set the multicast list + * @dev: Device to work on + */ +static void cvm_oct_common_set_multicast_list(struct net_device *dev) +{ + union cvmx_gmxx_prtx_cfg gmx_cfg; + struct octeon_ethernet *priv = netdev_priv(dev); + int interface = INTERFACE(priv->port); + + if ((interface < 2) && + (cvmx_helper_interface_get_mode(interface) != + CVMX_HELPER_INTERFACE_MODE_SPI)) { + union cvmx_gmxx_rxx_adr_ctl control; + int index = INDEX(priv->port); + + control.u64 = 0; + control.s.bcst = 1; /* Allow broadcast MAC addresses */ + + if (!netdev_mc_empty(dev) || (dev->flags & IFF_ALLMULTI) || + (dev->flags & IFF_PROMISC)) + /* Force accept multicast packets */ + control.s.mcst = 2; + else + /* Force reject multicast packets */ + control.s.mcst = 1; + + if (dev->flags & IFF_PROMISC) + /* + * Reject matches if promisc. Since CAM is + * shut off, should accept everything. + */ + control.s.cam_mode = 0; + else + /* Filter packets based on the CAM */ + control.s.cam_mode = 1; + + gmx_cfg.u64 = + cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), + gmx_cfg.u64 & ~1ull); + + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CTL(index, interface), + control.u64); + if (dev->flags & IFF_PROMISC) + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN + (index, interface), 0); + else + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM_EN + (index, interface), 1); + + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), + gmx_cfg.u64); + } +} + +static int cvm_oct_set_mac_filter(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + union cvmx_gmxx_prtx_cfg gmx_cfg; + int interface = INTERFACE(priv->port); + + if ((interface < 2) && + (cvmx_helper_interface_get_mode(interface) != + CVMX_HELPER_INTERFACE_MODE_SPI)) { + int i; + u8 *ptr = dev->dev_addr; + u64 mac = 0; + int index = INDEX(priv->port); + + for (i = 0; i < 6; i++) + mac = (mac << 8) | (u64)ptr[i]; + + gmx_cfg.u64 = + cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), + gmx_cfg.u64 & ~1ull); + + cvmx_write_csr(CVMX_GMXX_SMACX(index, interface), mac); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM0(index, interface), + ptr[0]); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM1(index, interface), + ptr[1]); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM2(index, interface), + ptr[2]); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM3(index, interface), + ptr[3]); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM4(index, interface), + ptr[4]); + cvmx_write_csr(CVMX_GMXX_RXX_ADR_CAM5(index, interface), + ptr[5]); + cvm_oct_common_set_multicast_list(dev); + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), + gmx_cfg.u64); + } + return 0; +} + +/** + * cvm_oct_common_set_mac_address - set the hardware MAC address for a device + * @dev: The device in question. + * @addr: Socket address. + * + * Returns Zero on success + */ +static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr) +{ + int r = eth_mac_addr(dev, addr); + + if (r) + return r; + return cvm_oct_set_mac_filter(dev); +} + +/** + * cvm_oct_common_init - per network device initialization + * @dev: Device to initialize + * + * Returns Zero on success + */ +int cvm_oct_common_init(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + const u8 *mac = NULL; + + if (priv->of_node) + mac = of_get_mac_address(priv->of_node); + + if (!IS_ERR_OR_NULL(mac)) + ether_addr_copy(dev->dev_addr, mac); + else + eth_hw_addr_random(dev); + + /* + * Force the interface to use the POW send if always_use_pow + * was specified or it is in the pow send list. + */ + if ((pow_send_group != -1) && + (always_use_pow || strstr(pow_send_list, dev->name))) + priv->queue = -1; + + if (priv->queue != -1) + dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM; + + /* We do our own locking, Linux doesn't need to */ + dev->features |= NETIF_F_LLTX; + dev->ethtool_ops = &cvm_oct_ethtool_ops; + + cvm_oct_set_mac_filter(dev); + dev_set_mtu(dev, dev->mtu); + + /* + * Zero out stats for port so we won't mistakenly show + * counters from the bootloader. + */ + memset(dev->netdev_ops->ndo_get_stats(dev), 0, + sizeof(struct net_device_stats)); + + if (dev->netdev_ops->ndo_stop) + dev->netdev_ops->ndo_stop(dev); + + return 0; +} + +void cvm_oct_common_uninit(struct net_device *dev) +{ + if (dev->phydev) + phy_disconnect(dev->phydev); +} + +int cvm_oct_common_open(struct net_device *dev, + void (*link_poll)(struct net_device *)) +{ + union cvmx_gmxx_prtx_cfg gmx_cfg; + struct octeon_ethernet *priv = netdev_priv(dev); + int interface = INTERFACE(priv->port); + int index = INDEX(priv->port); + union cvmx_helper_link_info link_info; + int rv; + + rv = cvm_oct_phy_setup_device(dev); + if (rv) + return rv; + + gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); + gmx_cfg.s.en = 1; + if (octeon_has_feature(OCTEON_FEATURE_PKND)) + gmx_cfg.s.pknd = priv->port; + cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64); + + if (octeon_is_simulation()) + return 0; + + if (dev->phydev) { + int r = phy_read_status(dev->phydev); + + if (r == 0 && dev->phydev->link == 0) + netif_carrier_off(dev); + cvm_oct_adjust_link(dev); + } else { + link_info = cvmx_helper_link_get(priv->port); + if (!link_info.s.link_up) + netif_carrier_off(dev); + priv->poll = link_poll; + link_poll(dev); + } + + return 0; +} + +void cvm_oct_link_poll(struct net_device *dev) +{ + struct octeon_ethernet *priv = netdev_priv(dev); + union cvmx_helper_link_info link_info; + + link_info = cvmx_helper_link_get(priv->port); + if (link_info.u64 == priv->link_info) + return; + + if (cvmx_helper_link_set(priv->port, link_info)) + link_info.u64 = priv->link_info; + else + priv->link_info = link_info.u64; + + if (link_info.s.link_up) { + if (!netif_carrier_ok(dev)) + netif_carrier_on(dev); + } else if (netif_carrier_ok(dev)) { + netif_carrier_off(dev); + } + cvm_oct_note_carrier(priv, link_info); +} + +static int cvm_oct_xaui_open(struct net_device *dev) +{ + return cvm_oct_common_open(dev, cvm_oct_link_poll); +} + +static const struct net_device_ops cvm_oct_npi_netdev_ops = { + .ndo_init = cvm_oct_common_init, + .ndo_uninit = cvm_oct_common_uninit, + .ndo_start_xmit = cvm_oct_xmit, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static const struct net_device_ops cvm_oct_xaui_netdev_ops = { + .ndo_init = cvm_oct_common_init, + .ndo_uninit = cvm_oct_common_uninit, + .ndo_open = cvm_oct_xaui_open, + .ndo_stop = cvm_oct_common_stop, + .ndo_start_xmit = cvm_oct_xmit, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static const struct net_device_ops cvm_oct_sgmii_netdev_ops = { + .ndo_init = cvm_oct_sgmii_init, + .ndo_uninit = cvm_oct_common_uninit, + .ndo_open = cvm_oct_sgmii_open, + .ndo_stop = cvm_oct_common_stop, + .ndo_start_xmit = cvm_oct_xmit, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static const struct net_device_ops cvm_oct_spi_netdev_ops = { + .ndo_init = cvm_oct_spi_init, + .ndo_uninit = cvm_oct_spi_uninit, + .ndo_start_xmit = cvm_oct_xmit, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static const struct net_device_ops cvm_oct_rgmii_netdev_ops = { + .ndo_init = cvm_oct_common_init, + .ndo_uninit = cvm_oct_common_uninit, + .ndo_open = cvm_oct_rgmii_open, + .ndo_stop = cvm_oct_common_stop, + .ndo_start_xmit = cvm_oct_xmit, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static const struct net_device_ops cvm_oct_pow_netdev_ops = { + .ndo_init = cvm_oct_common_init, + .ndo_start_xmit = cvm_oct_xmit_pow, + .ndo_set_rx_mode = cvm_oct_common_set_multicast_list, + .ndo_set_mac_address = cvm_oct_common_set_mac_address, + .ndo_do_ioctl = cvm_oct_ioctl, + .ndo_change_mtu = cvm_oct_common_change_mtu, + .ndo_get_stats = cvm_oct_common_get_stats, +#ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = cvm_oct_poll_controller, +#endif +}; + +static struct device_node *cvm_oct_of_get_child + (const struct device_node *parent, int reg_val) +{ + struct device_node *node = NULL; + int size; + const __be32 *addr; + + for (;;) { + node = of_get_next_child(parent, node); + if (!node) + break; + addr = of_get_property(node, "reg", &size); + if (addr && (be32_to_cpu(*addr) == reg_val)) + break; + } + return node; +} + +static struct device_node *cvm_oct_node_for_port(struct device_node *pip, + int interface, int port) +{ + struct device_node *ni, *np; + + ni = cvm_oct_of_get_child(pip, interface); + if (!ni) + return NULL; + + np = cvm_oct_of_get_child(ni, port); + of_node_put(ni); + + return np; +} + +static void cvm_set_rgmii_delay(struct octeon_ethernet *priv, int iface, + int port) +{ + struct device_node *np = priv->of_node; + u32 delay_value; + bool rx_delay; + bool tx_delay; + + /* By default, both RX/TX delay is enabled in + * __cvmx_helper_rgmii_enable(). + */ + rx_delay = true; + tx_delay = true; + + if (!of_property_read_u32(np, "rx-delay", &delay_value)) { + cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, iface), delay_value); + rx_delay = delay_value > 0; + } + if (!of_property_read_u32(np, "tx-delay", &delay_value)) { + cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, iface), delay_value); + tx_delay = delay_value > 0; + } + + if (!rx_delay && !tx_delay) + priv->phy_mode = PHY_INTERFACE_MODE_RGMII_ID; + else if (!rx_delay) + priv->phy_mode = PHY_INTERFACE_MODE_RGMII_RXID; + else if (!tx_delay) + priv->phy_mode = PHY_INTERFACE_MODE_RGMII_TXID; + else + priv->phy_mode = PHY_INTERFACE_MODE_RGMII; +} + +static int cvm_oct_probe(struct platform_device *pdev) +{ + int num_interfaces; + int interface; + int fau = FAU_NUM_PACKET_BUFFERS_TO_FREE; + int qos; + struct device_node *pip; + int mtu_overhead = ETH_HLEN + ETH_FCS_LEN; + +#if IS_ENABLED(CONFIG_VLAN_8021Q) + mtu_overhead += VLAN_HLEN; +#endif + + octeon_mdiobus_force_mod_depencency(); + + pip = pdev->dev.of_node; + if (!pip) { + pr_err("Error: No 'pip' in /aliases\n"); + return -EINVAL; + } + + cvm_oct_configure_common_hw(); + + cvmx_helper_initialize_packet_io_global(); + + if (receive_group_order) { + if (receive_group_order > 4) + receive_group_order = 4; + pow_receive_groups = (1 << (1 << receive_group_order)) - 1; + } else { + pow_receive_groups = BIT(pow_receive_group); + } + + /* Change the input group for all ports before input is enabled */ + num_interfaces = cvmx_helper_get_number_of_interfaces(); + for (interface = 0; interface < num_interfaces; interface++) { + int num_ports = cvmx_helper_ports_on_interface(interface); + int port; + + for (port = cvmx_helper_get_ipd_port(interface, 0); + port < cvmx_helper_get_ipd_port(interface, num_ports); + port++) { + union cvmx_pip_prt_tagx pip_prt_tagx; + + pip_prt_tagx.u64 = + cvmx_read_csr(CVMX_PIP_PRT_TAGX(port)); + + if (receive_group_order) { + int tag_mask; + + /* We support only 16 groups at the moment, so + * always disable the two additional "hidden" + * tag_mask bits on CN68XX. + */ + if (OCTEON_IS_MODEL(OCTEON_CN68XX)) + pip_prt_tagx.u64 |= 0x3ull << 44; + + tag_mask = ~((1 << receive_group_order) - 1); + pip_prt_tagx.s.grptagbase = 0; + pip_prt_tagx.s.grptagmask = tag_mask; + pip_prt_tagx.s.grptag = 1; + pip_prt_tagx.s.tag_mode = 0; + pip_prt_tagx.s.inc_prt_flag = 1; + pip_prt_tagx.s.ip6_dprt_flag = 1; + pip_prt_tagx.s.ip4_dprt_flag = 1; + pip_prt_tagx.s.ip6_sprt_flag = 1; + pip_prt_tagx.s.ip4_sprt_flag = 1; + pip_prt_tagx.s.ip6_dst_flag = 1; + pip_prt_tagx.s.ip4_dst_flag = 1; + pip_prt_tagx.s.ip6_src_flag = 1; + pip_prt_tagx.s.ip4_src_flag = 1; + pip_prt_tagx.s.grp = 0; + } else { + pip_prt_tagx.s.grptag = 0; + pip_prt_tagx.s.grp = pow_receive_group; + } + + cvmx_write_csr(CVMX_PIP_PRT_TAGX(port), + pip_prt_tagx.u64); + } + } + + cvmx_helper_ipd_and_packet_input_enable(); + + memset(cvm_oct_device, 0, sizeof(cvm_oct_device)); + + /* + * Initialize the FAU used for counting packet buffers that + * need to be freed. + */ + cvmx_fau_atomic_write32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); + + /* Initialize the FAU used for counting tx SKBs that need to be freed */ + cvmx_fau_atomic_write32(FAU_TOTAL_TX_TO_CLEAN, 0); + + if ((pow_send_group != -1)) { + struct net_device *dev; + + dev = alloc_etherdev(sizeof(struct octeon_ethernet)); + if (dev) { + /* Initialize the device private structure. */ + struct octeon_ethernet *priv = netdev_priv(dev); + + SET_NETDEV_DEV(dev, &pdev->dev); + dev->netdev_ops = &cvm_oct_pow_netdev_ops; + priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED; + priv->port = CVMX_PIP_NUM_INPUT_PORTS; + priv->queue = -1; + strscpy(dev->name, "pow%d", sizeof(dev->name)); + for (qos = 0; qos < 16; qos++) + skb_queue_head_init(&priv->tx_free_list[qos]); + dev->min_mtu = VLAN_ETH_ZLEN - mtu_overhead; + dev->max_mtu = OCTEON_MAX_MTU - mtu_overhead; + + if (register_netdev(dev) < 0) { + pr_err("Failed to register ethernet device for POW\n"); + free_netdev(dev); + } else { + cvm_oct_device[CVMX_PIP_NUM_INPUT_PORTS] = dev; + pr_info("%s: POW send group %d, receive group %d\n", + dev->name, pow_send_group, + pow_receive_group); + } + } else { + pr_err("Failed to allocate ethernet device for POW\n"); + } + } + + num_interfaces = cvmx_helper_get_number_of_interfaces(); + for (interface = 0; interface < num_interfaces; interface++) { + cvmx_helper_interface_mode_t imode = + cvmx_helper_interface_get_mode(interface); + int num_ports = cvmx_helper_ports_on_interface(interface); + int port; + int port_index; + + for (port_index = 0, + port = cvmx_helper_get_ipd_port(interface, 0); + port < cvmx_helper_get_ipd_port(interface, num_ports); + port_index++, port++) { + struct octeon_ethernet *priv; + struct net_device *dev = + alloc_etherdev(sizeof(struct octeon_ethernet)); + if (!dev) { + pr_err("Failed to allocate ethernet device for port %d\n", + port); + continue; + } + + /* Initialize the device private structure. */ + SET_NETDEV_DEV(dev, &pdev->dev); + priv = netdev_priv(dev); + priv->netdev = dev; + priv->of_node = cvm_oct_node_for_port(pip, interface, + port_index); + + INIT_DELAYED_WORK(&priv->port_periodic_work, + cvm_oct_periodic_worker); + priv->imode = imode; + priv->port = port; + priv->queue = cvmx_pko_get_base_queue(priv->port); + priv->fau = fau - cvmx_pko_get_num_queues(port) * 4; + priv->phy_mode = PHY_INTERFACE_MODE_NA; + for (qos = 0; qos < 16; qos++) + skb_queue_head_init(&priv->tx_free_list[qos]); + for (qos = 0; qos < cvmx_pko_get_num_queues(port); + qos++) + cvmx_fau_atomic_write32(priv->fau + qos * 4, 0); + dev->min_mtu = VLAN_ETH_ZLEN - mtu_overhead; + dev->max_mtu = OCTEON_MAX_MTU - mtu_overhead; + + switch (priv->imode) { + /* These types don't support ports to IPD/PKO */ + case CVMX_HELPER_INTERFACE_MODE_DISABLED: + case CVMX_HELPER_INTERFACE_MODE_PCIE: + case CVMX_HELPER_INTERFACE_MODE_PICMG: + break; + + case CVMX_HELPER_INTERFACE_MODE_NPI: + dev->netdev_ops = &cvm_oct_npi_netdev_ops; + strscpy(dev->name, "npi%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_XAUI: + dev->netdev_ops = &cvm_oct_xaui_netdev_ops; + strscpy(dev->name, "xaui%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_LOOP: + dev->netdev_ops = &cvm_oct_npi_netdev_ops; + strscpy(dev->name, "loop%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_SGMII: + priv->phy_mode = PHY_INTERFACE_MODE_SGMII; + dev->netdev_ops = &cvm_oct_sgmii_netdev_ops; + strscpy(dev->name, "eth%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_SPI: + dev->netdev_ops = &cvm_oct_spi_netdev_ops; + strscpy(dev->name, "spi%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_GMII: + priv->phy_mode = PHY_INTERFACE_MODE_GMII; + dev->netdev_ops = &cvm_oct_rgmii_netdev_ops; + strscpy(dev->name, "eth%d", sizeof(dev->name)); + break; + + case CVMX_HELPER_INTERFACE_MODE_RGMII: + dev->netdev_ops = &cvm_oct_rgmii_netdev_ops; + strscpy(dev->name, "eth%d", sizeof(dev->name)); + cvm_set_rgmii_delay(priv, interface, + port_index); + break; + } + + if (!dev->netdev_ops) { + free_netdev(dev); + } else if (register_netdev(dev) < 0) { + pr_err("Failed to register ethernet device for interface %d, port %d\n", + interface, priv->port); + free_netdev(dev); + } else { + cvm_oct_device[priv->port] = dev; + fau -= + cvmx_pko_get_num_queues(priv->port) * + sizeof(u32); + schedule_delayed_work(&priv->port_periodic_work, + HZ); + } + } + } + + cvm_oct_tx_initialize(); + cvm_oct_rx_initialize(); + + /* + * 150 uS: about 10 1500-byte packets at 1GE. + */ + cvm_oct_tx_poll_interval = 150 * (octeon_get_clock_rate() / 1000000); + + schedule_delayed_work(&cvm_oct_rx_refill_work, HZ); + + return 0; +} + +static int cvm_oct_remove(struct platform_device *pdev) +{ + int port; + + cvmx_ipd_disable(); + + atomic_inc_return(&cvm_oct_poll_queue_stopping); + cancel_delayed_work_sync(&cvm_oct_rx_refill_work); + + cvm_oct_rx_shutdown(); + cvm_oct_tx_shutdown(); + + cvmx_pko_disable(); + + /* Free the ethernet devices */ + for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) { + if (cvm_oct_device[port]) { + struct net_device *dev = cvm_oct_device[port]; + struct octeon_ethernet *priv = netdev_priv(dev); + + cancel_delayed_work_sync(&priv->port_periodic_work); + + cvm_oct_tx_shutdown_dev(dev); + unregister_netdev(dev); + free_netdev(dev); + cvm_oct_device[port] = NULL; + } + } + + cvmx_pko_shutdown(); + + cvmx_ipd_free_ptr(); + + /* Free the HW pools */ + cvm_oct_mem_empty_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE, + num_packet_buffers); + cvm_oct_mem_empty_fpa(CVMX_FPA_WQE_POOL, CVMX_FPA_WQE_POOL_SIZE, + num_packet_buffers); + if (CVMX_FPA_OUTPUT_BUFFER_POOL != CVMX_FPA_PACKET_POOL) + cvm_oct_mem_empty_fpa(CVMX_FPA_OUTPUT_BUFFER_POOL, + CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE, 128); + return 0; +} + +static const struct of_device_id cvm_oct_match[] = { + { + .compatible = "cavium,octeon-3860-pip", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, cvm_oct_match); + +static struct platform_driver cvm_oct_driver = { + .probe = cvm_oct_probe, + .remove = cvm_oct_remove, + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = cvm_oct_match, + }, +}; + +module_platform_driver(cvm_oct_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Cavium Networks <support@caviumnetworks.com>"); +MODULE_DESCRIPTION("Cavium Networks Octeon ethernet driver."); diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h new file mode 100644 index 000000000000..a6140705706f --- /dev/null +++ b/drivers/staging/octeon/octeon-ethernet.h @@ -0,0 +1,107 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This file is based on code from OCTEON SDK by Cavium Networks. + * + * Copyright (c) 2003-2010 Cavium Networks + */ + +/* + * External interface for the Cavium Octeon ethernet driver. + */ +#ifndef OCTEON_ETHERNET_H +#define OCTEON_ETHERNET_H + +#include <linux/of.h> +#include <linux/phy.h> + +#ifdef CONFIG_CAVIUM_OCTEON_SOC + +#include <asm/octeon/octeon.h> + +#include <asm/octeon/cvmx-asxx-defs.h> +#include <asm/octeon/cvmx-config.h> +#include <asm/octeon/cvmx-fau.h> +#include <asm/octeon/cvmx-gmxx-defs.h> +#include <asm/octeon/cvmx-helper.h> +#include <asm/octeon/cvmx-helper-util.h> +#include <asm/octeon/cvmx-ipd.h> +#include <asm/octeon/cvmx-ipd-defs.h> +#include <asm/octeon/cvmx-npi-defs.h> +#include <asm/octeon/cvmx-pip.h> +#include <asm/octeon/cvmx-pko.h> +#include <asm/octeon/cvmx-pow.h> +#include <asm/octeon/cvmx-scratch.h> +#include <asm/octeon/cvmx-spi.h> +#include <asm/octeon/cvmx-spxx-defs.h> +#include <asm/octeon/cvmx-stxx-defs.h> +#include <asm/octeon/cvmx-wqe.h> + +#else + +#include "octeon-stubs.h" + +#endif + +/** + * This is the definition of the Ethernet driver's private + * driver state stored in netdev_priv(dev). + */ +struct octeon_ethernet { + /* PKO hardware output port */ + int port; + /* PKO hardware queue for the port */ + int queue; + /* Hardware fetch and add to count outstanding tx buffers */ + int fau; + /* My netdev. */ + struct net_device *netdev; + /* + * Type of port. This is one of the enums in + * cvmx_helper_interface_mode_t + */ + int imode; + /* PHY mode */ + phy_interface_t phy_mode; + /* List of outstanding tx buffers per queue */ + struct sk_buff_head tx_free_list[16]; + unsigned int last_speed; + unsigned int last_link; + /* Last negotiated link state */ + u64 link_info; + /* Called periodically to check link status */ + void (*poll)(struct net_device *dev); + struct delayed_work port_periodic_work; + struct device_node *of_node; +}; + +int cvm_oct_free_work(void *work_queue_entry); + +int cvm_oct_rgmii_open(struct net_device *dev); + +int cvm_oct_sgmii_init(struct net_device *dev); +int cvm_oct_sgmii_open(struct net_device *dev); + +int cvm_oct_spi_init(struct net_device *dev); +void cvm_oct_spi_uninit(struct net_device *dev); + +int cvm_oct_common_init(struct net_device *dev); +void cvm_oct_common_uninit(struct net_device *dev); +void cvm_oct_adjust_link(struct net_device *dev); +int cvm_oct_common_stop(struct net_device *dev); +int cvm_oct_common_open(struct net_device *dev, + void (*link_poll)(struct net_device *)); +void cvm_oct_note_carrier(struct octeon_ethernet *priv, + union cvmx_helper_link_info li); +void cvm_oct_link_poll(struct net_device *dev); + +extern int always_use_pow; +extern int pow_send_group; +extern int pow_receive_groups; +extern char pow_send_list[]; +extern struct net_device *cvm_oct_device[]; +extern atomic_t cvm_oct_poll_queue_stopping; +extern u64 cvm_oct_tx_poll_interval; + +extern int rx_napi_weight; + +#endif diff --git a/drivers/staging/octeon/octeon-stubs.h b/drivers/staging/octeon/octeon-stubs.h new file mode 100644 index 000000000000..d06743504f2b --- /dev/null +++ b/drivers/staging/octeon/octeon-stubs.h @@ -0,0 +1,1434 @@ +#define CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE 512 + +#ifndef XKPHYS_TO_PHYS +# define XKPHYS_TO_PHYS(p) (p) +#endif + +#define OCTEON_IRQ_WORKQ0 0 +#define OCTEON_IRQ_RML 0 +#define OCTEON_IRQ_TIMER1 0 +#define OCTEON_IS_MODEL(x) 0 +#define octeon_has_feature(x) 0 +#define octeon_get_clock_rate() 0 + +#define CVMX_SYNCIOBDMA do { } while (0) + +#define CVMX_HELPER_INPUT_TAG_TYPE 0 +#define CVMX_HELPER_FIRST_MBUFF_SKIP 7 +#define CVMX_FAU_REG_END (2048) +#define CVMX_FPA_OUTPUT_BUFFER_POOL (2) +#define CVMX_FPA_OUTPUT_BUFFER_POOL_SIZE 16 +#define CVMX_FPA_PACKET_POOL (0) +#define CVMX_FPA_PACKET_POOL_SIZE 16 +#define CVMX_FPA_WQE_POOL (1) +#define CVMX_FPA_WQE_POOL_SIZE 16 +#define CVMX_GMXX_RXX_ADR_CAM_EN(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CTL(a, b) ((a) + (b)) +#define CVMX_GMXX_PRTX_CFG(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_FRM_MAX(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_JABBER(a, b) ((a) + (b)) +#define CVMX_IPD_CTL_STATUS 0 +#define CVMX_PIP_FRM_LEN_CHKX(a) (a) +#define CVMX_PIP_NUM_INPUT_PORTS 1 +#define CVMX_SCR_SCRATCH 0 +#define CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 2 +#define CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 2 +#define CVMX_IPD_SUB_PORT_FCS 0 +#define CVMX_SSO_WQ_IQ_DIS 0 +#define CVMX_SSO_WQ_INT 0 +#define CVMX_POW_WQ_INT 0 +#define CVMX_SSO_WQ_INT_PC 0 +#define CVMX_NPI_RSL_INT_BLOCKS 0 +#define CVMX_POW_WQ_INT_PC 0 + +union cvmx_pip_wqe_word2 { + uint64_t u64; + struct { + uint64_t bufs:8; + uint64_t ip_offset:8; + uint64_t vlan_valid:1; + uint64_t vlan_stacked:1; + uint64_t unassigned:1; + uint64_t vlan_cfi:1; + uint64_t vlan_id:12; + uint64_t pr:4; + uint64_t unassigned2:8; + uint64_t dec_ipcomp:1; + uint64_t tcp_or_udp:1; + uint64_t dec_ipsec:1; + uint64_t is_v6:1; + uint64_t software:1; + uint64_t L4_error:1; + uint64_t is_frag:1; + uint64_t IP_exc:1; + uint64_t is_bcast:1; + uint64_t is_mcast:1; + uint64_t not_IP:1; + uint64_t rcv_error:1; + uint64_t err_code:8; + } s; + struct { + uint64_t bufs:8; + uint64_t ip_offset:8; + uint64_t vlan_valid:1; + uint64_t vlan_stacked:1; + uint64_t unassigned:1; + uint64_t vlan_cfi:1; + uint64_t vlan_id:12; + uint64_t port:12; + uint64_t dec_ipcomp:1; + uint64_t tcp_or_udp:1; + uint64_t dec_ipsec:1; + uint64_t is_v6:1; + uint64_t software:1; + uint64_t L4_error:1; + uint64_t is_frag:1; + uint64_t IP_exc:1; + uint64_t is_bcast:1; + uint64_t is_mcast:1; + uint64_t not_IP:1; + uint64_t rcv_error:1; + uint64_t err_code:8; + } s_cn68xx; + + struct { + uint64_t unused1:16; + uint64_t vlan:16; + uint64_t unused2:32; + } svlan; + struct { + uint64_t bufs:8; + uint64_t unused:8; + uint64_t vlan_valid:1; + uint64_t vlan_stacked:1; + uint64_t unassigned:1; + uint64_t vlan_cfi:1; + uint64_t vlan_id:12; + uint64_t pr:4; + uint64_t unassigned2:12; + uint64_t software:1; + uint64_t unassigned3:1; + uint64_t is_rarp:1; + uint64_t is_arp:1; + uint64_t is_bcast:1; + uint64_t is_mcast:1; + uint64_t not_IP:1; + uint64_t rcv_error:1; + uint64_t err_code:8; + } snoip; + +}; + +union cvmx_pip_wqe_word0 { + struct { + uint64_t next_ptr:40; + uint8_t unused; + __wsum hw_chksum; + } cn38xx; + struct { + uint64_t pknd:6; /* 0..5 */ + uint64_t unused2:2; /* 6..7 */ + uint64_t bpid:6; /* 8..13 */ + uint64_t unused1:18; /* 14..31 */ + uint64_t l2ptr:8; /* 32..39 */ + uint64_t l3ptr:8; /* 40..47 */ + uint64_t unused0:8; /* 48..55 */ + uint64_t l4ptr:8; /* 56..63 */ + } cn68xx; +}; + +union cvmx_wqe_word0 { + uint64_t u64; + union cvmx_pip_wqe_word0 pip; +}; + +union cvmx_wqe_word1 { + uint64_t u64; + struct { + uint64_t tag:32; + uint64_t tag_type:2; + uint64_t varies:14; + uint64_t len:16; + }; + struct { + uint64_t tag:32; + uint64_t tag_type:2; + uint64_t zero_2:3; + uint64_t grp:6; + uint64_t zero_1:1; + uint64_t qos:3; + uint64_t zero_0:1; + uint64_t len:16; + } cn68xx; + struct { + uint64_t tag:32; + uint64_t tag_type:2; + uint64_t zero_2:1; + uint64_t grp:4; + uint64_t qos:3; + uint64_t ipprt:6; + uint64_t len:16; + } cn38xx; +}; + +union cvmx_buf_ptr { + void *ptr; + uint64_t u64; + struct { + uint64_t i:1; + uint64_t back:4; + uint64_t pool:3; + uint64_t size:16; + uint64_t addr:40; + } s; +}; + +struct cvmx_wqe { + union cvmx_wqe_word0 word0; + union cvmx_wqe_word1 word1; + union cvmx_pip_wqe_word2 word2; + union cvmx_buf_ptr packet_ptr; + uint8_t packet_data[96]; +}; + +union cvmx_helper_link_info { + uint64_t u64; + struct { + uint64_t reserved_20_63:44; + uint64_t link_up:1; /**< Is the physical link up? */ + uint64_t full_duplex:1; /**< 1 if the link is full duplex */ + uint64_t speed:18; /**< Speed of the link in Mbps */ + } s; +}; + +enum cvmx_fau_reg_32 { + CVMX_FAU_REG_32_START = 0, +}; + +enum cvmx_fau_op_size { + CVMX_FAU_OP_SIZE_8 = 0, + CVMX_FAU_OP_SIZE_16 = 1, + CVMX_FAU_OP_SIZE_32 = 2, + CVMX_FAU_OP_SIZE_64 = 3 +}; + +typedef enum { + CVMX_SPI_MODE_UNKNOWN = 0, + CVMX_SPI_MODE_TX_HALFPLEX = 1, + CVMX_SPI_MODE_RX_HALFPLEX = 2, + CVMX_SPI_MODE_DUPLEX = 3 +} cvmx_spi_mode_t; + +typedef enum { + CVMX_HELPER_INTERFACE_MODE_DISABLED, + CVMX_HELPER_INTERFACE_MODE_RGMII, + CVMX_HELPER_INTERFACE_MODE_GMII, + CVMX_HELPER_INTERFACE_MODE_SPI, + CVMX_HELPER_INTERFACE_MODE_PCIE, + CVMX_HELPER_INTERFACE_MODE_XAUI, + CVMX_HELPER_INTERFACE_MODE_SGMII, + CVMX_HELPER_INTERFACE_MODE_PICMG, + CVMX_HELPER_INTERFACE_MODE_NPI, + CVMX_HELPER_INTERFACE_MODE_LOOP, +} cvmx_helper_interface_mode_t; + +typedef enum { + CVMX_POW_WAIT = 1, + CVMX_POW_NO_WAIT = 0, +} cvmx_pow_wait_t; + +typedef enum { + CVMX_PKO_LOCK_NONE = 0, + CVMX_PKO_LOCK_ATOMIC_TAG = 1, + CVMX_PKO_LOCK_CMD_QUEUE = 2, +} cvmx_pko_lock_t; + +typedef enum { + CVMX_PKO_SUCCESS, + CVMX_PKO_INVALID_PORT, + CVMX_PKO_INVALID_QUEUE, + CVMX_PKO_INVALID_PRIORITY, + CVMX_PKO_NO_MEMORY, + CVMX_PKO_PORT_ALREADY_SETUP, + CVMX_PKO_CMD_QUEUE_INIT_ERROR +} cvmx_pko_status_t; + +enum cvmx_pow_tag_type { + CVMX_POW_TAG_TYPE_ORDERED = 0L, + CVMX_POW_TAG_TYPE_ATOMIC = 1L, + CVMX_POW_TAG_TYPE_NULL = 2L, + CVMX_POW_TAG_TYPE_NULL_NULL = 3L +}; + +union cvmx_ipd_ctl_status { + uint64_t u64; + struct cvmx_ipd_ctl_status_s { + uint64_t reserved_18_63:46; + uint64_t use_sop:1; + uint64_t rst_done:1; + uint64_t clken:1; + uint64_t no_wptr:1; + uint64_t pq_apkt:1; + uint64_t pq_nabuf:1; + uint64_t ipd_full:1; + uint64_t pkt_off:1; + uint64_t len_m8:1; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } s; + struct cvmx_ipd_ctl_status_cn30xx { + uint64_t reserved_10_63:54; + uint64_t len_m8:1; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } cn30xx; + struct cvmx_ipd_ctl_status_cn38xxp2 { + uint64_t reserved_9_63:55; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } cn38xxp2; + struct cvmx_ipd_ctl_status_cn50xx { + uint64_t reserved_15_63:49; + uint64_t no_wptr:1; + uint64_t pq_apkt:1; + uint64_t pq_nabuf:1; + uint64_t ipd_full:1; + uint64_t pkt_off:1; + uint64_t len_m8:1; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } cn50xx; + struct cvmx_ipd_ctl_status_cn58xx { + uint64_t reserved_12_63:52; + uint64_t ipd_full:1; + uint64_t pkt_off:1; + uint64_t len_m8:1; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } cn58xx; + struct cvmx_ipd_ctl_status_cn63xxp1 { + uint64_t reserved_16_63:48; + uint64_t clken:1; + uint64_t no_wptr:1; + uint64_t pq_apkt:1; + uint64_t pq_nabuf:1; + uint64_t ipd_full:1; + uint64_t pkt_off:1; + uint64_t len_m8:1; + uint64_t reset:1; + uint64_t addpkt:1; + uint64_t naddbuf:1; + uint64_t pkt_lend:1; + uint64_t wqe_lend:1; + uint64_t pbp_en:1; + uint64_t opc_mode:2; + uint64_t ipd_en:1; + } cn63xxp1; +}; + +union cvmx_ipd_sub_port_fcs { + uint64_t u64; + struct cvmx_ipd_sub_port_fcs_s { + uint64_t port_bit:32; + uint64_t reserved_32_35:4; + uint64_t port_bit2:4; + uint64_t reserved_40_63:24; + } s; + struct cvmx_ipd_sub_port_fcs_cn30xx { + uint64_t port_bit:3; + uint64_t reserved_3_63:61; + } cn30xx; + struct cvmx_ipd_sub_port_fcs_cn38xx { + uint64_t port_bit:32; + uint64_t reserved_32_63:32; + } cn38xx; +}; + +union cvmx_ipd_sub_port_qos_cnt { + uint64_t u64; + struct cvmx_ipd_sub_port_qos_cnt_s { + uint64_t cnt:32; + uint64_t port_qos:9; + uint64_t reserved_41_63:23; + } s; +}; + +typedef struct { + uint32_t dropped_octets; + uint32_t dropped_packets; + uint32_t pci_raw_packets; + uint32_t octets; + uint32_t packets; + uint32_t multicast_packets; + uint32_t broadcast_packets; + uint32_t len_64_packets; + uint32_t len_65_127_packets; + uint32_t len_128_255_packets; + uint32_t len_256_511_packets; + uint32_t len_512_1023_packets; + uint32_t len_1024_1518_packets; + uint32_t len_1519_max_packets; + uint32_t fcs_align_err_packets; + uint32_t runt_packets; + uint32_t runt_crc_packets; + uint32_t oversize_packets; + uint32_t oversize_crc_packets; + uint32_t inb_packets; + uint64_t inb_octets; + uint16_t inb_errors; +} cvmx_pip_port_status_t; + +typedef struct { + uint32_t packets; + uint64_t octets; + uint64_t doorbell; +} cvmx_pko_port_status_t; + +union cvmx_pip_frm_len_chkx { + uint64_t u64; + struct cvmx_pip_frm_len_chkx_s { + uint64_t reserved_32_63:32; + uint64_t maxlen:16; + uint64_t minlen:16; + } s; +}; + +union cvmx_gmxx_rxx_frm_ctl { + uint64_t u64; + struct cvmx_gmxx_rxx_frm_ctl_s { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t vlan_len:1; + uint64_t pad_len:1; + uint64_t pre_align:1; + uint64_t null_dis:1; + uint64_t reserved_11_11:1; + uint64_t ptp_mode:1; + uint64_t reserved_13_63:51; + } s; + struct cvmx_gmxx_rxx_frm_ctl_cn30xx { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t vlan_len:1; + uint64_t pad_len:1; + uint64_t reserved_9_63:55; + } cn30xx; + struct cvmx_gmxx_rxx_frm_ctl_cn31xx { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t vlan_len:1; + uint64_t reserved_8_63:56; + } cn31xx; + struct cvmx_gmxx_rxx_frm_ctl_cn50xx { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t reserved_7_8:2; + uint64_t pre_align:1; + uint64_t null_dis:1; + uint64_t reserved_11_63:53; + } cn50xx; + struct cvmx_gmxx_rxx_frm_ctl_cn56xxp1 { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t reserved_7_8:2; + uint64_t pre_align:1; + uint64_t reserved_10_63:54; + } cn56xxp1; + struct cvmx_gmxx_rxx_frm_ctl_cn58xx { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t vlan_len:1; + uint64_t pad_len:1; + uint64_t pre_align:1; + uint64_t null_dis:1; + uint64_t reserved_11_63:53; + } cn58xx; + struct cvmx_gmxx_rxx_frm_ctl_cn61xx { + uint64_t pre_chk:1; + uint64_t pre_strp:1; + uint64_t ctl_drp:1; + uint64_t ctl_bck:1; + uint64_t ctl_mcst:1; + uint64_t ctl_smac:1; + uint64_t pre_free:1; + uint64_t reserved_7_8:2; + uint64_t pre_align:1; + uint64_t null_dis:1; + uint64_t reserved_11_11:1; + uint64_t ptp_mode:1; + uint64_t reserved_13_63:51; + } cn61xx; +}; + +union cvmx_gmxx_rxx_int_reg { + uint64_t u64; + struct cvmx_gmxx_rxx_int_reg_s { + uint64_t minerr:1; + uint64_t carext:1; + uint64_t maxerr:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t alnerr:1; + uint64_t lenerr:1; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t niberr:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t phy_link:1; + uint64_t phy_spd:1; + uint64_t phy_dupx:1; + uint64_t pause_drp:1; + uint64_t loc_fault:1; + uint64_t rem_fault:1; + uint64_t bad_seq:1; + uint64_t bad_term:1; + uint64_t unsop:1; + uint64_t uneop:1; + uint64_t undat:1; + uint64_t hg2fld:1; + uint64_t hg2cc:1; + uint64_t reserved_29_63:35; + } s; + struct cvmx_gmxx_rxx_int_reg_cn30xx { + uint64_t minerr:1; + uint64_t carext:1; + uint64_t maxerr:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t alnerr:1; + uint64_t lenerr:1; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t niberr:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t phy_link:1; + uint64_t phy_spd:1; + uint64_t phy_dupx:1; + uint64_t reserved_19_63:45; + } cn30xx; + struct cvmx_gmxx_rxx_int_reg_cn50xx { + uint64_t reserved_0_0:1; + uint64_t carext:1; + uint64_t reserved_2_2:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t alnerr:1; + uint64_t reserved_6_6:1; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t niberr:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t phy_link:1; + uint64_t phy_spd:1; + uint64_t phy_dupx:1; + uint64_t pause_drp:1; + uint64_t reserved_20_63:44; + } cn50xx; + struct cvmx_gmxx_rxx_int_reg_cn52xx { + uint64_t reserved_0_0:1; + uint64_t carext:1; + uint64_t reserved_2_2:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t reserved_5_6:2; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t reserved_9_9:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t reserved_16_18:3; + uint64_t pause_drp:1; + uint64_t loc_fault:1; + uint64_t rem_fault:1; + uint64_t bad_seq:1; + uint64_t bad_term:1; + uint64_t unsop:1; + uint64_t uneop:1; + uint64_t undat:1; + uint64_t hg2fld:1; + uint64_t hg2cc:1; + uint64_t reserved_29_63:35; + } cn52xx; + struct cvmx_gmxx_rxx_int_reg_cn56xxp1 { + uint64_t reserved_0_0:1; + uint64_t carext:1; + uint64_t reserved_2_2:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t reserved_5_6:2; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t reserved_9_9:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t reserved_16_18:3; + uint64_t pause_drp:1; + uint64_t loc_fault:1; + uint64_t rem_fault:1; + uint64_t bad_seq:1; + uint64_t bad_term:1; + uint64_t unsop:1; + uint64_t uneop:1; + uint64_t undat:1; + uint64_t reserved_27_63:37; + } cn56xxp1; + struct cvmx_gmxx_rxx_int_reg_cn58xx { + uint64_t minerr:1; + uint64_t carext:1; + uint64_t maxerr:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t alnerr:1; + uint64_t lenerr:1; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t niberr:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t phy_link:1; + uint64_t phy_spd:1; + uint64_t phy_dupx:1; + uint64_t pause_drp:1; + uint64_t reserved_20_63:44; + } cn58xx; + struct cvmx_gmxx_rxx_int_reg_cn61xx { + uint64_t minerr:1; + uint64_t carext:1; + uint64_t reserved_2_2:1; + uint64_t jabber:1; + uint64_t fcserr:1; + uint64_t reserved_5_6:2; + uint64_t rcverr:1; + uint64_t skperr:1; + uint64_t reserved_9_9:1; + uint64_t ovrerr:1; + uint64_t pcterr:1; + uint64_t rsverr:1; + uint64_t falerr:1; + uint64_t coldet:1; + uint64_t ifgerr:1; + uint64_t reserved_16_18:3; + uint64_t pause_drp:1; + uint64_t loc_fault:1; + uint64_t rem_fault:1; + uint64_t bad_seq:1; + uint64_t bad_term:1; + uint64_t unsop:1; + uint64_t uneop:1; + uint64_t undat:1; + uint64_t hg2fld:1; + uint64_t hg2cc:1; + uint64_t reserved_29_63:35; + } cn61xx; +}; + +union cvmx_gmxx_prtx_cfg { + uint64_t u64; + struct cvmx_gmxx_prtx_cfg_s { + uint64_t reserved_22_63:42; + uint64_t pknd:6; + uint64_t reserved_14_15:2; + uint64_t tx_idle:1; + uint64_t rx_idle:1; + uint64_t reserved_9_11:3; + uint64_t speed_msb:1; + uint64_t reserved_4_7:4; + uint64_t slottime:1; + uint64_t duplex:1; + uint64_t speed:1; + uint64_t en:1; + } s; + struct cvmx_gmxx_prtx_cfg_cn30xx { + uint64_t reserved_4_63:60; + uint64_t slottime:1; + uint64_t duplex:1; + uint64_t speed:1; + uint64_t en:1; + } cn30xx; + struct cvmx_gmxx_prtx_cfg_cn52xx { + uint64_t reserved_14_63:50; + uint64_t tx_idle:1; + uint64_t rx_idle:1; + uint64_t reserved_9_11:3; + uint64_t speed_msb:1; + uint64_t reserved_4_7:4; + uint64_t slottime:1; + uint64_t duplex:1; + uint64_t speed:1; + uint64_t en:1; + } cn52xx; +}; + +union cvmx_gmxx_rxx_adr_ctl { + uint64_t u64; + struct cvmx_gmxx_rxx_adr_ctl_s { + uint64_t reserved_4_63:60; + uint64_t cam_mode:1; + uint64_t mcst:2; + uint64_t bcst:1; + } s; +}; + +union cvmx_pip_prt_tagx { + uint64_t u64; + struct cvmx_pip_prt_tagx_s { + uint64_t reserved_54_63:10; + uint64_t portadd_en:1; + uint64_t inc_hwchk:1; + uint64_t reserved_50_51:2; + uint64_t grptagbase_msb:2; + uint64_t reserved_46_47:2; + uint64_t grptagmask_msb:2; + uint64_t reserved_42_43:2; + uint64_t grp_msb:2; + uint64_t grptagbase:4; + uint64_t grptagmask:4; + uint64_t grptag:1; + uint64_t grptag_mskip:1; + uint64_t tag_mode:2; + uint64_t inc_vs:2; + uint64_t inc_vlan:1; + uint64_t inc_prt_flag:1; + uint64_t ip6_dprt_flag:1; + uint64_t ip4_dprt_flag:1; + uint64_t ip6_sprt_flag:1; + uint64_t ip4_sprt_flag:1; + uint64_t ip6_nxth_flag:1; + uint64_t ip4_pctl_flag:1; + uint64_t ip6_dst_flag:1; + uint64_t ip4_dst_flag:1; + uint64_t ip6_src_flag:1; + uint64_t ip4_src_flag:1; + uint64_t tcp6_tag_type:2; + uint64_t tcp4_tag_type:2; + uint64_t ip6_tag_type:2; + uint64_t ip4_tag_type:2; + uint64_t non_tag_type:2; + uint64_t grp:4; + } s; + struct cvmx_pip_prt_tagx_cn30xx { + uint64_t reserved_40_63:24; + uint64_t grptagbase:4; + uint64_t grptagmask:4; + uint64_t grptag:1; + uint64_t reserved_30_30:1; + uint64_t tag_mode:2; + uint64_t inc_vs:2; + uint64_t inc_vlan:1; + uint64_t inc_prt_flag:1; + uint64_t ip6_dprt_flag:1; + uint64_t ip4_dprt_flag:1; + uint64_t ip6_sprt_flag:1; + uint64_t ip4_sprt_flag:1; + uint64_t ip6_nxth_flag:1; + uint64_t ip4_pctl_flag:1; + uint64_t ip6_dst_flag:1; + uint64_t ip4_dst_flag:1; + uint64_t ip6_src_flag:1; + uint64_t ip4_src_flag:1; + uint64_t tcp6_tag_type:2; + uint64_t tcp4_tag_type:2; + uint64_t ip6_tag_type:2; + uint64_t ip4_tag_type:2; + uint64_t non_tag_type:2; + uint64_t grp:4; + } cn30xx; + struct cvmx_pip_prt_tagx_cn50xx { + uint64_t reserved_40_63:24; + uint64_t grptagbase:4; + uint64_t grptagmask:4; + uint64_t grptag:1; + uint64_t grptag_mskip:1; + uint64_t tag_mode:2; + uint64_t inc_vs:2; + uint64_t inc_vlan:1; + uint64_t inc_prt_flag:1; + uint64_t ip6_dprt_flag:1; + uint64_t ip4_dprt_flag:1; + uint64_t ip6_sprt_flag:1; + uint64_t ip4_sprt_flag:1; + uint64_t ip6_nxth_flag:1; + uint64_t ip4_pctl_flag:1; + uint64_t ip6_dst_flag:1; + uint64_t ip4_dst_flag:1; + uint64_t ip6_src_flag:1; + uint64_t ip4_src_flag:1; + uint64_t tcp6_tag_type:2; + uint64_t tcp4_tag_type:2; + uint64_t ip6_tag_type:2; + uint64_t ip4_tag_type:2; + uint64_t non_tag_type:2; + uint64_t grp:4; + } cn50xx; +}; + +union cvmx_spxx_int_reg { + uint64_t u64; + struct cvmx_spxx_int_reg_s { + uint64_t reserved_32_63:32; + uint64_t spf:1; + uint64_t reserved_12_30:19; + uint64_t calerr:1; + uint64_t syncerr:1; + uint64_t diperr:1; + uint64_t tpaovr:1; + uint64_t rsverr:1; + uint64_t drwnng:1; + uint64_t clserr:1; + uint64_t spiovr:1; + uint64_t reserved_2_3:2; + uint64_t abnorm:1; + uint64_t prtnxa:1; + } s; +}; + +union cvmx_spxx_int_msk { + uint64_t u64; + struct cvmx_spxx_int_msk_s { + uint64_t reserved_12_63:52; + uint64_t calerr:1; + uint64_t syncerr:1; + uint64_t diperr:1; + uint64_t tpaovr:1; + uint64_t rsverr:1; + uint64_t drwnng:1; + uint64_t clserr:1; + uint64_t spiovr:1; + uint64_t reserved_2_3:2; + uint64_t abnorm:1; + uint64_t prtnxa:1; + } s; +}; + +union cvmx_pow_wq_int { + uint64_t u64; + struct cvmx_pow_wq_int_s { + uint64_t wq_int:16; + uint64_t iq_dis:16; + uint64_t reserved_32_63:32; + } s; +}; + +union cvmx_sso_wq_int_thrx { + uint64_t u64; + struct { + uint64_t iq_thr:12; + uint64_t reserved_12_13:2; + uint64_t ds_thr:12; + uint64_t reserved_26_27:2; + uint64_t tc_thr:4; + uint64_t tc_en:1; + uint64_t reserved_33_63:31; + } s; +}; + +union cvmx_stxx_int_reg { + uint64_t u64; + struct cvmx_stxx_int_reg_s { + uint64_t reserved_9_63:55; + uint64_t syncerr:1; + uint64_t frmerr:1; + uint64_t unxfrm:1; + uint64_t nosync:1; + uint64_t diperr:1; + uint64_t datovr:1; + uint64_t ovrbst:1; + uint64_t calpar1:1; + uint64_t calpar0:1; + } s; +}; + +union cvmx_stxx_int_msk { + uint64_t u64; + struct cvmx_stxx_int_msk_s { + uint64_t reserved_8_63:56; + uint64_t frmerr:1; + uint64_t unxfrm:1; + uint64_t nosync:1; + uint64_t diperr:1; + uint64_t datovr:1; + uint64_t ovrbst:1; + uint64_t calpar1:1; + uint64_t calpar0:1; + } s; +}; + +union cvmx_pow_wq_int_pc { + uint64_t u64; + struct cvmx_pow_wq_int_pc_s { + uint64_t reserved_0_7:8; + uint64_t pc_thr:20; + uint64_t reserved_28_31:4; + uint64_t pc:28; + uint64_t reserved_60_63:4; + } s; +}; + +union cvmx_pow_wq_int_thrx { + uint64_t u64; + struct cvmx_pow_wq_int_thrx_s { + uint64_t reserved_29_63:35; + uint64_t tc_en:1; + uint64_t tc_thr:4; + uint64_t reserved_23_23:1; + uint64_t ds_thr:11; + uint64_t reserved_11_11:1; + uint64_t iq_thr:11; + } s; + struct cvmx_pow_wq_int_thrx_cn30xx { + uint64_t reserved_29_63:35; + uint64_t tc_en:1; + uint64_t tc_thr:4; + uint64_t reserved_18_23:6; + uint64_t ds_thr:6; + uint64_t reserved_6_11:6; + uint64_t iq_thr:6; + } cn30xx; + struct cvmx_pow_wq_int_thrx_cn31xx { + uint64_t reserved_29_63:35; + uint64_t tc_en:1; + uint64_t tc_thr:4; + uint64_t reserved_20_23:4; + uint64_t ds_thr:8; + uint64_t reserved_8_11:4; + uint64_t iq_thr:8; + } cn31xx; + struct cvmx_pow_wq_int_thrx_cn52xx { + uint64_t reserved_29_63:35; + uint64_t tc_en:1; + uint64_t tc_thr:4; + uint64_t reserved_21_23:3; + uint64_t ds_thr:9; + uint64_t reserved_9_11:3; + uint64_t iq_thr:9; + } cn52xx; + struct cvmx_pow_wq_int_thrx_cn63xx { + uint64_t reserved_29_63:35; + uint64_t tc_en:1; + uint64_t tc_thr:4; + uint64_t reserved_22_23:2; + uint64_t ds_thr:10; + uint64_t reserved_10_11:2; + uint64_t iq_thr:10; + } cn63xx; +}; + +union cvmx_npi_rsl_int_blocks { + uint64_t u64; + struct cvmx_npi_rsl_int_blocks_s { + uint64_t reserved_32_63:32; + uint64_t rint_31:1; + uint64_t iob:1; + uint64_t reserved_28_29:2; + uint64_t rint_27:1; + uint64_t rint_26:1; + uint64_t rint_25:1; + uint64_t rint_24:1; + uint64_t asx1:1; + uint64_t asx0:1; + uint64_t rint_21:1; + uint64_t pip:1; + uint64_t spx1:1; + uint64_t spx0:1; + uint64_t lmc:1; + uint64_t l2c:1; + uint64_t rint_15:1; + uint64_t reserved_13_14:2; + uint64_t pow:1; + uint64_t tim:1; + uint64_t pko:1; + uint64_t ipd:1; + uint64_t rint_8:1; + uint64_t zip:1; + uint64_t dfa:1; + uint64_t fpa:1; + uint64_t key:1; + uint64_t npi:1; + uint64_t gmx1:1; + uint64_t gmx0:1; + uint64_t mio:1; + } s; + struct cvmx_npi_rsl_int_blocks_cn30xx { + uint64_t reserved_32_63:32; + uint64_t rint_31:1; + uint64_t iob:1; + uint64_t rint_29:1; + uint64_t rint_28:1; + uint64_t rint_27:1; + uint64_t rint_26:1; + uint64_t rint_25:1; + uint64_t rint_24:1; + uint64_t asx1:1; + uint64_t asx0:1; + uint64_t rint_21:1; + uint64_t pip:1; + uint64_t spx1:1; + uint64_t spx0:1; + uint64_t lmc:1; + uint64_t l2c:1; + uint64_t rint_15:1; + uint64_t rint_14:1; + uint64_t usb:1; + uint64_t pow:1; + uint64_t tim:1; + uint64_t pko:1; + uint64_t ipd:1; + uint64_t rint_8:1; + uint64_t zip:1; + uint64_t dfa:1; + uint64_t fpa:1; + uint64_t key:1; + uint64_t npi:1; + uint64_t gmx1:1; + uint64_t gmx0:1; + uint64_t mio:1; + } cn30xx; + struct cvmx_npi_rsl_int_blocks_cn38xx { + uint64_t reserved_32_63:32; + uint64_t rint_31:1; + uint64_t iob:1; + uint64_t rint_29:1; + uint64_t rint_28:1; + uint64_t rint_27:1; + uint64_t rint_26:1; + uint64_t rint_25:1; + uint64_t rint_24:1; + uint64_t asx1:1; + uint64_t asx0:1; + uint64_t rint_21:1; + uint64_t pip:1; + uint64_t spx1:1; + uint64_t spx0:1; + uint64_t lmc:1; + uint64_t l2c:1; + uint64_t rint_15:1; + uint64_t rint_14:1; + uint64_t rint_13:1; + uint64_t pow:1; + uint64_t tim:1; + uint64_t pko:1; + uint64_t ipd:1; + uint64_t rint_8:1; + uint64_t zip:1; + uint64_t dfa:1; + uint64_t fpa:1; + uint64_t key:1; + uint64_t npi:1; + uint64_t gmx1:1; + uint64_t gmx0:1; + uint64_t mio:1; + } cn38xx; + struct cvmx_npi_rsl_int_blocks_cn50xx { + uint64_t reserved_31_63:33; + uint64_t iob:1; + uint64_t lmc1:1; + uint64_t agl:1; + uint64_t reserved_24_27:4; + uint64_t asx1:1; + uint64_t asx0:1; + uint64_t reserved_21_21:1; + uint64_t pip:1; + uint64_t spx1:1; + uint64_t spx0:1; + uint64_t lmc:1; + uint64_t l2c:1; + uint64_t reserved_15_15:1; + uint64_t rad:1; + uint64_t usb:1; + uint64_t pow:1; + uint64_t tim:1; + uint64_t pko:1; + uint64_t ipd:1; + uint64_t reserved_8_8:1; + uint64_t zip:1; + uint64_t dfa:1; + uint64_t fpa:1; + uint64_t key:1; + uint64_t npi:1; + uint64_t gmx1:1; + uint64_t gmx0:1; + uint64_t mio:1; + } cn50xx; +}; + +union cvmx_pko_command_word0 { + uint64_t u64; + struct { + uint64_t total_bytes:16; + uint64_t segs:6; + uint64_t dontfree:1; + uint64_t ignore_i:1; + uint64_t ipoffp1:7; + uint64_t gather:1; + uint64_t rsp:1; + uint64_t wqp:1; + uint64_t n2:1; + uint64_t le:1; + uint64_t reg0:11; + uint64_t subone0:1; + uint64_t reg1:11; + uint64_t subone1:1; + uint64_t size0:2; + uint64_t size1:2; + } s; +}; + +union cvmx_ciu_timx { + uint64_t u64; + struct cvmx_ciu_timx_s { + uint64_t reserved_37_63:27; + uint64_t one_shot:1; + uint64_t len:36; + } s; +}; + +union cvmx_gmxx_rxx_rx_inbnd { + uint64_t u64; + struct cvmx_gmxx_rxx_rx_inbnd_s { + uint64_t status:1; + uint64_t speed:2; + uint64_t duplex:1; + uint64_t reserved_4_63:60; + } s; +}; + +static inline int32_t cvmx_fau_fetch_and_add32(enum cvmx_fau_reg_32 reg, + int32_t value) +{ + return value; +} + +static inline void cvmx_fau_atomic_add32(enum cvmx_fau_reg_32 reg, + int32_t value) +{ } + +static inline void cvmx_fau_atomic_write32(enum cvmx_fau_reg_32 reg, + int32_t value) +{ } + +static inline uint64_t cvmx_scratch_read64(uint64_t address) +{ + return 0; +} + +static inline void cvmx_scratch_write64(uint64_t address, uint64_t value) +{ } + +static inline int cvmx_wqe_get_grp(struct cvmx_wqe *work) +{ + return 0; +} + +static inline void *cvmx_phys_to_ptr(uint64_t physical_address) +{ + return (void *)(uintptr_t)(physical_address); +} + +static inline uint64_t cvmx_ptr_to_phys(void *ptr) +{ + return (unsigned long)ptr; +} + +static inline int cvmx_helper_get_interface_num(int ipd_port) +{ + return ipd_port; +} + +static inline int cvmx_helper_get_interface_index_num(int ipd_port) +{ + return ipd_port; +} + +static inline void cvmx_fpa_enable(void) +{ } + +static inline uint64_t cvmx_read_csr(uint64_t csr_addr) +{ + return 0; +} + +static inline void cvmx_write_csr(uint64_t csr_addr, uint64_t val) +{ } + +static inline int cvmx_helper_setup_red(int pass_thresh, int drop_thresh) +{ + return 0; +} + +static inline void *cvmx_fpa_alloc(uint64_t pool) +{ + return NULL; +} + +static inline void cvmx_fpa_free(void *ptr, uint64_t pool, + uint64_t num_cache_lines) +{ } + +static inline int octeon_is_simulation(void) +{ + return 1; +} + +static inline void cvmx_pip_get_port_status(uint64_t port_num, uint64_t clear, + cvmx_pip_port_status_t *status) +{ } + +static inline void cvmx_pko_get_port_status(uint64_t port_num, uint64_t clear, + cvmx_pko_port_status_t *status) +{ } + +static inline cvmx_helper_interface_mode_t cvmx_helper_interface_get_mode(int + interface) +{ + return 0; +} + +static inline union cvmx_helper_link_info cvmx_helper_link_get(int ipd_port) +{ + union cvmx_helper_link_info ret = { .u64 = 0 }; + + return ret; +} + +static inline int cvmx_helper_link_set(int ipd_port, + union cvmx_helper_link_info link_info) +{ + return 0; +} + +static inline int cvmx_helper_initialize_packet_io_global(void) +{ + return 0; +} + +static inline int cvmx_helper_get_number_of_interfaces(void) +{ + return 2; +} + +static inline int cvmx_helper_ports_on_interface(int interface) +{ + return 1; +} + +static inline int cvmx_helper_get_ipd_port(int interface, int port) +{ + return 0; +} + +static inline int cvmx_helper_ipd_and_packet_input_enable(void) +{ + return 0; +} + +static inline void cvmx_ipd_disable(void) +{ } + +static inline void cvmx_ipd_free_ptr(void) +{ } + +static inline void cvmx_pko_disable(void) +{ } + +static inline void cvmx_pko_shutdown(void) +{ } + +static inline int cvmx_pko_get_base_queue_per_core(int port, int core) +{ + return port; +} + +static inline int cvmx_pko_get_base_queue(int port) +{ + return port; +} + +static inline int cvmx_pko_get_num_queues(int port) +{ + return port; +} + +static inline unsigned int cvmx_get_core_num(void) +{ + return 0; +} + +static inline void cvmx_pow_work_request_async_nocheck(int scr_addr, + cvmx_pow_wait_t wait) +{ } + +static inline void cvmx_pow_work_request_async(int scr_addr, + cvmx_pow_wait_t wait) +{ } + +static inline struct cvmx_wqe *cvmx_pow_work_response_async(int scr_addr) +{ + struct cvmx_wqe *wqe = (void *)(unsigned long)scr_addr; + + return wqe; +} + +static inline struct cvmx_wqe *cvmx_pow_work_request_sync(cvmx_pow_wait_t wait) +{ + return (void *)(unsigned long)wait; +} + +static inline int cvmx_spi_restart_interface(int interface, + cvmx_spi_mode_t mode, int timeout) +{ + return 0; +} + +static inline void cvmx_fau_async_fetch_and_add32(uint64_t scraddr, + enum cvmx_fau_reg_32 reg, + int32_t value) +{ } + +static inline union cvmx_gmxx_rxx_rx_inbnd cvmx_spi4000_check_speed( + int interface, + int port) +{ + union cvmx_gmxx_rxx_rx_inbnd r; + + r.u64 = 0; + return r; +} + +static inline void cvmx_pko_send_packet_prepare(uint64_t port, uint64_t queue, + cvmx_pko_lock_t use_locking) +{ } + +static inline cvmx_pko_status_t cvmx_pko_send_packet_finish(uint64_t port, + uint64_t queue, union cvmx_pko_command_word0 pko_command, + union cvmx_buf_ptr packet, cvmx_pko_lock_t use_locking) +{ + return 0; +} + +static inline void cvmx_wqe_set_port(struct cvmx_wqe *work, int port) +{ } + +static inline void cvmx_wqe_set_qos(struct cvmx_wqe *work, int qos) +{ } + +static inline int cvmx_wqe_get_qos(struct cvmx_wqe *work) +{ + return 0; +} + +static inline void cvmx_wqe_set_grp(struct cvmx_wqe *work, int grp) +{ } + +static inline void cvmx_pow_work_submit(struct cvmx_wqe *wqp, uint32_t tag, + enum cvmx_pow_tag_type tag_type, + uint64_t qos, uint64_t grp) +{ } + +#define CVMX_ASXX_RX_CLK_SETX(a, b) ((a) + (b)) +#define CVMX_ASXX_TX_CLK_SETX(a, b) ((a) + (b)) +#define CVMX_CIU_TIMX(a) (a) +#define CVMX_GMXX_RXX_ADR_CAM0(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CAM1(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CAM2(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CAM3(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CAM4(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_ADR_CAM5(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_FRM_CTL(a, b) ((a) + (b)) +#define CVMX_GMXX_RXX_INT_REG(a, b) ((a) + (b)) +#define CVMX_GMXX_SMACX(a, b) ((a) + (b)) +#define CVMX_PIP_PRT_TAGX(a) (a) +#define CVMX_POW_PP_GRP_MSKX(a) (a) +#define CVMX_POW_WQ_INT_THRX(a) (a) +#define CVMX_SPXX_INT_MSK(a) (a) +#define CVMX_SPXX_INT_REG(a) (a) +#define CVMX_SSO_PPX_GRP_MSK(a) (a) +#define CVMX_SSO_WQ_INT_THRX(a) (a) +#define CVMX_STXX_INT_MSK(a) (a) +#define CVMX_STXX_INT_REG(a) (a) diff --git a/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts b/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts index 61fad96818c2..096137fcd5cc 100644 --- a/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts +++ b/drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dts @@ -3,51 +3,46 @@ /plugin/; / { - compatible = "bcm,bcm2835", "bcm,bcm2708", "bcm,bcm2709"; + compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"; +}; - fragment@0 { - target = <&spi0>; - __overlay__ { - status = "okay"; +&spi0 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; - spidev@0{ - status = "disabled"; - }; + spidev@0{ + reg = <0>; + status = "disabled"; + }; - spidev@1{ - status = "disabled"; - }; - }; + spidev@1{ + reg = <1>; + status = "disabled"; }; +}; - fragment@1 { - target = <&gpio>; - __overlay__ { - pi433_pins: pi433_pins { - brcm,pins = <7 25 24>; - brcm,function = <0 0 0>; // in in in - }; - }; +&gpio { + pi433_pins: pi433_pins { + brcm,pins = <7 25 24>; + brcm,function = <0 0 0>; // in in in }; +}; - fragment@2 { - target = <&spi0>; - __overlay__ { - #address-cells = <1>; - #size-cells = <0>; - status = "okay"; - - pi433: pi433@0 { - compatible = "Smarthome-Wolf,pi433"; - reg = <0>; - spi-max-frequency = <10000000>; - status = "okay"; - - pinctrl-0 = <&pi433_pins>; - DIO0-gpio = <&gpio 24 0>; - DIO1-gpio = <&gpio 25 0>; - DIO2-gpio = <&gpio 7 0>; - }; - }; +&spi0 { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + + pi433: pi433@0 { + compatible = "Smarthome-Wolf,pi433"; + reg = <0>; + spi-max-frequency = <10000000>; + status = "okay"; + + pinctrl-0 = <&pi433_pins>; + DIO0-gpio = <&gpio 24 0>; + DIO1-gpio = <&gpio 25 0>; + DIO2-gpio = <&gpio 7 0>; }; }; diff --git a/drivers/staging/pi433/pi433_if.h b/drivers/staging/pi433/pi433_if.h index 9feb95c431cb..16c5b7fba249 100644 --- a/drivers/staging/pi433/pi433_if.h +++ b/drivers/staging/pi433/pi433_if.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0+ - * +/* SPDX-License-Identifier: GPL-2.0+ */ +/* * include/linux/TODO * * userspace interface for pi433 radio module diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h index d43a8d87d5d3..b648ba5fff89 100644 --- a/drivers/staging/pi433/rf69.h +++ b/drivers/staging/pi433/rf69.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0+ - * +/* SPDX-License-Identifier: GPL-2.0+ */ +/* * hardware abstraction/register access for HopeRf rf69 radio module * * Copyright (C) 2016 Wolf-Entwicklungen diff --git a/drivers/staging/pi433/rf69_enum.h b/drivers/staging/pi433/rf69_enum.h index 3ee1952245c2..fbf56fcf5fe8 100644 --- a/drivers/staging/pi433/rf69_enum.h +++ b/drivers/staging/pi433/rf69_enum.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0+ - * +/* SPDX-License-Identifier: GPL-2.0+ */ +/* * enumerations for HopeRf rf69 radio module * * Copyright (C) 2016 Wolf-Entwicklungen diff --git a/drivers/staging/pi433/rf69_registers.h b/drivers/staging/pi433/rf69_registers.h index be5497cdace0..a170c66c3d5b 100644 --- a/drivers/staging/pi433/rf69_registers.h +++ b/drivers/staging/pi433/rf69_registers.h @@ -1,5 +1,5 @@ -/* SPDX-License-Identifier: GPL-2.0+ - * +/* SPDX-License-Identifier: GPL-2.0+ */ +/* * register description for HopeRf rf69 radio module * * Copyright (C) 2016 Wolf-Entwicklungen diff --git a/drivers/staging/qlge/qlge.h b/drivers/staging/qlge/qlge.h index 4bc5d5fce9bf..fc8c5ca8935d 100644 --- a/drivers/staging/qlge/qlge.h +++ b/drivers/staging/qlge/qlge.h @@ -16,8 +16,8 @@ /* * General definitions... */ -#define DRV_NAME "qlge" -#define DRV_STRING "QLogic 10 Gigabit PCI-E Ethernet Driver " +#define DRV_NAME "qlge" +#define DRV_STRING "QLogic 10 Gigabit PCI-E Ethernet Driver " #define DRV_VERSION "1.00.00.35" #define WQ_ADDR_ALIGN 0x3 /* 4 byte alignment */ @@ -59,7 +59,7 @@ #define MAX_CQ 128 #define DFLT_COALESCE_WAIT 100 /* 100 usec wait for coalescing */ #define MAX_INTER_FRAME_WAIT 10 /* 10 usec max interframe-wait for coalescing */ -#define DFLT_INTER_FRAME_WAIT (MAX_INTER_FRAME_WAIT/2) +#define DFLT_INTER_FRAME_WAIT (MAX_INTER_FRAME_WAIT / 2) #define UDELAY_COUNT 3 #define UDELAY_DELAY 100 @@ -119,7 +119,6 @@ enum { * Processor Address Register (PROC_ADDR) bit definitions. */ enum { - /* Misc. stuff */ MAILBOX_COUNT = 16, MAILBOX_TIMEOUT = 5, @@ -1077,11 +1076,11 @@ struct tx_buf_desc { * IOCB Definitions... */ -#define OPCODE_OB_MAC_IOCB 0x01 +#define OPCODE_OB_MAC_IOCB 0x01 #define OPCODE_OB_MAC_TSO_IOCB 0x02 -#define OPCODE_IB_MAC_IOCB 0x20 -#define OPCODE_IB_MPI_IOCB 0x21 -#define OPCODE_IB_AE_IOCB 0x3f +#define OPCODE_IB_MAC_IOCB 0x20 +#define OPCODE_IB_MPI_IOCB 0x21 +#define OPCODE_IB_AE_IOCB 0x3f struct ob_mac_iocb_req { u8 opcode; @@ -1173,15 +1172,15 @@ struct ib_mac_iocb_rsp { u8 flags1; #define IB_MAC_IOCB_RSP_OI 0x01 /* Override intr delay */ #define IB_MAC_IOCB_RSP_I 0x02 /* Disable Intr Generation */ -#define IB_MAC_CSUM_ERR_MASK 0x1c /* A mask to use for csum errs */ +#define IB_MAC_CSUM_ERR_MASK 0x1c /* A mask to use for csum errs */ #define IB_MAC_IOCB_RSP_TE 0x04 /* Checksum error */ #define IB_MAC_IOCB_RSP_NU 0x08 /* No checksum rcvd */ #define IB_MAC_IOCB_RSP_IE 0x10 /* IPv4 checksum error */ #define IB_MAC_IOCB_RSP_M_MASK 0x60 /* Multicast info */ #define IB_MAC_IOCB_RSP_M_NONE 0x00 /* Not mcast frame */ #define IB_MAC_IOCB_RSP_M_HASH 0x20 /* HASH mcast frame */ -#define IB_MAC_IOCB_RSP_M_REG 0x40 /* Registered mcast frame */ -#define IB_MAC_IOCB_RSP_M_PROM 0x60 /* Promiscuous mcast frame */ +#define IB_MAC_IOCB_RSP_M_REG 0x40 /* Registered mcast frame */ +#define IB_MAC_IOCB_RSP_M_PROM 0x60 /* Promiscuous mcast frame */ #define IB_MAC_IOCB_RSP_B 0x80 /* Broadcast frame */ u8 flags2; #define IB_MAC_IOCB_RSP_P 0x01 /* Promiscuous frame */ @@ -1198,16 +1197,16 @@ struct ib_mac_iocb_rsp { #define IB_MAC_IOCB_RSP_FO 0x80 /* Failover port */ u8 flags3; #define IB_MAC_IOCB_RSP_RSS_MASK 0x07 /* RSS mask */ -#define IB_MAC_IOCB_RSP_M_NONE 0x00 /* No RSS match */ -#define IB_MAC_IOCB_RSP_M_IPV4 0x04 /* IPv4 RSS match */ -#define IB_MAC_IOCB_RSP_M_IPV6 0x02 /* IPv6 RSS match */ -#define IB_MAC_IOCB_RSP_M_TCP_V4 0x05 /* TCP with IPv4 */ -#define IB_MAC_IOCB_RSP_M_TCP_V6 0x03 /* TCP with IPv6 */ -#define IB_MAC_IOCB_RSP_V4 0x08 /* IPV4 */ -#define IB_MAC_IOCB_RSP_V6 0x10 /* IPV6 */ -#define IB_MAC_IOCB_RSP_IH 0x20 /* Split after IP header */ -#define IB_MAC_IOCB_RSP_DS 0x40 /* data is in small buffer */ -#define IB_MAC_IOCB_RSP_DL 0x80 /* data is in large buffer */ +#define IB_MAC_IOCB_RSP_M_NONE 0x00 /* No RSS match */ +#define IB_MAC_IOCB_RSP_M_IPV4 0x04 /* IPv4 RSS match */ +#define IB_MAC_IOCB_RSP_M_IPV6 0x02 /* IPv6 RSS match */ +#define IB_MAC_IOCB_RSP_M_TCP_V4 0x05 /* TCP with IPv4 */ +#define IB_MAC_IOCB_RSP_M_TCP_V6 0x03 /* TCP with IPv6 */ +#define IB_MAC_IOCB_RSP_V4 0x08 /* IPV4 */ +#define IB_MAC_IOCB_RSP_V6 0x10 /* IPV6 */ +#define IB_MAC_IOCB_RSP_IH 0x20 /* Split after IP header */ +#define IB_MAC_IOCB_RSP_DS 0x40 /* data is in small buffer */ +#define IB_MAC_IOCB_RSP_DL 0x80 /* data is in large buffer */ __le32 data_len; /* */ __le64 data_addr; /* */ __le32 rss; /* */ @@ -1233,17 +1232,17 @@ struct ib_ae_iocb_rsp { #define IB_AE_IOCB_RSP_OI 0x01 #define IB_AE_IOCB_RSP_I 0x02 u8 event; -#define LINK_UP_EVENT 0x00 -#define LINK_DOWN_EVENT 0x01 -#define CAM_LOOKUP_ERR_EVENT 0x06 -#define SOFT_ECC_ERROR_EVENT 0x07 -#define MGMT_ERR_EVENT 0x08 -#define TEN_GIG_MAC_EVENT 0x09 -#define GPI0_H2L_EVENT 0x10 -#define GPI0_L2H_EVENT 0x20 -#define GPI1_H2L_EVENT 0x11 -#define GPI1_L2H_EVENT 0x21 -#define PCI_ERR_ANON_BUF_RD 0x40 +#define LINK_UP_EVENT 0x00 +#define LINK_DOWN_EVENT 0x01 +#define CAM_LOOKUP_ERR_EVENT 0x06 +#define SOFT_ECC_ERROR_EVENT 0x07 +#define MGMT_ERR_EVENT 0x08 +#define TEN_GIG_MAC_EVENT 0x09 +#define GPI0_H2L_EVENT 0x10 +#define GPI0_L2H_EVENT 0x20 +#define GPI1_H2L_EVENT 0x11 +#define GPI1_L2H_EVENT 0x21 +#define PCI_ERR_ANON_BUF_RD 0x40 u8 q_id; __le32 reserved[15]; } __packed; @@ -1367,7 +1366,7 @@ struct tx_ring_desc { struct tx_ring_desc *next; }; -#define QL_TXQ_IDX(qdev, skb) (smp_processor_id()%(qdev->tx_ring_count)) +#define QL_TXQ_IDX(qdev, skb) (smp_processor_id() % (qdev->tx_ring_count)) struct tx_ring { /* @@ -1762,7 +1761,6 @@ struct ql_nic_misc { }; struct ql_reg_dump { - /* segment 0 */ struct mpi_coredump_global_header mpi_global_header; @@ -1792,7 +1790,7 @@ struct ql_reg_dump { /* segment 34 */ struct mpi_coredump_segment_header ets_seg_hdr; - u32 ets[8+2]; + u32 ets[8 + 2]; }; struct ql_mpi_coredump { @@ -2059,7 +2057,6 @@ enum { }; struct nic_operations { - int (*get_flash) (struct ql_adapter *); int (*port_initialize) (struct ql_adapter *); }; diff --git a/drivers/staging/qlge/qlge_dbg.c b/drivers/staging/qlge/qlge_dbg.c index 8cf39615c520..1795533cbd3a 100644 --- a/drivers/staging/qlge/qlge_dbg.c +++ b/drivers/staging/qlge/qlge_dbg.c @@ -29,15 +29,13 @@ static int ql_write_other_func_reg(struct ql_adapter *qdev, u32 reg, u32 reg_val) { u32 register_to_read; - int status = 0; register_to_read = MPI_NIC_REG_BLOCK | MPI_NIC_READ | (qdev->alt_func << MPI_NIC_FUNCTION_SHIFT) | reg; - status = ql_write_mpi_reg(qdev, register_to_read, reg_val); - return status; + return ql_write_mpi_reg(qdev, register_to_read, reg_val); } static int ql_wait_other_func_reg_rdy(struct ql_adapter *qdev, u32 reg, @@ -499,6 +497,7 @@ static int ql_get_mpi_regs(struct ql_adapter *qdev, u32 *buf, u32 offset, u32 count) { int i, status = 0; + for (i = 0; i < count; i++, buf++) { status = ql_read_mpi_reg(qdev, offset + i, buf); if (status) @@ -552,7 +551,6 @@ static int ql_get_probe_dump(struct ql_adapter *qdev, unsigned int *buf) buf = ql_get_probe(qdev, PRB_MX_ADDR_FC_CLOCK, PRB_MX_ADDR_VALID_FC_MOD, buf); return 0; - } /* Read out the routing index registers */ @@ -610,7 +608,6 @@ static void ql_get_mac_protocol_registers(struct ql_adapter *qdev, u32 *buf) for (type = 0; type < MAC_ADDR_TYPE_COUNT; type++) { switch (type) { - case 0: /* CAM */ initial_val |= MAC_ADDR_ADR; max_index = MAC_ADDR_MAX_CAM_ENTRIES; @@ -1204,7 +1201,6 @@ int ql_core_dump(struct ql_adapter *qdev, struct ql_mpi_coredump *mpi_coredump) err: ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */ return status; - } static void ql_get_core_dump(struct ql_adapter *qdev) @@ -1324,27 +1320,10 @@ void ql_mpi_core_to_log(struct work_struct *work) { struct ql_adapter *qdev = container_of(work, struct ql_adapter, mpi_core_to_log.work); - u32 *tmp, count; - int i; - count = sizeof(struct ql_mpi_coredump) / sizeof(u32); - tmp = (u32 *)qdev->mpi_coredump; - netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev, - "Core is dumping to log file!\n"); - - for (i = 0; i < count; i += 8) { - pr_err("%.08x: %.08x %.08x %.08x %.08x %.08x " - "%.08x %.08x %.08x\n", i, - tmp[i + 0], - tmp[i + 1], - tmp[i + 2], - tmp[i + 3], - tmp[i + 4], - tmp[i + 5], - tmp[i + 6], - tmp[i + 7]); - msleep(5); - } + print_hex_dump(KERN_DEBUG, "Core is dumping to log file!\n", + DUMP_PREFIX_OFFSET, 32, 4, qdev->mpi_coredump, + sizeof(*qdev->mpi_coredump), false); } #ifdef QL_REG_DUMP @@ -1352,6 +1331,7 @@ static void ql_dump_intr_states(struct ql_adapter *qdev) { int i; u32 value; + for (i = 0; i < qdev->intr_count; i++) { ql_write32(qdev, INTR_EN, qdev->intr_context[i].intr_read_mask); value = ql_read32(qdev, INTR_EN); @@ -1437,6 +1417,7 @@ void ql_dump_routing_entries(struct ql_adapter *qdev) { int i; u32 value; + i = ql_sem_spinlock(qdev, SEM_RT_IDX_MASK); if (i) return; @@ -1525,7 +1506,7 @@ void ql_dump_regs(struct ql_adapter *qdev) #ifdef QL_STAT_DUMP #define DUMP_STAT(qdev, stat) \ - pr_err("%s = %ld\n", #stat, (unsigned long)qdev->nic_stats.stat) + pr_err("%s = %ld\n", #stat, (unsigned long)(qdev)->nic_stats.stat) void ql_dump_stat(struct ql_adapter *qdev) { @@ -1578,15 +1559,16 @@ void ql_dump_stat(struct ql_adapter *qdev) #ifdef QL_DEV_DUMP #define DUMP_QDEV_FIELD(qdev, type, field) \ - pr_err("qdev->%-24s = " type "\n", #field, qdev->field) + pr_err("qdev->%-24s = " type "\n", #field, (qdev)->(field)) #define DUMP_QDEV_DMA_FIELD(qdev, field) \ pr_err("qdev->%-24s = %llx\n", #field, (unsigned long long)qdev->field) #define DUMP_QDEV_ARRAY(qdev, type, array, index, field) \ pr_err("%s[%d].%s = " type "\n", \ - #array, index, #field, qdev->array[index].field); + #array, index, #field, (qdev)->array[index].field); void ql_dump_qdev(struct ql_adapter *qdev) { int i; + DUMP_QDEV_FIELD(qdev, "%lx", flags); DUMP_QDEV_FIELD(qdev, "%p", vlgrp); DUMP_QDEV_FIELD(qdev, "%p", pdev); @@ -1640,9 +1622,9 @@ void ql_dump_wqicb(struct wqicb *wqicb) le16_to_cpu(wqicb->cq_id_rss)); pr_err("wqicb->rid = 0x%x\n", le16_to_cpu(wqicb->rid)); pr_err("wqicb->wq_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(wqicb->addr)); + (unsigned long long)le64_to_cpu(wqicb->addr)); pr_err("wqicb->wq_cnsmr_idx_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(wqicb->cnsmr_idx_addr)); + (unsigned long long)le64_to_cpu(wqicb->cnsmr_idx_addr)); } void ql_dump_tx_ring(struct tx_ring *tx_ring) @@ -1653,7 +1635,7 @@ void ql_dump_tx_ring(struct tx_ring *tx_ring) tx_ring->wq_id); pr_err("tx_ring->base = %p\n", tx_ring->wq_base); pr_err("tx_ring->base_dma = 0x%llx\n", - (unsigned long long) tx_ring->wq_base_dma); + (unsigned long long)tx_ring->wq_base_dma); pr_err("tx_ring->cnsmr_idx_sh_reg, addr = 0x%p, value = %d\n", tx_ring->cnsmr_idx_sh_reg, tx_ring->cnsmr_idx_sh_reg @@ -1672,6 +1654,7 @@ void ql_dump_tx_ring(struct tx_ring *tx_ring) void ql_dump_ricb(struct ricb *ricb) { int i; + pr_err("===================== Dumping ricb ===============\n"); pr_err("Dumping ricb stuff...\n"); @@ -1706,21 +1689,21 @@ void ql_dump_cqicb(struct cqicb *cqicb) pr_err("cqicb->flags = %x\n", cqicb->flags); pr_err("cqicb->len = %d\n", le16_to_cpu(cqicb->len)); pr_err("cqicb->addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(cqicb->addr)); + (unsigned long long)le64_to_cpu(cqicb->addr)); pr_err("cqicb->prod_idx_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(cqicb->prod_idx_addr)); + (unsigned long long)le64_to_cpu(cqicb->prod_idx_addr)); pr_err("cqicb->pkt_delay = 0x%.04x\n", le16_to_cpu(cqicb->pkt_delay)); pr_err("cqicb->irq_delay = 0x%.04x\n", le16_to_cpu(cqicb->irq_delay)); pr_err("cqicb->lbq_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(cqicb->lbq_addr)); + (unsigned long long)le64_to_cpu(cqicb->lbq_addr)); pr_err("cqicb->lbq_buf_size = 0x%.04x\n", le16_to_cpu(cqicb->lbq_buf_size)); pr_err("cqicb->lbq_len = 0x%.04x\n", le16_to_cpu(cqicb->lbq_len)); pr_err("cqicb->sbq_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(cqicb->sbq_addr)); + (unsigned long long)le64_to_cpu(cqicb->sbq_addr)); pr_err("cqicb->sbq_buf_size = 0x%.04x\n", le16_to_cpu(cqicb->sbq_buf_size)); pr_err("cqicb->sbq_len = 0x%.04x\n", @@ -1748,7 +1731,7 @@ void ql_dump_rx_ring(struct rx_ring *rx_ring) pr_err("rx_ring->cqicb = %p\n", &rx_ring->cqicb); pr_err("rx_ring->cq_base = %p\n", rx_ring->cq_base); pr_err("rx_ring->cq_base_dma = %llx\n", - (unsigned long long) rx_ring->cq_base_dma); + (unsigned long long)rx_ring->cq_base_dma); pr_err("rx_ring->cq_size = %d\n", rx_ring->cq_size); pr_err("rx_ring->cq_len = %d\n", rx_ring->cq_len); pr_err("rx_ring->prod_idx_sh_reg, addr = 0x%p, value = %d\n", @@ -1756,7 +1739,7 @@ void ql_dump_rx_ring(struct rx_ring *rx_ring) rx_ring->prod_idx_sh_reg ? ql_read_sh_reg(rx_ring->prod_idx_sh_reg) : 0); pr_err("rx_ring->prod_idx_sh_reg_dma = %llx\n", - (unsigned long long) rx_ring->prod_idx_sh_reg_dma); + (unsigned long long)rx_ring->prod_idx_sh_reg_dma); pr_err("rx_ring->cnsmr_idx_db_reg = %p\n", rx_ring->cnsmr_idx_db_reg); pr_err("rx_ring->cnsmr_idx = %d\n", rx_ring->cnsmr_idx); @@ -1855,7 +1838,6 @@ void ql_dump_tx_desc(struct tx_buf_desc *tbd) pr_err("tbd->flags = %s %s\n", tbd->len & TX_DESC_C ? "C" : ".", tbd->len & TX_DESC_E ? "E" : "."); - } void ql_dump_ob_mac_iocb(struct ob_mac_iocb_req *ob_mac_iocb) @@ -1980,7 +1962,7 @@ void ql_dump_ib_mac_rsp(struct ib_mac_iocb_rsp *ib_mac_rsp) pr_err("data_len = %d\n", le32_to_cpu(ib_mac_rsp->data_len)); pr_err("data_addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(ib_mac_rsp->data_addr)); + (unsigned long long)le64_to_cpu(ib_mac_rsp->data_addr)); if (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_RSS_MASK) pr_err("rss = %x\n", le32_to_cpu(ib_mac_rsp->rss)); @@ -1997,7 +1979,7 @@ void ql_dump_ib_mac_rsp(struct ib_mac_iocb_rsp *ib_mac_rsp) pr_err("hdr length = %d\n", le32_to_cpu(ib_mac_rsp->hdr_len)); pr_err("hdr addr = 0x%llx\n", - (unsigned long long) le64_to_cpu(ib_mac_rsp->hdr_addr)); + (unsigned long long)le64_to_cpu(ib_mac_rsp->hdr_addr)); } } #endif diff --git a/drivers/staging/qlge/qlge_ethtool.c b/drivers/staging/qlge/qlge_ethtool.c index 790997aff995..441ac08d14d2 100644 --- a/drivers/staging/qlge/qlge_ethtool.c +++ b/drivers/staging/qlge/qlge_ethtool.c @@ -259,8 +259,9 @@ static void ql_update_stats(struct ql_adapter *qdev) "Error reading status register 0x%.04x.\n", i); goto end; - } else + } else { *iter = data; + } iter++; } @@ -273,8 +274,9 @@ static void ql_update_stats(struct ql_adapter *qdev) "Error reading status register 0x%.04x.\n", i); goto end; - } else + } else { *iter = data; + } iter++; } @@ -290,8 +292,9 @@ static void ql_update_stats(struct ql_adapter *qdev) "Error reading status register 0x%.04x.\n", i); goto end; - } else + } else { *iter = data; + } iter++; } @@ -304,8 +307,9 @@ static void ql_update_stats(struct ql_adapter *qdev) "Error reading status register 0x%.04x.\n", i); goto end; - } else + } else { *iter = data; + } iter++; } @@ -316,8 +320,9 @@ static void ql_update_stats(struct ql_adapter *qdev) netif_err(qdev, drv, qdev->ndev, "Error reading status register 0x%.04x.\n", i); goto end; - } else + } else { *iter = data; + } end: ql_sem_unlock(qdev, qdev->xg_sem_mask); quit: @@ -488,8 +493,9 @@ static int ql_start_loopback(struct ql_adapter *qdev) if (netif_carrier_ok(qdev->ndev)) { set_bit(QL_LB_LINK_UP, &qdev->flags); netif_carrier_off(qdev->ndev); - } else + } else { clear_bit(QL_LB_LINK_UP, &qdev->flags); + } qdev->link_config |= CFG_LOOPBACK_PCS; return ql_mb_set_port_cfg(qdev); } @@ -686,7 +692,6 @@ static int ql_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct ql_adapter *qdev = netdev_priv(netdev); - int status = 0; if ((pause->rx_pause) && (pause->tx_pause)) qdev->link_config |= CFG_PAUSE_STD; @@ -695,8 +700,7 @@ static int ql_set_pauseparam(struct net_device *netdev, else return -EINVAL; - status = ql_mb_set_port_cfg(qdev); - return status; + return ql_mb_set_port_cfg(qdev); } static u32 ql_get_msglevel(struct net_device *ndev) diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c index ef8037d0b52e..c92820f07968 100644 --- a/drivers/staging/qlge/qlge_main.c +++ b/drivers/staging/qlge/qlge_main.c @@ -52,16 +52,12 @@ MODULE_LICENSE("GPL"); MODULE_VERSION(DRV_VERSION); static const u32 default_msg = - NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | -/* NETIF_MSG_TIMER | */ - NETIF_MSG_IFDOWN | - NETIF_MSG_IFUP | - NETIF_MSG_RX_ERR | - NETIF_MSG_TX_ERR | -/* NETIF_MSG_TX_QUEUED | */ -/* NETIF_MSG_INTR | NETIF_MSG_TX_DONE | NETIF_MSG_RX_STATUS | */ -/* NETIF_MSG_PKTDATA | */ - NETIF_MSG_HW | NETIF_MSG_WOL | 0; + NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | + NETIF_MSG_IFDOWN | + NETIF_MSG_IFUP | + NETIF_MSG_RX_ERR | + NETIF_MSG_TX_ERR | + NETIF_MSG_HW | NETIF_MSG_WOL | 0; static int debug = -1; /* defaults above */ module_param(debug, int, 0664); @@ -143,6 +139,7 @@ static int ql_sem_trylock(struct ql_adapter *qdev, u32 sem_mask) int ql_sem_spinlock(struct ql_adapter *qdev, u32 sem_mask) { unsigned int wait_count = 30; + do { if (!ql_sem_trylock(qdev, sem_mask)) return 0; @@ -1210,6 +1207,7 @@ static void ql_unmap_send(struct ql_adapter *qdev, struct tx_ring_desc *tx_ring_desc, int mapped) { int i; + for (i = 0; i < mapped; i++) { if (i == 0 || (i == 7 && mapped > 7)) { /* @@ -1290,6 +1288,7 @@ static int ql_map_send(struct ql_adapter *qdev, */ for (frag_idx = 0; frag_idx < frag_cnt; frag_idx++, map_idx++) { skb_frag_t *frag = &skb_shinfo(skb)->frags[frag_idx]; + tbd++; if (frag_idx == 6 && frag_cnt > 7) { /* Let's tack on an sglist. @@ -1649,6 +1648,7 @@ static void ql_process_mac_rx_skb(struct ql_adapter *qdev, (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_V4)) { /* Unfragmented ipv4 UDP frame. */ struct iphdr *iph = (struct iphdr *) skb->data; + if (!(iph->frag_off & htons(IP_MF|IP_OFFSET))) { skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -1818,6 +1818,7 @@ static struct sk_buff *ql_build_rx_skb(struct ql_adapter *qdev, * eventually be in trouble. */ int size, i = 0; + sbq_desc = qlge_get_curr_buf(&rx_ring->sbq); pci_unmap_single(qdev->pdev, sbq_desc->dma_addr, SMALL_BUF_MAP_SIZE, PCI_DMA_FROMDEVICE); @@ -1936,6 +1937,7 @@ static void ql_process_mac_split_rx_intr(struct ql_adapter *qdev, (ib_mac_rsp->flags3 & IB_MAC_IOCB_RSP_V4)) { /* Unfragmented ipv4 UDP frame. */ struct iphdr *iph = (struct iphdr *) skb->data; + if (!(iph->frag_off & htons(IP_MF|IP_OFFSET))) { skb->ip_summed = CHECKSUM_UNNECESSARY; @@ -2391,6 +2393,7 @@ static void qlge_restore_vlan(struct ql_adapter *qdev) static irqreturn_t qlge_msix_rx_isr(int irq, void *dev_id) { struct rx_ring *rx_ring = dev_id; + napi_schedule(&rx_ring->napi); return IRQ_HANDLED; } @@ -2497,6 +2500,7 @@ static int ql_tso(struct sk_buff *skb, struct ob_mac_tso_iocb_req *mac_iocb_ptr) mac_iocb_ptr->flags2 |= OB_MAC_TSO_IOCB_LSO; if (likely(l3_proto == htons(ETH_P_IP))) { struct iphdr *iph = ip_hdr(skb); + iph->check = 0; mac_iocb_ptr->flags1 |= OB_MAC_TSO_IOCB_IP4; tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, @@ -2521,6 +2525,7 @@ static void ql_hw_csum_setup(struct sk_buff *skb, int len; struct iphdr *iph = ip_hdr(skb); __sum16 *check; + mac_iocb_ptr->opcode = OPCODE_OB_MAC_TSO_IOCB; mac_iocb_ptr->frame_len = cpu_to_le32((u32) skb->len); mac_iocb_ptr->net_trans_offset = @@ -3896,14 +3901,11 @@ static void ql_release_adapter_resources(struct ql_adapter *qdev) static int ql_get_adapter_resources(struct ql_adapter *qdev) { - int status = 0; - if (ql_alloc_mem_resources(qdev)) { netif_err(qdev, ifup, qdev->ndev, "Unable to allocate memory.\n"); return -ENOMEM; } - status = ql_request_irq(qdev); - return status; + return ql_request_irq(qdev); } static int qlge_close(struct net_device *ndev) @@ -4265,6 +4267,7 @@ static int qlge_set_mac_address(struct net_device *ndev, void *p) static void qlge_tx_timeout(struct net_device *ndev, unsigned int txqueue) { struct ql_adapter *qdev = netdev_priv(ndev); + ql_queue_asic_error(qdev); } @@ -4273,6 +4276,7 @@ static void ql_asic_reset_work(struct work_struct *work) struct ql_adapter *qdev = container_of(work, struct ql_adapter, asic_reset_work.work); int status; + rtnl_lock(); status = ql_adapter_down(qdev); if (status) @@ -4344,6 +4348,7 @@ static int ql_get_alt_pcie_func(struct ql_adapter *qdev) static int ql_get_board_info(struct ql_adapter *qdev) { int status; + qdev->func = (ql_read32(qdev, STS) & STS_FUNC_ID_MASK) >> STS_FUNC_ID_SHIFT; if (qdev->func > 3) @@ -4652,6 +4657,7 @@ static void qlge_remove(struct pci_dev *pdev) { struct net_device *ndev = pci_get_drvdata(pdev); struct ql_adapter *qdev = netdev_priv(ndev); + del_timer_sync(&qdev->timer); ql_cancel_all_work_sync(qdev); unregister_netdev(ndev); diff --git a/drivers/staging/qlge/qlge_mpi.c b/drivers/staging/qlge/qlge_mpi.c index bb03b2fa7233..60c08d9cc034 100644 --- a/drivers/staging/qlge/qlge_mpi.c +++ b/drivers/staging/qlge/qlge_mpi.c @@ -90,9 +90,7 @@ exit: int ql_soft_reset_mpi_risc(struct ql_adapter *qdev) { - int status; - status = ql_write_mpi_reg(qdev, 0x00001010, 1); - return status; + return ql_write_mpi_reg(qdev, 0x00001010, 1); } /* Determine if we are in charge of the firwmare. If @@ -237,6 +235,7 @@ static int ql_idc_cmplt_aen(struct ql_adapter *qdev) { int status; struct mbox_params *mbcp = &qdev->idc_mbc; + mbcp->out_count = 4; status = ql_get_mb_sts(qdev, mbcp); if (status) { @@ -255,6 +254,7 @@ static int ql_idc_cmplt_aen(struct ql_adapter *qdev) static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp) { int status; + mbcp->out_count = 2; status = ql_get_mb_sts(qdev, mbcp); @@ -353,6 +353,7 @@ static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp) netif_err(qdev, drv, qdev->ndev, "Lost AEN broken!\n"); else { int i; + netif_err(qdev, drv, qdev->ndev, "Lost AEN detected.\n"); for (i = 0; i < mbcp->out_count; i++) netif_err(qdev, drv, qdev->ndev, "mbox_out[%d] = 0x%.08x.\n", @@ -912,6 +913,7 @@ static int ql_idc_wait(struct ql_adapter *qdev) int status = -ETIMEDOUT; long wait_time = 1 * HZ; struct mbox_params *mbcp = &qdev->idc_mbc; + do { /* Wait here for the command to complete * via the IDC process. @@ -1096,6 +1098,7 @@ int ql_wait_fifo_empty(struct ql_adapter *qdev) static int ql_set_port_cfg(struct ql_adapter *qdev) { int status; + status = ql_mb_set_port_cfg(qdev); if (status) return status; diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c index 815dfee11968..f69e9453ad45 100644 --- a/drivers/staging/rtl8188eu/core/rtw_cmd.c +++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c @@ -199,7 +199,7 @@ _next: rtw_free_cmd_obj(pcmd); } else { /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */ - pcmd_callback(pcmd->padapter, pcmd);/* need conider that free cmd_obj in rtw_cmd_callback */ + pcmd_callback(pcmd->padapter, pcmd);/* need consider that free cmd_obj in rtw_cmd_callback */ } } else { RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("%s: cmdcode = 0x%x callback not defined!\n", __func__, pcmd->cmdcode)); diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c b/drivers/staging/rtl8188eu/core/rtw_debug.c index 6c2fe1a112ac..d0e41f2ef1ce 100644 --- a/drivers/staging/rtl8188eu/core/rtw_debug.c +++ b/drivers/staging/rtl8188eu/core/rtw_debug.c @@ -15,7 +15,7 @@ int proc_get_drv_version(char *page, char **start, { int len = 0; - len += snprintf(page + len, count - len, "%s\n", DRIVERVERSION); + len += scnprintf(page + len, count - len, "%s\n", DRIVERVERSION); *eof = 1; return len; @@ -86,16 +86,16 @@ int proc_get_read_reg(char *page, char **start, switch (proc_get_read_len) { case 1: - len += snprintf(page + len, count - len, "usb_read8(0x%x)=0x%x\n", proc_get_read_addr, usb_read8(padapter, proc_get_read_addr)); + len += scnprintf(page + len, count - len, "usb_read8(0x%x)=0x%x\n", proc_get_read_addr, usb_read8(padapter, proc_get_read_addr)); break; case 2: - len += snprintf(page + len, count - len, "usb_read16(0x%x)=0x%x\n", proc_get_read_addr, usb_read16(padapter, proc_get_read_addr)); + len += scnprintf(page + len, count - len, "usb_read16(0x%x)=0x%x\n", proc_get_read_addr, usb_read16(padapter, proc_get_read_addr)); break; case 4: - len += snprintf(page + len, count - len, "usb_read32(0x%x)=0x%x\n", proc_get_read_addr, usb_read32(padapter, proc_get_read_addr)); + len += scnprintf(page + len, count - len, "usb_read32(0x%x)=0x%x\n", proc_get_read_addr, usb_read32(padapter, proc_get_read_addr)); break; default: - len += snprintf(page + len, count - len, "error read length=%d\n", proc_get_read_len); + len += scnprintf(page + len, count - len, "error read length=%d\n", proc_get_read_len); break; } @@ -138,7 +138,7 @@ int proc_get_adapter_state(char *page, char **start, struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); int len = 0; - len += snprintf(page + len, count - len, "bSurpriseRemoved=%d, bDriverStopped=%d\n", + len += scnprintf(page + len, count - len, "bSurpriseRemoved=%d, bDriverStopped=%d\n", padapter->bSurpriseRemoved, padapter->bDriverStopped); *eof = 1; @@ -170,11 +170,11 @@ int proc_get_best_channel(char *page, char **start, } /* debug */ - len += snprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n", + len += scnprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n", pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count); } - len += snprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G); + len += scnprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G); *eof = 1; return len; diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c index 29f615443e8f..e186982d5908 100644 --- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c @@ -236,14 +236,10 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv) ie = rtw_set_ie(ie, _SSID_IE_, pdev_network->ssid.ssid_length, pdev_network->ssid.ssid, &sz); /* supported rates */ - if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) { - if (pdev_network->Configuration.DSConfig > 14) - wireless_mode = WIRELESS_11A_5N; - else - wireless_mode = WIRELESS_11BG_24N; - } else { + if (pregistrypriv->wireless_mode == WIRELESS_11ABGN) + wireless_mode = WIRELESS_11BG_24N; + else wireless_mode = pregistrypriv->wireless_mode; - } rtw_set_supported_rate(pdev_network->SupportedRates, wireless_mode); diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c index e764436e120f..9de2d421f6b1 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c @@ -149,7 +149,7 @@ static void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network * (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))) lifetime = 1; if (!isfreeall) { - delta_time = (curr_time - pnetwork->last_scanned)/HZ; + delta_time = (curr_time - pnetwork->last_scanned) / HZ; if (delta_time < lifetime)/* unit:sec */ return; } @@ -249,8 +249,8 @@ void rtw_generate_random_ibss(u8 *pibss) pibss[1] = 0x11; pibss[2] = 0x87; pibss[3] = (u8)(curtime & 0xff);/* p[0]; */ - pibss[4] = (u8)((curtime>>8) & 0xff);/* p[1]; */ - pibss[5] = (u8)((curtime>>16) & 0xff);/* p[2]; */ + pibss[4] = (u8)((curtime >> 8) & 0xff);/* p[1]; */ + pibss[5] = (u8)((curtime >> 16) & 0xff);/* p[2]; */ } u8 *rtw_get_capability_from_ie(u8 *ie) @@ -357,9 +357,9 @@ void update_network(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, rssi_final = rssi_ori; } else { if (sq_smp != 101) { /* from the right channel */ - ss_final = ((u32)(src->PhyInfo.SignalStrength)+(u32)(dst->PhyInfo.SignalStrength)*4)/5; - sq_final = ((u32)(src->PhyInfo.SignalQuality)+(u32)(dst->PhyInfo.SignalQuality)*4)/5; - rssi_final = (src->Rssi+dst->Rssi*4)/5; + ss_final = ((u32)(src->PhyInfo.SignalStrength) + (u32)(dst->PhyInfo.SignalStrength) * 4) / 5; + sq_final = ((u32)(src->PhyInfo.SignalQuality) + (u32)(dst->PhyInfo.SignalQuality) * 4) / 5; + rssi_final = (src->Rssi + dst->Rssi * 4) / 5; } else { /* bss info not receiving from the right channel, use the original RX signal infos */ ss_final = dst->PhyInfo.SignalStrength; @@ -510,7 +510,7 @@ static int rtw_is_desired_network(struct adapter *adapter, struct wlan_network * privacy = pnetwork->network.Privacy; if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) { - if (rtw_get_wps_ie(pnetwork->network.ies+_FIXED_IE_LENGTH_, pnetwork->network.ie_length-_FIXED_IE_LENGTH_, NULL, &wps_ielen)) + if (rtw_get_wps_ie(pnetwork->network.ies + _FIXED_IE_LENGTH_, pnetwork->network.ie_length - _FIXED_IE_LENGTH_, NULL, &wps_ielen)) return true; else return false; @@ -924,8 +924,8 @@ static void rtw_joinbss_update_network(struct adapter *padapter, struct wlan_net /* update fw_state will clr _FW_UNDER_LINKING here indirectly */ switch (pnetwork->network.InfrastructureMode) { case Ndis802_11Infrastructure: - if (pmlmepriv->fw_state&WIFI_UNDER_WPS) - pmlmepriv->fw_state = WIFI_STATION_STATE|WIFI_UNDER_WPS; + if (pmlmepriv->fw_state & WIFI_UNDER_WPS) + pmlmepriv->fw_state = WIFI_STATION_STATE | WIFI_UNDER_WPS; else pmlmepriv->fw_state = WIFI_STATION_STATE; break; @@ -1097,14 +1097,14 @@ static u8 search_max_mac_id(struct adapter *padapter) #if defined(CONFIG_88EU_AP_MODE) if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { for (aid = pstapriv->max_num_sta; aid > 0; aid--) { - if (pstapriv->sta_aid[aid-1]) + if (pstapriv->sta_aid[aid - 1]) break; } mac_id = aid + 1; } else #endif {/* adhoc id = 31~2 */ - for (mac_id = NUM_STA-1; mac_id >= IBSS_START_MAC_ID; mac_id--) { + for (mac_id = NUM_STA - 1; mac_id >= IBSS_START_MAC_ID; mac_id--) { if (pmlmeinfo->FW_sta_info[mac_id].status == 1) break; } @@ -1123,7 +1123,7 @@ void rtw_stassoc_hw_rpt(struct adapter *adapter, struct sta_info *psta) macid = search_max_mac_id(adapter); rtw_hal_set_hwreg(adapter, HW_VAR_TX_RPT_MAX_MACID, (u8 *)&macid); - media_status = (psta->mac_id<<8)|1; /* MACID|OPMODE:1 connect */ + media_status = (psta->mac_id << 8) | 1; /* MACID|OPMODE:1 connect */ rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status); } @@ -1213,7 +1213,7 @@ void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf) if (mac_id >= 0) { u16 media_status; - media_status = (mac_id<<8)|0; /* MACID|OPMODE:0 means disconnect */ + media_status = (mac_id << 8) | 0; /* MACID|OPMODE:0 means disconnect */ /* for STA, AP, ADHOC mode, report disconnect stauts to FW */ rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status); } @@ -1640,7 +1640,7 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ for (i = 12; i < in_len; i += (in_ie[i + 1] + 2) /* to the next IE element */) { ielength = initial_out_len; - if (in_ie[i] == 0xDD && in_ie[i+2] == 0x00 && in_ie[i+3] == 0x50 && in_ie[i+4] == 0xF2 && in_ie[i+5] == 0x02 && i+5 < in_len) { + if (in_ie[i] == 0xDD && in_ie[i + 2] == 0x00 && in_ie[i + 3] == 0x50 && in_ie[i + 4] == 0xF2 && in_ie[i + 5] == 0x02 && i + 5 < in_len) { /* WMM element ID and OUI */ /* Append WMM IE to the last index of out_ie */ @@ -1734,13 +1734,13 @@ int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_ authmode = _WPA2_IE_ID_; if (check_fwstate(pmlmepriv, WIFI_UNDER_WPS)) { - memcpy(out_ie+ielength, psecuritypriv->wps_ie, psecuritypriv->wps_ie_len); + memcpy(out_ie + ielength, psecuritypriv->wps_ie, psecuritypriv->wps_ie_len); ielength += psecuritypriv->wps_ie_len; } else if ((authmode == _WPA_IE_ID_) || (authmode == _WPA2_IE_ID_)) { /* copy RSN or SSN */ - memcpy(&out_ie[ielength], &psecuritypriv->supplicant_ie[0], psecuritypriv->supplicant_ie[1]+2); - ielength += psecuritypriv->supplicant_ie[1]+2; + memcpy(&out_ie[ielength], &psecuritypriv->supplicant_ie[0], psecuritypriv->supplicant_ie[1] + 2); + ielength += psecuritypriv->supplicant_ie[1] + 2; rtw_report_sec_ie(adapter, authmode, psecuritypriv->supplicant_ie); } @@ -1865,7 +1865,7 @@ unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ phtpriv->ht_option = false; - p = rtw_get_ie(in_ie+12, _HT_CAPABILITY_IE_, &ielen, in_len-12); + p = rtw_get_ie(in_ie + 12, _HT_CAPABILITY_IE_, &ielen, in_len - 12); if (p && ielen > 0) { struct ieee80211_ht_cap ht_cap; @@ -1904,16 +1904,16 @@ unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ else ht_cap.ampdu_params_info |= IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00; - rtw_set_ie(out_ie+out_len, _HT_CAPABILITY_IE_, + rtw_set_ie(out_ie + out_len, _HT_CAPABILITY_IE_, sizeof(struct ieee80211_ht_cap), (unsigned char *)&ht_cap, pout_len); phtpriv->ht_option = true; - p = rtw_get_ie(in_ie+12, _HT_ADD_INFO_IE_, &ielen, in_len-12); + p = rtw_get_ie(in_ie + 12, _HT_ADD_INFO_IE_, &ielen, in_len - 12); if (p && (ielen == sizeof(struct ieee80211_ht_addt_info))) { out_len = *pout_len; - rtw_set_ie(out_ie+out_len, _HT_ADD_INFO_IE_, ielen, p+2, pout_len); + rtw_set_ie(out_ie + out_len, _HT_ADD_INFO_IE_, ielen, p + 2, pout_len); } } return phtpriv->ht_option; diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c index 36841d20c3c1..04897cd48370 100644 --- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c @@ -1151,7 +1151,7 @@ static void issue_assocreq(struct adapter *padapter) if (!padapter->registrypriv.wifi_spec) { /* Commented by Kurt 20110629 */ /* In some older APs, WPS handshake */ - /* would be fail if we append vender extensions informations to AP */ + /* would be fail if we append vender extensions information to AP */ if (!memcmp(pIE->data, WPS_OUI, 4)) pIE->Length = 14; } diff --git a/drivers/staging/rtl8188eu/hal/hal_com.c b/drivers/staging/rtl8188eu/hal/hal_com.c index 95f1b1431373..ebe19e076ff2 100644 --- a/drivers/staging/rtl8188eu/hal/hal_com.c +++ b/drivers/staging/rtl8188eu/hal/hal_com.c @@ -18,26 +18,26 @@ void dump_chip_info(struct HAL_VERSION chip_vers) uint cnt = 0; char buf[128]; - cnt += sprintf((buf+cnt), "Chip Version Info: CHIP_8188E_"); - cnt += sprintf((buf+cnt), "%s_", chip_vers.ChipType == NORMAL_CHIP ? + cnt += sprintf((buf + cnt), "Chip Version Info: CHIP_8188E_"); + cnt += sprintf((buf + cnt), "%s_", chip_vers.ChipType == NORMAL_CHIP ? "Normal_Chip" : "Test_Chip"); - cnt += sprintf((buf+cnt), "%s_", chip_vers.VendorType == CHIP_VENDOR_TSMC ? + cnt += sprintf((buf + cnt), "%s_", chip_vers.VendorType == CHIP_VENDOR_TSMC ? "TSMC" : "UMC"); if (chip_vers.CUTVersion == A_CUT_VERSION) - cnt += sprintf((buf+cnt), "A_CUT_"); + cnt += sprintf((buf + cnt), "A_CUT_"); else if (chip_vers.CUTVersion == B_CUT_VERSION) - cnt += sprintf((buf+cnt), "B_CUT_"); + cnt += sprintf((buf + cnt), "B_CUT_"); else if (chip_vers.CUTVersion == C_CUT_VERSION) - cnt += sprintf((buf+cnt), "C_CUT_"); + cnt += sprintf((buf + cnt), "C_CUT_"); else if (chip_vers.CUTVersion == D_CUT_VERSION) - cnt += sprintf((buf+cnt), "D_CUT_"); + cnt += sprintf((buf + cnt), "D_CUT_"); else if (chip_vers.CUTVersion == E_CUT_VERSION) - cnt += sprintf((buf+cnt), "E_CUT_"); + cnt += sprintf((buf + cnt), "E_CUT_"); else - cnt += sprintf((buf+cnt), "UNKNOWN_CUT(%d)_", + cnt += sprintf((buf + cnt), "UNKNOWN_CUT(%d)_", chip_vers.CUTVersion); - cnt += sprintf((buf+cnt), "1T1R_"); - cnt += sprintf((buf+cnt), "RomVer(0)\n"); + cnt += sprintf((buf + cnt), "1T1R_"); + cnt += sprintf((buf + cnt), "RomVer(0)\n"); pr_info("%s", buf); } diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c index 7489491f5aaa..698377ea60ee 100644 --- a/drivers/staging/rtl8188eu/hal/odm.c +++ b/drivers/staging/rtl8188eu/hal/odm.c @@ -342,7 +342,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm) u8 CurrentIGI = pDM_DigTable->CurIGValue; ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG()==>\n")); - if ((!(pDM_Odm->SupportAbility&ODM_BB_DIG)) || (!(pDM_Odm->SupportAbility&ODM_BB_FA_CNT))) { + if ((!(pDM_Odm->SupportAbility & ODM_BB_DIG)) || (!(pDM_Odm->SupportAbility & ODM_BB_FA_CNT))) { ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG() Return: SupportAbility ODM_BB_DIG or ODM_BB_FA_CNT is disabled\n")); return; @@ -419,7 +419,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm) } if (pDM_DigTable->LargeFAHit >= 3) { - if ((pDM_DigTable->ForbiddenIGI+1) > pDM_DigTable->rx_gain_range_max) + if ((pDM_DigTable->ForbiddenIGI + 1) > pDM_DigTable->rx_gain_range_max) pDM_DigTable->rx_gain_range_min = pDM_DigTable->rx_gain_range_max; else pDM_DigTable->rx_gain_range_min = (pDM_DigTable->ForbiddenIGI + 1); @@ -432,7 +432,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm) pDM_DigTable->Recover_cnt--; } else { if (pDM_DigTable->LargeFAHit < 3) { - if ((pDM_DigTable->ForbiddenIGI-1) < DIG_Dynamic_MIN) { /* DM_DIG_MIN) */ + if ((pDM_DigTable->ForbiddenIGI - 1) < DIG_Dynamic_MIN) { /* DM_DIG_MIN) */ pDM_DigTable->ForbiddenIGI = DIG_Dynamic_MIN; /* DM_DIG_MIN; */ pDM_DigTable->rx_gain_range_min = DIG_Dynamic_MIN; /* DM_DIG_MIN; */ ODM_RT_TRACE(pDM_Odm, ODM_COMP_DIG, ODM_DBG_LOUD, ("odm_DIG(): Normal Case: At Lower Bound\n")); @@ -518,24 +518,24 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm) phy_set_bb_reg(adapter, ODM_REG_OFDM_FA_RSTD_11N, BIT(31), 1); /* hold page D counter */ ret_value = phy_query_bb_reg(adapter, ODM_REG_OFDM_FA_TYPE1_11N, bMaskDWord); - FalseAlmCnt->Cnt_Fast_Fsync = (ret_value&0xffff); - FalseAlmCnt->Cnt_SB_Search_fail = (ret_value & 0xffff0000)>>16; + FalseAlmCnt->Cnt_Fast_Fsync = (ret_value & 0xffff); + FalseAlmCnt->Cnt_SB_Search_fail = (ret_value & 0xffff0000) >> 16; ret_value = phy_query_bb_reg(adapter, ODM_REG_OFDM_FA_TYPE2_11N, bMaskDWord); - FalseAlmCnt->Cnt_OFDM_CCA = (ret_value&0xffff); - FalseAlmCnt->Cnt_Parity_Fail = (ret_value & 0xffff0000)>>16; + FalseAlmCnt->Cnt_OFDM_CCA = (ret_value & 0xffff); + FalseAlmCnt->Cnt_Parity_Fail = (ret_value & 0xffff0000) >> 16; ret_value = phy_query_bb_reg(adapter, ODM_REG_OFDM_FA_TYPE3_11N, bMaskDWord); - FalseAlmCnt->Cnt_Rate_Illegal = (ret_value&0xffff); - FalseAlmCnt->Cnt_Crc8_fail = (ret_value & 0xffff0000)>>16; + FalseAlmCnt->Cnt_Rate_Illegal = (ret_value & 0xffff); + FalseAlmCnt->Cnt_Crc8_fail = (ret_value & 0xffff0000) >> 16; ret_value = phy_query_bb_reg(adapter, ODM_REG_OFDM_FA_TYPE4_11N, bMaskDWord); - FalseAlmCnt->Cnt_Mcs_fail = (ret_value&0xffff); + FalseAlmCnt->Cnt_Mcs_fail = (ret_value & 0xffff); FalseAlmCnt->Cnt_Ofdm_fail = FalseAlmCnt->Cnt_Parity_Fail + FalseAlmCnt->Cnt_Rate_Illegal + FalseAlmCnt->Cnt_Crc8_fail + FalseAlmCnt->Cnt_Mcs_fail + FalseAlmCnt->Cnt_Fast_Fsync + FalseAlmCnt->Cnt_SB_Search_fail; ret_value = phy_query_bb_reg(adapter, ODM_REG_SC_CNT_11N, bMaskDWord); - FalseAlmCnt->Cnt_BW_LSC = (ret_value&0xffff); - FalseAlmCnt->Cnt_BW_USC = (ret_value & 0xffff0000)>>16; + FalseAlmCnt->Cnt_BW_LSC = (ret_value & 0xffff); + FalseAlmCnt->Cnt_BW_USC = (ret_value & 0xffff0000) >> 16; /* hold cck counter */ phy_set_bb_reg(adapter, ODM_REG_CCK_FA_RST_11N, BIT(12), 1); @@ -544,10 +544,10 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm) ret_value = phy_query_bb_reg(adapter, ODM_REG_CCK_FA_LSB_11N, bMaskByte0); FalseAlmCnt->Cnt_Cck_fail = ret_value; ret_value = phy_query_bb_reg(adapter, ODM_REG_CCK_FA_MSB_11N, bMaskByte3); - FalseAlmCnt->Cnt_Cck_fail += (ret_value & 0xff)<<8; + FalseAlmCnt->Cnt_Cck_fail += (ret_value & 0xff) << 8; ret_value = phy_query_bb_reg(adapter, ODM_REG_CCK_CCA_CNT_11N, bMaskDWord); - FalseAlmCnt->Cnt_CCK_CCA = ((ret_value&0xFF)<<8) | ((ret_value&0xFF00)>>8); + FalseAlmCnt->Cnt_CCK_CCA = ((ret_value & 0xFF) << 8) | ((ret_value & 0xFF00) >> 8); FalseAlmCnt->Cnt_all = (FalseAlmCnt->Cnt_Fast_Fsync + FalseAlmCnt->Cnt_SB_Search_fail + @@ -583,14 +583,14 @@ void odm_CCKPacketDetectionThresh(struct odm_dm_struct *pDM_Odm) u8 CurCCK_CCAThres; struct false_alarm_stats *FalseAlmCnt = &(pDM_Odm->FalseAlmCnt); - if (!(pDM_Odm->SupportAbility & (ODM_BB_CCK_PD|ODM_BB_FA_CNT))) + if (!(pDM_Odm->SupportAbility & (ODM_BB_CCK_PD | ODM_BB_FA_CNT))) return; if (pDM_Odm->ExtLNA) return; if (pDM_Odm->bLinked) { if (pDM_Odm->RSSI_Min > 25) { CurCCK_CCAThres = 0xcd; - } else if ((pDM_Odm->RSSI_Min <= 25) && (pDM_Odm->RSSI_Min > 10)) { + } else if (pDM_Odm->RSSI_Min > 10) { CurCCK_CCAThres = 0x83; } else { if (FalseAlmCnt->Cnt_Cck_fail > 1000) @@ -630,10 +630,10 @@ void ODM_RF_Saving(struct odm_dm_struct *pDM_Odm, u8 bForceInNormal) Rssi_Low_bound = 45; } if (pDM_PSTable->initialize == 0) { - pDM_PSTable->Reg874 = (phy_query_bb_reg(adapter, 0x874, bMaskDWord)&0x1CC000)>>14; - pDM_PSTable->RegC70 = (phy_query_bb_reg(adapter, 0xc70, bMaskDWord) & BIT(3))>>3; - pDM_PSTable->Reg85C = (phy_query_bb_reg(adapter, 0x85c, bMaskDWord)&0xFF000000)>>24; - pDM_PSTable->RegA74 = (phy_query_bb_reg(adapter, 0xa74, bMaskDWord)&0xF000)>>12; + pDM_PSTable->Reg874 = (phy_query_bb_reg(adapter, 0x874, bMaskDWord) & 0x1CC000) >> 14; + pDM_PSTable->RegC70 = (phy_query_bb_reg(adapter, 0xc70, bMaskDWord) & BIT(3)) >> 3; + pDM_PSTable->Reg85C = (phy_query_bb_reg(adapter, 0x85c, bMaskDWord) & 0xFF000000) >> 24; + pDM_PSTable->RegA74 = (phy_query_bb_reg(adapter, 0xa74, bMaskDWord) & 0xF000) >> 12; pDM_PSTable->initialize = 1; } @@ -718,13 +718,13 @@ u32 ODM_Get_Rate_Bitmap(struct odm_dm_struct *pDM_Odm, u32 macid, u32 ra_mask, u else rate_bitmap = 0x0000000f; break; - case (ODM_WM_A|ODM_WM_G): + case (ODM_WM_A | ODM_WM_G): if (rssi_level == DM_RATR_STA_HIGH) rate_bitmap = 0x00000f00; else rate_bitmap = 0x00000ff0; break; - case (ODM_WM_B|ODM_WM_G): + case (ODM_WM_B | ODM_WM_G): if (rssi_level == DM_RATR_STA_HIGH) rate_bitmap = 0x00000f00; else if (rssi_level == DM_RATR_STA_MIDDLE) @@ -732,8 +732,8 @@ u32 ODM_Get_Rate_Bitmap(struct odm_dm_struct *pDM_Odm, u32 macid, u32 ra_mask, u else rate_bitmap = 0x00000ff5; break; - case (ODM_WM_B|ODM_WM_G|ODM_WM_N24G): - case (ODM_WM_A|ODM_WM_B|ODM_WM_G|ODM_WM_N24G): + case (ODM_WM_B | ODM_WM_G | ODM_WM_N24G): + case (ODM_WM_A | ODM_WM_B | ODM_WM_G | ODM_WM_N24G): if (rssi_level == DM_RATR_STA_HIGH) { rate_bitmap = 0x000f0000; } else if (rssi_level == DM_RATR_STA_MIDDLE) { @@ -911,7 +911,7 @@ void odm_RSSIMonitorCheckCE(struct odm_dm_struct *pDM_Odm) if (psta->rssi_stat.UndecoratedSmoothedPWDB > tmpEntryMaxPWDB) tmpEntryMaxPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB; if (psta->rssi_stat.UndecoratedSmoothedPWDB != (-1)) - PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16)); + PWDB_rssi[sta_cnt++] = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB << 16)); } } diff --git a/drivers/staging/rtl8188eu/hal/odm_hwconfig.c b/drivers/staging/rtl8188eu/hal/odm_hwconfig.c index d5a9ac51e907..a6f2731b076d 100644 --- a/drivers/staging/rtl8188eu/hal/odm_hwconfig.c +++ b/drivers/staging/rtl8188eu/hal/odm_hwconfig.c @@ -103,33 +103,33 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm, switch (LNA_idx) { case 7: if (VGA_idx <= 27) - rx_pwr_all = -100 + 2 * (27-VGA_idx); /* VGA_idx = 27~2 */ + rx_pwr_all = -100 + 2 * (27 - VGA_idx); /* VGA_idx = 27~2 */ else rx_pwr_all = -100; break; case 6: - rx_pwr_all = -48 + 2 * (2-VGA_idx); /* VGA_idx = 2~0 */ + rx_pwr_all = -48 + 2 * (2 - VGA_idx); /* VGA_idx = 2~0 */ break; case 5: - rx_pwr_all = -42 + 2 * (7-VGA_idx); /* VGA_idx = 7~5 */ + rx_pwr_all = -42 + 2 * (7 - VGA_idx); /* VGA_idx = 7~5 */ break; case 4: - rx_pwr_all = -36 + 2 * (7-VGA_idx); /* VGA_idx = 7~4 */ + rx_pwr_all = -36 + 2 * (7 - VGA_idx); /* VGA_idx = 7~4 */ break; case 3: - rx_pwr_all = -24 + 2 * (7-VGA_idx); /* VGA_idx = 7~0 */ + rx_pwr_all = -24 + 2 * (7 - VGA_idx); /* VGA_idx = 7~0 */ break; case 2: if (cck_highpwr) - rx_pwr_all = -12 + 2 * (5-VGA_idx); /* VGA_idx = 5~0 */ + rx_pwr_all = -12 + 2 * (5 - VGA_idx); /* VGA_idx = 5~0 */ else - rx_pwr_all = -6 + 2 * (5-VGA_idx); + rx_pwr_all = -6 + 2 * (5 - VGA_idx); break; case 1: - rx_pwr_all = 8-2 * VGA_idx; + rx_pwr_all = 8 - 2 * VGA_idx; break; case 0: - rx_pwr_all = 14-2 * VGA_idx; + rx_pwr_all = 14 - 2 * VGA_idx; break; default: break; @@ -138,7 +138,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm, PWDB_ALL = odm_query_rxpwrpercentage(rx_pwr_all); if (!cck_highpwr) { if (PWDB_ALL >= 80) - PWDB_ALL = ((PWDB_ALL-80)<<1) + ((PWDB_ALL-80)>>1) + 80; + PWDB_ALL = ((PWDB_ALL - 80) << 1) + ((PWDB_ALL - 80) >> 1) + 80; else if ((PWDB_ALL <= 78) && (PWDB_ALL >= 20)) PWDB_ALL += 3; if (PWDB_ALL > 100) @@ -162,7 +162,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm, else if (SQ_rpt < 20) SQ = 100; else - SQ = ((64-SQ_rpt) * 100) / 44; + SQ = ((64 - SQ_rpt) * 100) / 44; } pPhyInfo->SignalQuality = SQ; pPhyInfo->RxMIMOSignalQuality[RF_PATH_A] = SQ; @@ -200,8 +200,8 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm, pPhyInfo->RxMIMOSignalStrength[i] = (u8)RSSI; /* Get Rx snr value in DB */ - pPhyInfo->RxSNR[i] = (s32)(pPhyStaRpt->path_rxsnr[i]/2); - dm_odm->PhyDbgInfo.RxSNRdB[i] = (s32)(pPhyStaRpt->path_rxsnr[i]/2); + pPhyInfo->RxSNR[i] = (s32)(pPhyStaRpt->path_rxsnr[i] / 2); + dm_odm->PhyDbgInfo.RxSNRdB[i] = (s32)(pPhyStaRpt->path_rxsnr[i] / 2); } /* (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) */ rx_pwr_all = (((pPhyStaRpt->cck_sig_qual_ofdm_pwdb_all) >> 1) & 0x7f) - 110; @@ -280,8 +280,8 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm, if (dm_odm->AntDivType == CG_TRX_SMART_ANTDIV) { if (pDM_FatTable->FAT_State == FAT_TRAINING_STATE) { if (pPktinfo->bPacketToSelf) { - antsel_tr_mux = (pDM_FatTable->antsel_rx_keep_2<<2) | - (pDM_FatTable->antsel_rx_keep_1<<1) | + antsel_tr_mux = (pDM_FatTable->antsel_rx_keep_2 << 2) | + (pDM_FatTable->antsel_rx_keep_1 << 1) | pDM_FatTable->antsel_rx_keep_0; pDM_FatTable->antSumRSSI[antsel_tr_mux] += pPhyInfo->RxPWDBAll; pDM_FatTable->antRSSIcnt[antsel_tr_mux]++; @@ -289,8 +289,8 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm, } } else if ((dm_odm->AntDivType == CG_TRX_HW_ANTDIV) || (dm_odm->AntDivType == CGCS_RX_HW_ANTDIV)) { if (pPktinfo->bPacketToSelf || pPktinfo->bPacketBeacon) { - antsel_tr_mux = (pDM_FatTable->antsel_rx_keep_2<<2) | - (pDM_FatTable->antsel_rx_keep_1<<1) | pDM_FatTable->antsel_rx_keep_0; + antsel_tr_mux = (pDM_FatTable->antsel_rx_keep_2 << 2) | + (pDM_FatTable->antsel_rx_keep_1 << 1) | pDM_FatTable->antsel_rx_keep_0; rtl88eu_dm_ant_sel_statistics(dm_odm, antsel_tr_mux, pPktinfo->StationID, pPhyInfo->RxPWDBAll); } } @@ -328,17 +328,17 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm, } else { if (pPhyInfo->RxPWDBAll > (u32)UndecoratedSmoothedOFDM) { UndecoratedSmoothedOFDM = - (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor-1)) + + (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor - 1)) + (RSSI_Ave)) / (Rx_Smooth_Factor); UndecoratedSmoothedOFDM = UndecoratedSmoothedOFDM + 1; } else { UndecoratedSmoothedOFDM = - (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor-1)) + + (((UndecoratedSmoothedOFDM) * (Rx_Smooth_Factor - 1)) + (RSSI_Ave)) / (Rx_Smooth_Factor); } } - pEntry->rssi_stat.PacketMap = (pEntry->rssi_stat.PacketMap<<1) | BIT(0); + pEntry->rssi_stat.PacketMap = (pEntry->rssi_stat.PacketMap << 1) | BIT(0); } else { RSSI_Ave = pPhyInfo->RxPWDBAll; @@ -349,16 +349,16 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm, } else { if (pPhyInfo->RxPWDBAll > (u32)UndecoratedSmoothedCCK) { UndecoratedSmoothedCCK = - ((UndecoratedSmoothedCCK * (Rx_Smooth_Factor-1)) + + ((UndecoratedSmoothedCCK * (Rx_Smooth_Factor - 1)) + pPhyInfo->RxPWDBAll) / Rx_Smooth_Factor; UndecoratedSmoothedCCK = UndecoratedSmoothedCCK + 1; } else { UndecoratedSmoothedCCK = - ((UndecoratedSmoothedCCK * (Rx_Smooth_Factor-1)) + + ((UndecoratedSmoothedCCK * (Rx_Smooth_Factor - 1)) + pPhyInfo->RxPWDBAll) / Rx_Smooth_Factor; } } - pEntry->rssi_stat.PacketMap = pEntry->rssi_stat.PacketMap<<1; + pEntry->rssi_stat.PacketMap = pEntry->rssi_stat.PacketMap << 1; } /* 2011.07.28 LukeLee: modified to prevent unstable CCK RSSI */ if (pEntry->rssi_stat.ValidBit >= 64) @@ -367,16 +367,16 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm, pEntry->rssi_stat.ValidBit++; for (i = 0; i < pEntry->rssi_stat.ValidBit; i++) - OFDM_pkt += (u8)(pEntry->rssi_stat.PacketMap>>i) & BIT(0); + OFDM_pkt += (u8)(pEntry->rssi_stat.PacketMap >> i) & BIT(0); if (pEntry->rssi_stat.ValidBit == 64) { Weighting = min_t(u32, OFDM_pkt << 4, 64); - UndecoratedSmoothedPWDB = (Weighting * UndecoratedSmoothedOFDM + (64-Weighting) * UndecoratedSmoothedCCK)>>6; + UndecoratedSmoothedPWDB = (Weighting * UndecoratedSmoothedOFDM + (64 - Weighting) * UndecoratedSmoothedCCK) >> 6; } else { if (pEntry->rssi_stat.ValidBit != 0) UndecoratedSmoothedPWDB = (OFDM_pkt * UndecoratedSmoothedOFDM + - (pEntry->rssi_stat.ValidBit-OFDM_pkt) * - UndecoratedSmoothedCCK)/pEntry->rssi_stat.ValidBit; + (pEntry->rssi_stat.ValidBit - OFDM_pkt) * + UndecoratedSmoothedCCK) / pEntry->rssi_stat.ValidBit; else UndecoratedSmoothedPWDB = 0; } diff --git a/drivers/staging/rtl8188eu/hal/phy.c b/drivers/staging/rtl8188eu/hal/phy.c index afaf9e55195a..b9025815b682 100644 --- a/drivers/staging/rtl8188eu/hal/phy.c +++ b/drivers/staging/rtl8188eu/hal/phy.c @@ -69,10 +69,10 @@ static u32 rf_serial_read(struct adapter *adapt, bMaskDWord); tmplong2 = (tmplong2 & (~bLSSIReadAddress)) | - (offset<<23) | bLSSIReadEdge; + (offset << 23) | bLSSIReadEdge; phy_set_bb_reg(adapt, rFPGA0_XA_HSSIParameter2, bMaskDWord, - tmplong&(~bLSSIReadEdge)); + tmplong & (~bLSSIReadEdge)); udelay(10); phy_set_bb_reg(adapt, phyreg->rfHSSIPara2, bMaskDWord, tmplong2); @@ -102,7 +102,7 @@ static void rf_serial_write(struct adapter *adapt, struct bb_reg_def *phyreg = &adapt->HalData->PHYRegDef[rfpath]; offset &= 0xff; - data_and_addr = ((offset<<20) | (data&0x000fffff)) & 0x0fffffff; + data_and_addr = ((offset << 20) | (data & 0x000fffff)) & 0x0fffffff; phy_set_bb_reg(adapt, phyreg->rf3wireOffset, bMaskDWord, data_and_addr); } @@ -143,20 +143,20 @@ static void get_tx_power_index(struct adapter *adapt, u8 channel, u8 *cck_pwr, for (TxCount = 0; TxCount < path_nums; TxCount++) { if (TxCount == RF_PATH_A) { cck_pwr[TxCount] = hal_data->Index24G_CCK_Base[TxCount][index]; - ofdm_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index]+ + ofdm_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index] + hal_data->OFDM_24G_Diff[TxCount][RF_PATH_A]; - bw20_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index]+ + bw20_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index] + hal_data->BW20_24G_Diff[TxCount][RF_PATH_A]; bw40_pwr[TxCount] = hal_data->Index24G_BW40_Base[TxCount][index]; } else if (TxCount == RF_PATH_B) { cck_pwr[TxCount] = hal_data->Index24G_CCK_Base[TxCount][index]; - ofdm_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index]+ - hal_data->BW20_24G_Diff[RF_PATH_A][index]+ + ofdm_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index] + + hal_data->BW20_24G_Diff[RF_PATH_A][index] + hal_data->BW20_24G_Diff[TxCount][index]; - bw20_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index]+ - hal_data->BW20_24G_Diff[TxCount][RF_PATH_A]+ + bw20_pwr[TxCount] = hal_data->Index24G_BW40_Base[RF_PATH_A][index] + + hal_data->BW20_24G_Diff[TxCount][RF_PATH_A] + hal_data->BW20_24G_Diff[TxCount][index]; bw40_pwr[TxCount] = hal_data->Index24G_BW40_Base[TxCount][index]; } @@ -205,7 +205,7 @@ static void phy_set_bw_mode_callback(struct adapter *adapt) /* Set MAC register */ reg_bw_opmode = usb_read8(adapt, REG_BWOPMODE); - reg_prsr_rsc = usb_read8(adapt, REG_RRSR+2); + reg_prsr_rsc = usb_read8(adapt, REG_RRSR + 2); switch (hal_data->CurrentChannelBW) { case HT_CHANNEL_WIDTH_20: @@ -215,9 +215,9 @@ static void phy_set_bw_mode_callback(struct adapter *adapt) case HT_CHANNEL_WIDTH_40: reg_bw_opmode &= ~BW_OPMODE_20MHZ; usb_write8(adapt, REG_BWOPMODE, reg_bw_opmode); - reg_prsr_rsc = (reg_prsr_rsc&0x90) | - (hal_data->nCur40MhzPrimeSC<<5); - usb_write8(adapt, REG_RRSR+2, reg_prsr_rsc); + reg_prsr_rsc = (reg_prsr_rsc & 0x90) | + (hal_data->nCur40MhzPrimeSC << 5); + usb_write8(adapt, REG_RRSR + 2, reg_prsr_rsc); break; default: break; @@ -236,7 +236,7 @@ static void phy_set_bw_mode_callback(struct adapter *adapt) * These settings are required only for 40MHz */ phy_set_bb_reg(adapt, rCCK0_System, bCCKSideBand, - (hal_data->nCur40MhzPrimeSC>>1)); + (hal_data->nCur40MhzPrimeSC >> 1)); phy_set_bb_reg(adapt, rOFDM1_LSTF, 0xC00, hal_data->nCur40MhzPrimeSC); phy_set_bb_reg(adapt, 0x818, (BIT(26) | BIT(27)), @@ -337,8 +337,8 @@ void rtl88eu_dm_txpower_track_adjust(struct odm_dm_struct *dm_odm, u8 type, if (pwr_value >= ODM_TXPWRTRACK_MAX_IDX_88E && *direction == 1) pwr_value = ODM_TXPWRTRACK_MAX_IDX_88E; - *out_write_val = pwr_value | (pwr_value<<8) | (pwr_value<<16) | - (pwr_value<<24); + *out_write_val = pwr_value | (pwr_value << 8) | (pwr_value << 16) | + (pwr_value << 24); } static void dm_txpwr_track_setpwr(struct odm_dm_struct *dm_odm) @@ -389,9 +389,9 @@ void rtl88eu_dm_txpower_tracking_callback_thermalmeter(struct adapter *adapt) if (thermal_val) { /* Query OFDM path A default setting */ - ele_d = phy_query_bb_reg(adapt, rOFDM0_XATxIQImbalance, bMaskDWord)&bMaskOFDM_D; + ele_d = phy_query_bb_reg(adapt, rOFDM0_XATxIQImbalance, bMaskDWord) & bMaskOFDM_D; for (i = 0; i < OFDM_TABLE_SIZE_92D; i++) { - if (ele_d == (OFDMSwingTable[i]&bMaskOFDM_D)) { + if (ele_d == (OFDMSwingTable[i] & bMaskOFDM_D)) { ofdm_index_old[0] = (u8)i; dm_odm->BbSwingIdxOfdmBase = (u8)i; break; @@ -472,18 +472,18 @@ void rtl88eu_dm_txpower_tracking_callback_thermalmeter(struct adapter *adapt) } } if (offset >= index_mapping_NUM_88E) - offset = index_mapping_NUM_88E-1; + offset = index_mapping_NUM_88E - 1; /* Updating ofdm_index values with new OFDM / CCK offset */ ofdm_index[0] = dm_odm->RFCalibrateInfo.OFDM_index[0] + ofdm_index_mapping[j][offset]; - if (ofdm_index[0] > OFDM_TABLE_SIZE_92D-1) - ofdm_index[0] = OFDM_TABLE_SIZE_92D-1; + if (ofdm_index[0] > OFDM_TABLE_SIZE_92D - 1) + ofdm_index[0] = OFDM_TABLE_SIZE_92D - 1; else if (ofdm_index[0] < ofdm_min_index) ofdm_index[0] = ofdm_min_index; cck_index = dm_odm->RFCalibrateInfo.CCK_index + ofdm_index_mapping[j][offset]; - if (cck_index > CCK_TABLE_SIZE-1) - cck_index = CCK_TABLE_SIZE-1; + if (cck_index > CCK_TABLE_SIZE - 1) + cck_index = CCK_TABLE_SIZE - 1; else if (cck_index < 0) cck_index = 0; @@ -548,8 +548,8 @@ static u8 phy_path_a_iqk(struct adapter *adapt, bool config_pathb) reg_e9c = phy_query_bb_reg(adapt, rTx_Power_After_IQK_A, bMaskDWord); if (!(reg_eac & BIT(28)) && - (((reg_e94 & 0x03FF0000)>>16) != 0x142) && - (((reg_e9c & 0x03FF0000)>>16) != 0x42)) + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) result |= 0x01; return result; } @@ -600,13 +600,13 @@ static u8 phy_path_a_rx_iqk(struct adapter *adapt, bool configPathB) reg_e9c = phy_query_bb_reg(adapt, rTx_Power_After_IQK_A, bMaskDWord); if (!(reg_eac & BIT(28)) && - (((reg_e94 & 0x03FF0000)>>16) != 0x142) && - (((reg_e9c & 0x03FF0000)>>16) != 0x42)) + (((reg_e94 & 0x03FF0000) >> 16) != 0x142) && + (((reg_e9c & 0x03FF0000) >> 16) != 0x42)) result |= 0x01; else /* if Tx not OK, ignore Rx */ return result; - u4tmp = 0x80007C00 | (reg_e94&0x3FF0000) | ((reg_e9c&0x3FF0000) >> 16); + u4tmp = 0x80007C00 | (reg_e94 & 0x3FF0000) | ((reg_e9c & 0x3FF0000) >> 16); phy_set_bb_reg(adapt, rTx_IQK, bMaskDWord, u4tmp); /* 1 RX IQK */ @@ -648,8 +648,8 @@ static u8 phy_path_a_rx_iqk(struct adapter *adapt, bool configPathB) phy_set_rf_reg(adapt, RF_PATH_A, 0xdf, bRFRegOffsetMask, 0x180); if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */ - (((reg_ea4 & 0x03FF0000)>>16) != 0x132) && - (((reg_eac & 0x03FF0000)>>16) != 0x36)) + (((reg_ea4 & 0x03FF0000) >> 16) != 0x132) && + (((reg_eac & 0x03FF0000) >> 16) != 0x36)) result |= 0x02; else ODM_RT_TRACE(dm_odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, @@ -677,15 +677,15 @@ static u8 phy_path_b_iqk(struct adapter *adapt) regecc = phy_query_bb_reg(adapt, rRx_Power_After_IQK_B_2, bMaskDWord); if (!(regeac & BIT(31)) && - (((regeb4 & 0x03FF0000)>>16) != 0x142) && - (((regebc & 0x03FF0000)>>16) != 0x42)) + (((regeb4 & 0x03FF0000) >> 16) != 0x142) && + (((regebc & 0x03FF0000) >> 16) != 0x42)) result |= 0x01; else return result; if (!(regeac & BIT(30)) && - (((regec4 & 0x03FF0000)>>16) != 0x132) && - (((regecc & 0x03FF0000)>>16) != 0x36)) + (((regec4 & 0x03FF0000) >> 16) != 0x132) && + (((regecc & 0x03FF0000) >> 16) != 0x36)) result |= 0x02; else ODM_RT_TRACE(dm_odm, ODM_COMP_CALIBRATION, @@ -711,7 +711,7 @@ static void patha_fill_iqk(struct adapter *adapt, bool iqkok, s32 result[][8], tx0_a = (x * oldval_0) >> 8; phy_set_bb_reg(adapt, rOFDM0_XATxIQImbalance, 0x3FF, tx0_a); phy_set_bb_reg(adapt, rOFDM0_ECCAThreshold, BIT(31), - ((x * oldval_0>>7) & 0x1)); + ((x * oldval_0 >> 7) & 0x1)); y = result[final_candidate][1]; if ((y & 0x00000200) != 0) @@ -719,11 +719,11 @@ static void patha_fill_iqk(struct adapter *adapt, bool iqkok, s32 result[][8], tx0_c = (y * oldval_0) >> 8; phy_set_bb_reg(adapt, rOFDM0_XCTxAFE, 0xF0000000, - ((tx0_c&0x3C0)>>6)); + ((tx0_c & 0x3C0) >> 6)); phy_set_bb_reg(adapt, rOFDM0_XATxIQImbalance, 0x003F0000, - (tx0_c&0x3F)); + (tx0_c & 0x3F)); phy_set_bb_reg(adapt, rOFDM0_ECCAThreshold, BIT(29), - ((y * oldval_0>>7) & 0x1)); + ((y * oldval_0 >> 7) & 0x1)); if (txonly) return; @@ -757,7 +757,7 @@ static void pathb_fill_iqk(struct adapter *adapt, bool iqkok, s32 result[][8], phy_set_bb_reg(adapt, rOFDM0_XBTxIQImbalance, 0x3FF, tx1_a); phy_set_bb_reg(adapt, rOFDM0_ECCAThreshold, BIT(27), - ((x * oldval_1>>7) & 0x1)); + ((x * oldval_1 >> 7) & 0x1)); y = result[final_candidate][5]; if ((y & 0x00000200) != 0) @@ -766,11 +766,11 @@ static void pathb_fill_iqk(struct adapter *adapt, bool iqkok, s32 result[][8], tx1_c = (y * oldval_1) >> 8; phy_set_bb_reg(adapt, rOFDM0_XDTxAFE, 0xF0000000, - ((tx1_c&0x3C0)>>6)); + ((tx1_c & 0x3C0) >> 6)); phy_set_bb_reg(adapt, rOFDM0_XBTxIQImbalance, 0x003F0000, - (tx1_c&0x3F)); + (tx1_c & 0x3F)); phy_set_bb_reg(adapt, rOFDM0_ECCAThreshold, BIT(25), - ((y * oldval_1>>7) & 0x1)); + ((y * oldval_1 >> 7) & 0x1)); if (txonly) return; @@ -851,9 +851,9 @@ static void mac_setting_calibration(struct adapter *adapt, u32 *mac_reg, u32 *ba usb_write8(adapt, mac_reg[i], 0x3F); for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++) - usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT(3)))); + usb_write8(adapt, mac_reg[i], (u8)(backup[i] & (~BIT(3)))); - usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT(5)))); + usb_write8(adapt, mac_reg[i], (u8)(backup[i] & (~BIT(5)))); } static void path_a_standby(struct adapter *adapt) @@ -902,22 +902,22 @@ static bool simularity_compare(struct adapter *adapt, s32 resulta[][8], if (diff > MAX_TOLERANCE) { if ((i == 2 || i == 6) && !sim_bitmap) { - if (resulta[c1][i] + resulta[c1][i+1] == 0) - final_candidate[(i/4)] = c2; - else if (resulta[c2][i] + resulta[c2][i+1] == 0) - final_candidate[(i/4)] = c1; + if (resulta[c1][i] + resulta[c1][i + 1] == 0) + final_candidate[(i / 4)] = c2; + else if (resulta[c2][i] + resulta[c2][i + 1] == 0) + final_candidate[(i / 4)] = c1; else - sim_bitmap = sim_bitmap | (1<<i); + sim_bitmap = sim_bitmap | (1 << i); } else { - sim_bitmap = sim_bitmap | (1<<i); + sim_bitmap = sim_bitmap | (1 << i); } } } if (sim_bitmap == 0) { - for (i = 0; i < (bound/4); i++) { + for (i = 0; i < (bound / 4); i++) { if (final_candidate[i] != 0xFF) { - for (j = i*4; j < (i+1)*4-2; j++) + for (j = i * 4; j < (i + 1) * 4 - 2; j++) resulta[3][j] = resulta[final_candidate[i]][j]; result = false; } @@ -1038,9 +1038,9 @@ static void phy_iq_calibrate(struct adapter *adapt, s32 result[][8], path_a_ok = phy_path_a_iqk(adapt, is2t); if (path_a_ok == 0x01) { result[t][0] = (phy_query_bb_reg(adapt, rTx_Power_Before_IQK_A, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][1] = (phy_query_bb_reg(adapt, rTx_Power_After_IQK_A, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; break; } } @@ -1049,9 +1049,9 @@ static void phy_iq_calibrate(struct adapter *adapt, s32 result[][8], path_a_ok = phy_path_a_rx_iqk(adapt, is2t); if (path_a_ok == 0x03) { result[t][2] = (phy_query_bb_reg(adapt, rRx_Power_Before_IQK_A_2, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][3] = (phy_query_bb_reg(adapt, rRx_Power_After_IQK_A_2, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; break; } ODM_RT_TRACE(dm_odm, ODM_COMP_CALIBRATION, ODM_DBG_LOUD, @@ -1073,19 +1073,19 @@ static void phy_iq_calibrate(struct adapter *adapt, s32 result[][8], path_b_ok = phy_path_b_iqk(adapt); if (path_b_ok == 0x03) { result[t][4] = (phy_query_bb_reg(adapt, rTx_Power_Before_IQK_B, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][5] = (phy_query_bb_reg(adapt, rTx_Power_After_IQK_B, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][6] = (phy_query_bb_reg(adapt, rRx_Power_Before_IQK_B_2, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][7] = (phy_query_bb_reg(adapt, rRx_Power_After_IQK_B_2, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; break; } else if (i == (retry_count - 1) && path_b_ok == 0x01) { /* Tx IQK OK */ result[t][4] = (phy_query_bb_reg(adapt, rTx_Power_Before_IQK_B, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; result[t][5] = (phy_query_bb_reg(adapt, rTx_Power_After_IQK_B, - bMaskDWord)&0x3FF0000)>>16; + bMaskDWord) & 0x3FF0000) >> 16; } } @@ -1138,12 +1138,12 @@ static void phy_lc_calibrate(struct adapter *adapt, bool is2t) /* Check continuous TX and Packet TX */ tmpreg = usb_read8(adapt, 0xd03); - if ((tmpreg&0x70) != 0) - usb_write8(adapt, 0xd03, tmpreg&0x8F); + if ((tmpreg & 0x70) != 0) + usb_write8(adapt, 0xd03, tmpreg & 0x8F); else usb_write8(adapt, REG_TXPAUSE, 0xFF); - if ((tmpreg&0x70) != 0) { + if ((tmpreg & 0x70) != 0) { /* 1. Read original RF mode */ /* Path-A */ rf_a_mode = rtw_hal_read_rfreg(adapt, RF_PATH_A, RF_AC, @@ -1157,12 +1157,12 @@ static void phy_lc_calibrate(struct adapter *adapt, bool is2t) /* 2. Set RF mode = standby mode */ /* Path-A */ phy_set_rf_reg(adapt, RF_PATH_A, RF_AC, bMask12Bits, - (rf_a_mode&0x8FFFF)|0x10000); + (rf_a_mode & 0x8FFFF) | 0x10000); /* Path-B */ if (is2t) phy_set_rf_reg(adapt, RF_PATH_B, RF_AC, bMask12Bits, - (rf_b_mode&0x8FFFF)|0x10000); + (rf_b_mode & 0x8FFFF) | 0x10000); } /* 3. Read RF reg18 */ @@ -1170,12 +1170,12 @@ static void phy_lc_calibrate(struct adapter *adapt, bool is2t) /* 4. Set LC calibration begin bit15 */ phy_set_rf_reg(adapt, RF_PATH_A, RF_CHNLBW, bMask12Bits, - lc_cal|0x08000); + lc_cal | 0x08000); msleep(100); /* Restore original situation */ - if ((tmpreg&0x70) != 0) { + if ((tmpreg & 0x70) != 0) { /* Deal with continuous TX case */ /* Path-A */ usb_write8(adapt, 0xd03, tmpreg); diff --git a/drivers/staging/rtl8188eu/hal/pwrseqcmd.c b/drivers/staging/rtl8188eu/hal/pwrseqcmd.c index 249cbc375074..77edd7ad19a1 100644 --- a/drivers/staging/rtl8188eu/hal/pwrseqcmd.c +++ b/drivers/staging/rtl8188eu/hal/pwrseqcmd.c @@ -85,7 +85,7 @@ u8 rtl88eu_pwrseqcmdparsing(struct adapter *padapter, u8 cut_vers, if (GET_PWR_CFG_VALUE(pwrcfgcmd) == PWRSEQ_DELAY_US) udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd)); else - udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd)*1000); + udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd) * 1000); break; case PWR_CMD_END: /* When this command is parsed, end the process */ diff --git a/drivers/staging/rtl8188eu/hal/rf.c b/drivers/staging/rtl8188eu/hal/rf.c index 6fe4daea8fd5..00a9f692bb06 100644 --- a/drivers/staging/rtl8188eu/hal/rf.c +++ b/drivers/staging/rtl8188eu/hal/rf.c @@ -49,9 +49,9 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel) tx_agc[RF_PATH_B] = 0x3f3f3f3f; for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) { tx_agc[idx1] = powerlevel[idx1] | - (powerlevel[idx1]<<8) | - (powerlevel[idx1]<<16) | - (powerlevel[idx1]<<24); + (powerlevel[idx1] << 8) | + (powerlevel[idx1] << 16) | + (powerlevel[idx1] << 24); } } else { if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1) { @@ -63,17 +63,17 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel) } else { for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) { tx_agc[idx1] = powerlevel[idx1] | - (powerlevel[idx1]<<8) | - (powerlevel[idx1]<<16) | - (powerlevel[idx1]<<24); + (powerlevel[idx1] << 8) | + (powerlevel[idx1] << 16) | + (powerlevel[idx1] << 24); } if (hal_data->EEPROMRegulatory == 0) { tmpval = hal_data->MCSTxPowerLevelOriginalOffset[0][6] + - (hal_data->MCSTxPowerLevelOriginalOffset[0][7]<<8); + (hal_data->MCSTxPowerLevelOriginalOffset[0][7] << 8); tx_agc[RF_PATH_A] += tmpval; tmpval = hal_data->MCSTxPowerLevelOriginalOffset[0][14] + - (hal_data->MCSTxPowerLevelOriginalOffset[0][15]<<24); + (hal_data->MCSTxPowerLevelOriginalOffset[0][15] << 24); tx_agc[RF_PATH_B] += tmpval; } } @@ -100,15 +100,15 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel) } /* rf-A cck tx power */ - tmpval = tx_agc[RF_PATH_A]&0xff; + tmpval = tx_agc[RF_PATH_A] & 0xff; phy_set_bb_reg(adapt, rTxAGC_A_CCK1_Mcs32, bMaskByte1, tmpval); - tmpval = tx_agc[RF_PATH_A]>>8; + tmpval = tx_agc[RF_PATH_A] >> 8; phy_set_bb_reg(adapt, rTxAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); /* rf-B cck tx power */ - tmpval = tx_agc[RF_PATH_B]>>24; + tmpval = tx_agc[RF_PATH_B] >> 24; phy_set_bb_reg(adapt, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte0, tmpval); - tmpval = tx_agc[RF_PATH_B]&0x00ffffff; + tmpval = tx_agc[RF_PATH_B] & 0x00ffffff; phy_set_bb_reg(adapt, rTxAGC_B_CCK1_55_Mcs32, 0xffffff00, tmpval); } @@ -124,9 +124,9 @@ static void getpowerbase88e(struct adapter *adapt, u8 *pwr_level_ofdm, for (i = 0; i < 2; i++) { powerbase0 = pwr_level_ofdm[i]; - powerbase0 = (powerbase0<<24) | (powerbase0<<16) | - (powerbase0<<8) | powerbase0; - *(ofdmbase+i) = powerbase0; + powerbase0 = (powerbase0 << 24) | (powerbase0 << 16) | + (powerbase0 << 8) | powerbase0; + *(ofdmbase + i) = powerbase0; } /* Check HT20 to HT40 diff */ if (adapt->HalData->CurrentChannelBW == HT_CHANNEL_WIDTH_20) @@ -134,8 +134,8 @@ static void getpowerbase88e(struct adapter *adapt, u8 *pwr_level_ofdm, else powerlevel[0] = pwr_level_bw40[0]; powerbase1 = powerlevel[0]; - powerbase1 = (powerbase1<<24) | (powerbase1<<16) | - (powerbase1<<8) | powerbase1; + powerbase1 = (powerbase1 << 24) | (powerbase1 << 16) | + (powerbase1 << 8) | powerbase1; *mcs_base = powerbase1; } static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, @@ -157,7 +157,7 @@ static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, switch (regulatory) { case 0: chnlGroup = 0; - write_val = hal_data->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf ? 8 : 0)] + + write_val = hal_data->MCSTxPowerLevelOriginalOffset[chnlGroup][index + (rf ? 8 : 0)] + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); break; case 1: /* Realtek regulatory */ @@ -167,7 +167,7 @@ static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, if (hal_data->pwrGroupCnt >= hal_data->PGMaxGroup) Hal_GetChnlGroup88E(channel, &chnlGroup); - write_val = hal_data->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf ? 8 : 0)] + + write_val = hal_data->MCSTxPowerLevelOriginalOffset[chnlGroup][index + (rf ? 8 : 0)] + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); break; case 2: /* Better regulatory */ @@ -179,14 +179,14 @@ static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, chnlGroup = 0; if (index < 2) - pwr_diff = hal_data->TxPwrLegacyHtDiff[rf][channel-1]; + pwr_diff = hal_data->TxPwrLegacyHtDiff[rf][channel - 1]; else if (hal_data->CurrentChannelBW == HT_CHANNEL_WIDTH_20) - pwr_diff = hal_data->TxPwrHt20Diff[rf][channel-1]; + pwr_diff = hal_data->TxPwrHt20Diff[rf][channel - 1]; if (hal_data->CurrentChannelBW == HT_CHANNEL_WIDTH_40) - customer_pwr_limit = hal_data->PwrGroupHT40[rf][channel-1]; + customer_pwr_limit = hal_data->PwrGroupHT40[rf][channel - 1]; else - customer_pwr_limit = hal_data->PwrGroupHT20[rf][channel-1]; + customer_pwr_limit = hal_data->PwrGroupHT20[rf][channel - 1]; if (pwr_diff >= customer_pwr_limit) pwr_diff = 0; @@ -200,9 +200,9 @@ static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, if (pwr_diff_limit[i] > pwr_diff) pwr_diff_limit[i] = pwr_diff; } - customer_limit = (pwr_diff_limit[3]<<24) | - (pwr_diff_limit[2]<<16) | - (pwr_diff_limit[1]<<8) | + customer_limit = (pwr_diff_limit[3] << 24) | + (pwr_diff_limit[2] << 16) | + (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]); write_val = customer_limit + ((index < 2) ? powerbase0[rf] : powerbase1[rf]); break; @@ -221,7 +221,7 @@ static void get_rx_power_val_by_reg(struct adapter *adapt, u8 channel, else if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level2) write_val = 0x00000000; - *(out_val+rf) = write_val; + *(out_val + rf) = write_val; } } @@ -240,12 +240,12 @@ static void write_ofdm_pwr_reg(struct adapter *adapt, u8 index, u32 *pvalue) for (rf = 0; rf < 2; rf++) { write_val = pvalue[rf]; for (i = 0; i < 4; i++) { - pwr_val[i] = (u8)((write_val & (0x7f<<(i*8)))>>(i*8)); + pwr_val[i] = (u8)((write_val & (0x7f << (i * 8))) >> (i * 8)); if (pwr_val[i] > RF6052_MAX_TX_PWR) pwr_val[i] = RF6052_MAX_TX_PWR; } - write_val = (pwr_val[3]<<24) | (pwr_val[2]<<16) | - (pwr_val[1]<<8) | pwr_val[0]; + write_val = (pwr_val[3] << 24) | (pwr_val[2] << 16) | + (pwr_val[1] << 8) | pwr_val[0]; if (rf == 0) regoffset = regoffset_a[index]; diff --git a/drivers/staging/rtl8188eu/hal/rf_cfg.c b/drivers/staging/rtl8188eu/hal/rf_cfg.c index 47b1bf5a6143..0b20e62f9a68 100644 --- a/drivers/staging/rtl8188eu/hal/rf_cfg.c +++ b/drivers/staging/rtl8188eu/hal/rf_cfg.c @@ -15,7 +15,7 @@ static bool check_condition(struct adapter *adapt, const u32 condition) u32 _board = odm->BoardType; u32 _platform = odm->SupportPlatform; u32 _interface = odm->SupportInterface; - u32 cond = condition; + u32 cond; if (condition == 0xCDCDCDCD) return true; @@ -143,7 +143,7 @@ static u32 Array_RadioA_1T_8188E[] = { #define READ_NEXT_PAIR(v1, v2, i) \ do { \ i += 2; v1 = array[i]; \ - v2 = array[i+1]; \ + v2 = array[i + 1]; \ } while (0) #define RFREG_OFFSET_MASK 0xfffff @@ -190,7 +190,7 @@ static bool rtl88e_phy_config_rf_with_headerfile(struct adapter *adapt) for (i = 0; i < array_len; i += 2) { u32 v1 = array[i]; - u32 v2 = array[i+1]; + u32 v2 = array[i + 1]; if (v1 < 0xCDCDCDCD) { rtl8188e_config_rf_reg(adapt, v1, v2); diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c index 7646167a0b36..371e746915dd 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c @@ -113,24 +113,24 @@ void rtw_hal_add_ra_tid(struct adapter *pAdapter, u32 bitmap, u8 arg, u8 rssi_le struct odm_dm_struct *odmpriv = &pAdapter->HalData->odmpriv; u8 macid, init_rate, raid, shortGIrate = false; - macid = arg&0x1f; + macid = arg & 0x1f; - raid = (bitmap>>28) & 0x0f; + raid = (bitmap >> 28) & 0x0f; bitmap &= 0x0fffffff; if (rssi_level != DM_RATR_STA_INIT) bitmap = ODM_Get_Rate_Bitmap(odmpriv, macid, bitmap, rssi_level); - bitmap |= ((raid<<28)&0xf0000000); + bitmap |= ((raid << 28) & 0xf0000000); - init_rate = get_highest_rate_idx(bitmap&0x0fffffff)&0x3f; + init_rate = get_highest_rate_idx(bitmap & 0x0fffffff) & 0x3f; shortGIrate = (arg & BIT(5)) ? true : false; if (shortGIrate) init_rate |= BIT(6); - raid = (bitmap>>28) & 0x0f; + raid = (bitmap >> 28) & 0x0f; bitmap &= 0x0fffffff; @@ -172,7 +172,7 @@ void rtl8188e_set_FwPwrMode_cmd(struct adapter *adapt, u8 Mode) break; } - H2CSetPwrMode.SmartPS_RLBM = (((pwrpriv->smart_ps<<4)&0xf0) | (RLBM & 0x0f)); + H2CSetPwrMode.SmartPS_RLBM = (((pwrpriv->smart_ps << 4) & 0xf0) | (RLBM & 0x0f)); H2CSetPwrMode.AwakeInterval = 1; @@ -239,9 +239,9 @@ static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength) pframe += 2; pktlen += 2; - if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) { + if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) { pktlen += cur_network->ie_length - sizeof(struct ndis_802_11_fixed_ie); - memcpy(pframe, cur_network->ies+sizeof(struct ndis_802_11_fixed_ie), pktlen); + memcpy(pframe, cur_network->ies + sizeof(struct ndis_802_11_fixed_ie), pktlen); goto _ConstructBeacon; } @@ -258,7 +258,7 @@ static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength) /* DS parameter set */ pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen); - if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) { + if ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) { u32 ATIMWindow; /* IBSS Parameter Set... */ ATIMWindow = 0; @@ -473,7 +473,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished) /* 3 (2) ps-poll *1 page */ RsvdPageLoc.LocPsPoll = PageNum; ConstructPSPoll(adapt, &ReservedPagePacket[BufIndex], &PSPollLength); - rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], PSPollLength, true, false); + rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex - TxDescLen], PSPollLength, true, false); PageNeed = (u8)PageNum_128(TxDescLen + PSPollLength); PageNum += PageNeed; @@ -483,7 +483,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished) /* 3 (3) null data * 1 page */ RsvdPageLoc.LocNullData = PageNum; ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex], &NullDataLength, pnetwork->MacAddress, false, 0, 0, false); - rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], NullDataLength, false, false); + rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex - TxDescLen], NullDataLength, false, false); PageNeed = (u8)PageNum_128(TxDescLen + NullDataLength); PageNum += PageNeed; @@ -493,7 +493,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished) /* 3 (4) probe response * 1page */ RsvdPageLoc.LocProbeRsp = PageNum; ConstructProbeRsp(adapt, &ReservedPagePacket[BufIndex], &ProbeRspLength, pnetwork->MacAddress, false); - rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], ProbeRspLength, false, false); + rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex - TxDescLen], ProbeRspLength, false, false); PageNeed = (u8)PageNum_128(TxDescLen + ProbeRspLength); PageNum += PageNeed; @@ -504,7 +504,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished) RsvdPageLoc.LocQosNull = PageNum; ConstructNullFunctionData(adapt, &ReservedPagePacket[BufIndex], &QosNullLength, pnetwork->MacAddress, true, 0, 0, false); - rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex-TxDescLen], QosNullLength, false, false); + rtl8188e_fill_fake_txdesc(adapt, &ReservedPagePacket[BufIndex - TxDescLen], QosNullLength, false, false); PageNeed = (u8)PageNum_128(TxDescLen + QosNullLength); PageNum += PageNeed; @@ -546,17 +546,17 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) if (mstatus == 1) { /* We should set AID, correct TSF, HW seq enable before set JoinBssReport to Fw in 88/92C. */ /* Suggested by filen. Added by tynli. */ - usb_write16(adapt, REG_BCN_PSR_RPT, (0xC000|pmlmeinfo->aid)); + usb_write16(adapt, REG_BCN_PSR_RPT, (0xC000 | pmlmeinfo->aid)); /* Do not set TSF again here or vWiFi beacon DMA INT will not work. */ /* Set REG_CR bit 8. DMA beacon by SW. */ haldata->RegCR_1 |= BIT(0); - usb_write8(adapt, REG_CR+1, haldata->RegCR_1); + usb_write8(adapt, REG_CR + 1, haldata->RegCR_1); /* Disable Hw protection for a time which revserd for Hw sending beacon. */ /* Fix download reserved page packet fail that access collision with the protection time. */ /* 2010.05.11. Added by tynli. */ - usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(3))); + usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) & (~BIT(3))); usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(4)); if (haldata->RegFwHwTxQCtrl & BIT(6)) { @@ -565,7 +565,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) } /* Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame. */ - usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl&(~BIT(6)))); + usb_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl & (~BIT(6)))); haldata->RegFwHwTxQCtrl &= (~BIT(6)); /* Clear beacon valid check bit. */ @@ -582,7 +582,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) /* check rsvd page download OK. */ rtw_hal_get_hwreg(adapt, HW_VAR_BCN_VALID, (u8 *)(&bcn_valid)); poll++; - } while (!bcn_valid && (poll%10) != 0 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped); + } while (!bcn_valid && (poll % 10) != 0 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped); } while (!bcn_valid && DLBcnCount <= 100 && !adapt->bSurpriseRemoved && !adapt->bDriverStopped); if (adapt->bSurpriseRemoved || adapt->bDriverStopped) @@ -600,7 +600,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) /* Enable Bcn */ usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(3)); - usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(4))); + usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) & (~BIT(4))); /* To make sure that if there exists an adapter which would like to send beacon. */ /* If exists, the origianl value of 0x422[6] will be 1, we should check this to */ @@ -608,7 +608,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) /* the beacon cannot be sent by HW. */ /* 2010.06.23. Added by tynli. */ if (bSendBeacon) { - usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl | BIT(6))); + usb_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl | BIT(6))); haldata->RegFwHwTxQCtrl |= BIT(6); } @@ -621,6 +621,6 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus) /* Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli. */ /* Clear CR[8] or beacon packet will not be send to TxBuf anymore. */ haldata->RegCR_1 &= (~BIT(0)); - usb_write8(adapt, REG_CR+1, haldata->RegCR_1); + usb_write8(adapt, REG_CR + 1, haldata->RegCR_1); } } diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c index 57ae0e83dd3e..740004d71a15 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c @@ -22,7 +22,7 @@ void iol_mode_enable(struct adapter *padapter, u8 enable) if (enable) { /* Enable initial offload */ reg_0xf0 = usb_read8(padapter, REG_SYS_CFG); - usb_write8(padapter, REG_SYS_CFG, reg_0xf0|SW_OFFLOAD_EN); + usb_write8(padapter, REG_SYS_CFG, reg_0xf0 | SW_OFFLOAD_EN); if (!padapter->bFWReady) { DBG_88E("bFWReady == false call reset 8051...\n"); @@ -42,9 +42,9 @@ s32 iol_execute(struct adapter *padapter, u8 control) u8 reg_0x88 = 0; unsigned long start = 0; - control = control&0x0f; + control = control & 0x0f; reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0); - usb_write8(padapter, REG_HMEBOX_E0, reg_0x88|control); + usb_write8(padapter, REG_HMEBOX_E0, reg_0x88 | control); start = jiffies; while ((reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0)) & control && @@ -54,7 +54,7 @@ s32 iol_execute(struct adapter *padapter, u8 control) reg_0x88 = usb_read8(padapter, REG_HMEBOX_E0); status = (reg_0x88 & control) ? _FAIL : _SUCCESS; - if (reg_0x88 & control<<4) + if (reg_0x88 & control << 4) status = _FAIL; return status; } @@ -64,7 +64,7 @@ static s32 iol_InitLLTTable(struct adapter *padapter, u8 txpktbuf_bndy) s32 rst = _SUCCESS; iol_mode_enable(padapter, 1); - usb_write8(padapter, REG_TDECTRL+1, txpktbuf_bndy); + usb_write8(padapter, REG_TDECTRL + 1, txpktbuf_bndy); rst = iol_execute(padapter, CMD_INIT_LLT); iol_mode_enable(padapter, 0); return rst; @@ -92,9 +92,9 @@ void _8051Reset88E(struct adapter *padapter) { u8 u1bTmp; - u1bTmp = usb_read8(padapter, REG_SYS_FUNC_EN+1); - usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp&(~BIT(2))); - usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp|(BIT(2))); + u1bTmp = usb_read8(padapter, REG_SYS_FUNC_EN + 1); + usb_write8(padapter, REG_SYS_FUNC_EN + 1, u1bTmp & (~BIT(2))); + usb_write8(padapter, REG_SYS_FUNC_EN + 1, u1bTmp | (BIT(2))); DBG_88E("=====> _8051Reset88E(): 8051 reset success .\n"); } @@ -122,7 +122,7 @@ void rtw_hal_read_chip_version(struct adapter *padapter) value32 = usb_read32(padapter, REG_SYS_CFG); ChipVersion.ChipType = ((value32 & RTL_ID) ? TEST_CHIP : NORMAL_CHIP); ChipVersion.VendorType = ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : CHIP_VENDOR_TSMC); - ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK)>>CHIP_VER_RTL_SHIFT; /* IC version (CUT) */ + ChipVersion.CUTVersion = (value32 & CHIP_VER_RTL_MASK) >> CHIP_VER_RTL_SHIFT; /* IC version (CUT) */ dump_chip_info(ChipVersion); @@ -163,10 +163,10 @@ void rtw_hal_notch_filter(struct adapter *adapter, bool enable) { if (enable) { DBG_88E("Enable notch filter\n"); - usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) | BIT(1)); + usb_write8(adapter, rOFDM0_RxDSP + 1, usb_read8(adapter, rOFDM0_RxDSP + 1) | BIT(1)); } else { DBG_88E("Disable notch filter\n"); - usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) & ~BIT(1)); + usb_write8(adapter, rOFDM0_RxDSP + 1, usb_read8(adapter, rOFDM0_RxDSP + 1) & ~BIT(1)); } } @@ -308,7 +308,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (pwrInfo24G->IndexCCK_Base[rfPath][group] == 0xFF) pwrInfo24G->IndexCCK_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; } - for (group = 0; group < MAX_CHNL_GROUP_24G-1; group++) { + for (group = 0; group < MAX_CHNL_GROUP_24G - 1; group++) { pwrInfo24G->IndexBW40_Base[rfPath][group] = PROMContent[eeAddr++]; if (pwrInfo24G->IndexBW40_Base[rfPath][group] == 0xFF) pwrInfo24G->IndexBW40_Base[rfPath][group] = EEPROM_DEFAULT_24G_INDEX; @@ -319,7 +319,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_24G_HT20_DIFF; } else { - pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; + pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0xf0) >> 4; if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0; } @@ -327,7 +327,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_24G_OFDM_DIFF; } else { - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); + pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0x0f); if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0; } @@ -337,7 +337,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->BW40_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; } else { - pwrInfo24G->BW40_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; + pwrInfo24G->BW40_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0xf0) >> 4; if (pwrInfo24G->BW40_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->BW40_Diff[rfPath][TxCount] |= 0xF0; } @@ -345,7 +345,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; } else { - pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); + pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0x0f); if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0; } @@ -354,7 +354,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; } else { - pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4; + pwrInfo24G->OFDM_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0xf0) >> 4; if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0; } @@ -362,7 +362,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G, if (PROMContent[eeAddr] == 0xFF) { pwrInfo24G->CCK_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF; } else { - pwrInfo24G->CCK_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f); + pwrInfo24G->CCK_Diff[rfPath][TxCount] = (PROMContent[eeAddr] & 0x0f); if (pwrInfo24G->CCK_Diff[rfPath][TxCount] & BIT(3)) /* 4bit sign number to 8 bit sign number */ pwrInfo24G->CCK_Diff[rfPath][TxCount] |= 0xF0; } @@ -450,9 +450,9 @@ void Hal_ReadTxPowerInfo88E(struct adapter *padapter, u8 *PROMContent, bool Auto /* 2010/10/19 MH Add Regulator recognize for CU. */ if (!AutoLoadFail) { - pHalData->EEPROMRegulatory = (PROMContent[EEPROM_RF_BOARD_OPTION_88E]&0x7); /* bit0~2 */ + pHalData->EEPROMRegulatory = (PROMContent[EEPROM_RF_BOARD_OPTION_88E] & 0x7); /* bit0~2 */ if (PROMContent[EEPROM_RF_BOARD_OPTION_88E] == 0xFF) - pHalData->EEPROMRegulatory = (EEPROM_DEFAULT_BOARD_OPTION&0x7); /* bit0~2 */ + pHalData->EEPROMRegulatory = (EEPROM_DEFAULT_BOARD_OPTION & 0x7); /* bit0~2 */ } else { pHalData->EEPROMRegulatory = 0; } @@ -532,9 +532,9 @@ void Hal_ReadAntennaDiversity88E(struct adapter *pAdapter, u8 *PROMContent, bool if (!AutoLoadFail) { /* Antenna Diversity setting. */ if (registry_par->antdiv_cfg == 2) { /* 2:By EFUSE */ - pHalData->AntDivCfg = (PROMContent[EEPROM_RF_BOARD_OPTION_88E]&0x18)>>3; + pHalData->AntDivCfg = (PROMContent[EEPROM_RF_BOARD_OPTION_88E] & 0x18) >> 3; if (PROMContent[EEPROM_RF_BOARD_OPTION_88E] == 0xFF) - pHalData->AntDivCfg = (EEPROM_DEFAULT_BOARD_OPTION&0x18)>>3; + pHalData->AntDivCfg = (EEPROM_DEFAULT_BOARD_OPTION & 0x18) >> 3; } else { pHalData->AntDivCfg = registry_par->antdiv_cfg; /* 0:OFF , 1:ON, 2:By EFUSE */ } diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c b/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c index 0a900827c4fc..7d0135fde795 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c @@ -182,7 +182,7 @@ void update_recvframe_phyinfo_88e(struct recv_frame *precvframe, rtl8188e_process_phy_info(padapter, precvframe); } } else if (pkt_info.bPacketToSelf || pkt_info.bPacketBeacon) { - if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) { + if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) { if (psta) precvframe->psta = psta; } diff --git a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c index 2808f2b119bf..7d315bd438d4 100644 --- a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c +++ b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c @@ -58,12 +58,12 @@ void rtl8188e_fill_fake_txdesc(struct adapter *adapt, u8 *desc, u32 BufferLen, u /* offset 0 */ ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG); /* own, bFirstSeg, bLastSeg; */ - ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000); /* 32 bytes for TX Desc */ + ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00ff0000); /* 32 bytes for TX Desc */ - ptxdesc->txdw0 |= cpu_to_le32(BufferLen&0x0000ffff); /* Buffer size + command header */ + ptxdesc->txdw0 |= cpu_to_le32(BufferLen & 0x0000ffff); /* Buffer size + command header */ /* offset 4 */ - ptxdesc->txdw1 |= cpu_to_le32((QSLT_MGNT<<QSEL_SHT)&0x00001f00); /* Fixed queue of Mgnt queue */ + ptxdesc->txdw1 |= cpu_to_le32((QSLT_MGNT << QSEL_SHT) & 0x00001f00); /* Fixed queue of Mgnt queue */ /* Set NAVUSEHDR to prevent Ps-poll AId filed to be changed to error vlaue by Hw. */ if (ispspoll) { @@ -91,16 +91,16 @@ static void fill_txdesc_sectype(struct pkt_attrib *pattrib, struct tx_desc *ptxd /* SEC_TYPE : 0:NO_ENC,1:WEP40/TKIP,2:WAPI,3:AES */ case _WEP40_: case _WEP104_: - ptxdesc->txdw1 |= cpu_to_le32((0x01<<SEC_TYPE_SHT)&0x00c00000); + ptxdesc->txdw1 |= cpu_to_le32((0x01 << SEC_TYPE_SHT) & 0x00c00000); ptxdesc->txdw2 |= cpu_to_le32(0x7 << AMPDU_DENSITY_SHT); break; case _TKIP_: case _TKIP_WTMIC_: - ptxdesc->txdw1 |= cpu_to_le32((0x01<<SEC_TYPE_SHT)&0x00c00000); + ptxdesc->txdw1 |= cpu_to_le32((0x01 << SEC_TYPE_SHT) & 0x00c00000); ptxdesc->txdw2 |= cpu_to_le32(0x7 << AMPDU_DENSITY_SHT); break; case _AES_: - ptxdesc->txdw1 |= cpu_to_le32((0x03<<SEC_TYPE_SHT)&0x00c00000); + ptxdesc->txdw1 |= cpu_to_le32((0x03 << SEC_TYPE_SHT) & 0x00c00000); ptxdesc->txdw2 |= cpu_to_le32(0x7 << AMPDU_DENSITY_SHT); break; case _NO_PRIVACY_: @@ -127,7 +127,7 @@ static void fill_txdesc_vcs(struct pkt_attrib *pattrib, __le32 *pdw) *pdw |= cpu_to_le32(HW_RTS_EN); /* Set RTS BW */ if (pattrib->ht_en) { - *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(27)) : 0; + *pdw |= (pattrib->bwmode & HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(27)) : 0; if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) *pdw |= cpu_to_le32((0x01 << 28) & 0x30000000); @@ -144,7 +144,7 @@ static void fill_txdesc_vcs(struct pkt_attrib *pattrib, __le32 *pdw) static void fill_txdesc_phy(struct pkt_attrib *pattrib, __le32 *pdw) { if (pattrib->ht_en) { - *pdw |= (pattrib->bwmode&HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(25)) : 0; + *pdw |= (pattrib->bwmode & HT_CHANNEL_WIDTH_40) ? cpu_to_le32(BIT(25)) : 0; if (pattrib->ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER) *pdw |= cpu_to_le32((0x01 << DATA_SC_SHT) & 0x003f0000); @@ -171,7 +171,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag if (adapt->registrypriv.mp_mode == 0) { if ((!bagg_pkt) && (urb_zero_packet_chk(adapt, sz) == 0)) { - ptxdesc = (struct tx_desc *)(pmem+PACKET_OFFSET_SZ); + ptxdesc = (struct tx_desc *)(pmem + PACKET_OFFSET_SZ); pull = 1; } } @@ -263,11 +263,11 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag ptxdesc->txdw4 |= cpu_to_le32(BIT(24));/* DATA_SHORT */ ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate(pmlmeext->tx_rate)); } - } else if ((pxmitframe->frame_tag&0x0f) == MGNT_FRAMETAG) { + } else if ((pxmitframe->frame_tag & 0x0f) == MGNT_FRAMETAG) { /* offset 4 */ ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id & 0x3f); - qsel = (uint)(pattrib->qsel&0x0000001f); + qsel = (uint)(pattrib->qsel & 0x0000001f); ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00); ptxdesc->txdw1 |= cpu_to_le32((pattrib->raid << RATE_ID_SHT) & 0x000f0000); @@ -278,7 +278,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag ptxdesc->txdw2 |= cpu_to_le32(BIT(19)); /* offset 12 */ - ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<SEQ_SHT)&0x0FFF0000); + ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum << SEQ_SHT) & 0x0FFF0000); /* offset 20 */ ptxdesc->txdw5 |= cpu_to_le32(RTY_LMT_EN);/* retry limit enable */ @@ -288,7 +288,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag ptxdesc->txdw5 |= cpu_to_le32(0x00300000);/* retry limit = 12 */ ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate(pmlmeext->tx_rate)); - } else if ((pxmitframe->frame_tag&0x0f) == TXAGG_FRAMETAG) { + } else if ((pxmitframe->frame_tag & 0x0f) == TXAGG_FRAMETAG) { DBG_88E("pxmitframe->frame_tag == TXAGG_FRAMETAG\n"); } else { DBG_88E("pxmitframe->frame_tag = %d\n", pxmitframe->frame_tag); @@ -301,7 +301,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag /* offset 8 */ /* offset 12 */ - ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum<<SEQ_SHT)&0x0fff0000); + ptxdesc->txdw3 |= cpu_to_le32((pattrib->seqnum << SEQ_SHT) & 0x0fff0000); /* offset 20 */ ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate(pmlmeext->tx_rate)); @@ -466,7 +466,7 @@ bool rtl8188eu_xmitframe_complete(struct adapter *adapt, /* 3 2. aggregate same priority and same DA(AP or STA) frames */ pfirstframe = pxmitframe; - len = xmitframe_need_length(pfirstframe) + TXDESC_SIZE + (pfirstframe->pkt_offset*PACKET_OFFSET_SZ); + len = xmitframe_need_length(pfirstframe) + TXDESC_SIZE + (pfirstframe->pkt_offset * PACKET_OFFSET_SZ); pbuf_tail = len; pbuf = round_up(pbuf_tail, 8); @@ -517,7 +517,7 @@ bool rtl8188eu_xmitframe_complete(struct adapter *adapt, pxmitframe->agg_num = 0; /* not first frame of aggregation */ pxmitframe->pkt_offset = 0; /* not first frame of aggregation, no need to reserve offset */ - len = xmitframe_need_length(pxmitframe) + TXDESC_SIZE + (pxmitframe->pkt_offset*PACKET_OFFSET_SZ); + len = xmitframe_need_length(pxmitframe) + TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ); if (round_up(pbuf + len, 8) > MAX_XMITBUF_SZ) { pxmitframe->agg_num = 1; diff --git a/drivers/staging/rtl8188eu/include/rtw_xmit.h b/drivers/staging/rtl8188eu/include/rtw_xmit.h index ba7e15fbde72..b9f11ef327e7 100644 --- a/drivers/staging/rtl8188eu/include/rtw_xmit.h +++ b/drivers/staging/rtl8188eu/include/rtw_xmit.h @@ -112,7 +112,7 @@ struct pkt_attrib { u32 last_txcmdsz; u8 nr_frags; u8 encrypt; /* when 0 indicate no encrypt. when non-zero, - * indicate the encrypt algorith + * indicate the encrypt algorithm */ u8 iv_len; u8 icv_len; diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c index ba53959e1303..9a89791720e0 100644 --- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c @@ -193,12 +193,12 @@ static char *translate_scan(struct adapter *padapter, /*Add basic and extended rates */ max_rate = 0; p = custom; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); while (pnetwork->network.SupportedRates[i] != 0) { rate = pnetwork->network.SupportedRates[i]&0x7F; if (rate > max_rate) max_rate = rate; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); i++; } diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c index 69d4b1d66b6f..4d6d0347ab8e 100644 --- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c +++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c @@ -26,18 +26,17 @@ void _rtw_init_queue(struct __queue *pqueue) struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv) { - struct net_device *pnetdev; + struct net_device *netdev; struct rtw_netdev_priv_indicator *pnpi; - pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4); - if (!pnetdev) - goto RETURN; + netdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4); + if (!netdev) + return NULL; - pnpi = netdev_priv(pnetdev); + pnpi = netdev_priv(netdev); pnpi->priv = old_priv; -RETURN: - return pnetdev; + return netdev; } void rtw_free_netdev(struct net_device *netdev) @@ -45,18 +44,15 @@ void rtw_free_netdev(struct net_device *netdev) struct rtw_netdev_priv_indicator *pnpi; if (!netdev) - goto RETURN; + return; pnpi = netdev_priv(netdev); if (!pnpi->priv) - goto RETURN; + return; vfree(pnpi->priv); free_netdev(netdev); - -RETURN: - return; } void rtw_buf_free(u8 **buf, u32 *buf_len) diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c index 845c8817281c..f7f09c0d273f 100644 --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c @@ -32,6 +32,7 @@ static const struct usb_device_id rtw_usb_id_tbl[] = { /****** 8188EUS ********/ {USB_DEVICE(0x056e, 0x4008)}, /* Elecom WDC-150SU2M */ {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */ + {USB_DEVICE(0x0B05, 0x18F0)}, /* ASUS USB-N10 Nano B1 */ {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */ {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */ {USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */ diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c index 980b850d729a..ddcd7885d190 100644 --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c @@ -304,7 +304,7 @@ static void _rtl92e_read_eeprom_info(struct net_device *dev) u16 i, usValue, IC_Version; u16 EEPROMId; - RT_TRACE(COMP_INIT, "====> _rtl92e_read_eeprom_info\n"); + RT_TRACE(COMP_INIT, "====> %s\n", __func__); EEPROMId = rtl92e_eeprom_read(dev, 0); if (EEPROMId != RTL8190_EEPROM_ID) { @@ -1354,8 +1354,8 @@ static u8 _rtl92e_rate_hw_to_mgn(bool bIsHT, u8 rate) default: RT_TRACE(COMP_RECV, - "_rtl92e_rate_hw_to_mgn(): Non supportedRate [%x], bIsHT = %d!!!\n", - rate, bIsHT); + "%s: Non supportedRate [%x], bIsHT = %d!!!\n", + __func__, rate, bIsHT); break; } @@ -1415,8 +1415,8 @@ static u8 _rtl92e_rate_hw_to_mgn(bool bIsHT, u8 rate) default: RT_TRACE(COMP_RECV, - "_rtl92e_rate_hw_to_mgn(): Non supported Rate [%x], bIsHT = %d!!!\n", - rate, bIsHT); + "%s: Non supported Rate [%x], bIsHT = %d!!!\n", + __func__, rate, bIsHT); break; } } diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c index 7d78f16efc1d..411138102948 100644 --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c @@ -1124,14 +1124,14 @@ static void _rtl92e_cck_tx_power_track_bw_switch_thermal(struct net_device *dev) priv->Record_CCK_20Mindex = 6; priv->CCK_index = priv->Record_CCK_20Mindex; RT_TRACE(COMP_POWER_TRACKING, - "20MHz, _rtl92e_cck_tx_power_track_bw_switch_thermal(),CCK_index = %d\n", + "20MHz, %s,CCK_index = %d\n", __func__, priv->CCK_index); break; case HT_CHANNEL_WIDTH_20_40: priv->CCK_index = priv->Record_CCK_40Mindex; RT_TRACE(COMP_POWER_TRACKING, - "40MHz, _rtl92e_cck_tx_power_track_bw_switch_thermal(), CCK_index = %d\n", + "40MHz, %s, CCK_index = %d\n", __func__, priv->CCK_index); break; } @@ -1155,7 +1155,7 @@ static void _rtl92e_set_bw_mode_work_item(struct net_device *dev) u8 regBwOpMode; RT_TRACE(COMP_SWBW, - "==>_rtl92e_set_bw_mode_work_item() Switch to %s bandwidth\n", + "==>%s Switch to %s bandwidth\n", __func__, priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 ? "20MHz" : "40MHz"); @@ -1416,15 +1416,14 @@ static bool _rtl92e_set_rf_power_state(struct net_device *dev, if (priv->SetRFPowerStateInProgress) return false; - RT_TRACE(COMP_PS, "===========> _rtl92e_set_rf_power_state()!\n"); + RT_TRACE(COMP_PS, "===========> %s!\n", __func__); priv->SetRFPowerStateInProgress = true; switch (priv->rf_chip) { case RF_8256: switch (eRFPowerState) { case eRfOn: - RT_TRACE(COMP_PS, - "_rtl92e_set_rf_power_state() eRfOn!\n"); + RT_TRACE(COMP_PS, "%s eRfOn!\n", __func__); if ((priv->rtllib->eRFPowerState == eRfOff) && RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) { bool rtstatus; @@ -1490,10 +1489,8 @@ static bool _rtl92e_set_rf_power_state(struct net_device *dev, } if (i >= MAX_DOZE_WAITING_TIMES_9x) { - RT_TRACE(COMP_POWER, - "\n\n\n TimeOut!! _rtl92e_set_rf_power_state(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n", - MAX_DOZE_WAITING_TIMES_9x, - QueueID); + RT_TRACE(COMP_POWER, "\n\n\n TimeOut!! %s: eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n", + __func__, MAX_DOZE_WAITING_TIMES_9x, QueueID); break; } } @@ -1501,8 +1498,7 @@ static bool _rtl92e_set_rf_power_state(struct net_device *dev, break; case eRfOff: - RT_TRACE(COMP_PS, - "_rtl92e_set_rf_power_state() eRfOff/Sleep !\n"); + RT_TRACE(COMP_PS, "%s eRfOff/Sleep !\n", __func__); for (QueueID = 0, i = 0; QueueID < MAX_TX_QUEUE; ) { ring = &priv->tx_ring[QueueID]; @@ -1567,9 +1563,7 @@ static bool _rtl92e_set_rf_power_state(struct net_device *dev, } priv->SetRFPowerStateInProgress = false; - RT_TRACE(COMP_PS, - "<=========== _rtl92e_set_rf_power_state() bResult = %d!\n", - bResult); + RT_TRACE(COMP_PS, "<=========== %s bResult = %d!\n", __func__, bResult); return bResult; } @@ -1581,21 +1575,17 @@ bool rtl92e_set_rf_power_state(struct net_device *dev, bool bResult = false; RT_TRACE(COMP_PS, - "---------> rtl92e_set_rf_power_state(): eRFPowerState(%d)\n", - eRFPowerState); + "---------> %s: eRFPowerState(%d)\n", __func__, eRFPowerState); if (eRFPowerState == priv->rtllib->eRFPowerState && priv->bHwRfOffAction == 0) { - RT_TRACE(COMP_PS, - "<--------- rtl92e_set_rf_power_state(): discard the request for eRFPowerState(%d) is the same.\n", - eRFPowerState); + RT_TRACE(COMP_PS, "<--------- %s: discard the request for eRFPowerState(%d) is the same.\n", + __func__, eRFPowerState); return bResult; } bResult = _rtl92e_set_rf_power_state(dev, eRFPowerState); - RT_TRACE(COMP_PS, - "<--------- rtl92e_set_rf_power_state(): bResult(%d)\n", - bResult); + RT_TRACE(COMP_PS, "<--------- %s: bResult(%d)\n", __func__, bResult); return bResult; } diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c index 627ea1029509..c8506517cc8d 100644 --- a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c +++ b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c @@ -108,8 +108,8 @@ void rtl92e_set_key(struct net_device *dev, u8 EntryNo, u8 KeyIndex, } RT_TRACE(COMP_SEC, - "====>to rtl92e_set_key(), dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n", - dev, EntryNo, KeyIndex, KeyType, MacAddr); + "====>to %s, dev:%p, EntryNo:%d, KeyIndex:%d,KeyType:%d, MacAddr %pM\n", + __func__, dev, EntryNo, KeyIndex, KeyType, MacAddr); if (DefaultKey) usConfig |= BIT15 | (KeyType<<2); @@ -163,7 +163,7 @@ void rtl92e_cam_restore(struct net_device *dev) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - RT_TRACE(COMP_SEC, "rtl92e_cam_restore:\n"); + RT_TRACE(COMP_SEC, "%s:\n", __func__); if ((priv->rtllib->pairwise_key_type == KEY_TYPE_WEP40) || diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c index 11183b9f757a..d3664e508cbe 100644 --- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c +++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c @@ -145,21 +145,21 @@ bool rtl92e_set_rf_state(struct net_device *dev, unsigned long flag; RT_TRACE((COMP_PS | COMP_RF), - "===>rtl92e_set_rf_state(): StateToSet(%d)\n", StateToSet); + "===>%s: StateToSet(%d)\n", __func__, StateToSet); while (true) { spin_lock_irqsave(&priv->rf_ps_lock, flag); if (priv->RFChangeInProgress) { spin_unlock_irqrestore(&priv->rf_ps_lock, flag); RT_TRACE((COMP_PS | COMP_RF), - "rtl92e_set_rf_state(): RF Change in progress! Wait to set..StateToSet(%d).\n", - StateToSet); + "%s: RF Change in progress! Wait to set..StateToSet(%d).\n", + __func__, StateToSet); while (priv->RFChangeInProgress) { RFWaitCounter++; RT_TRACE((COMP_PS | COMP_RF), - "rtl92e_set_rf_state(): Wait 1 ms (%d times)...\n", - RFWaitCounter); + "%s: Wait 1 ms (%d times)...\n", + __func__, RFWaitCounter); mdelay(1); if (RFWaitCounter > 100) { @@ -195,8 +195,8 @@ bool rtl92e_set_rf_state(struct net_device *dev, bConnectBySSID = true; } else { RT_TRACE((COMP_PS | COMP_RF), - "rtl92e_set_rf_state - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", - priv->rtllib->RfOffReason, ChangeSource); + "%s - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", + __func__, priv->rtllib->RfOffReason, ChangeSource); } break; @@ -232,8 +232,8 @@ bool rtl92e_set_rf_state(struct net_device *dev, if (bActionAllowed) { RT_TRACE((COMP_PS | COMP_RF), - "rtl92e_set_rf_state(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", - StateToSet, priv->rtllib->RfOffReason); + "%s: Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", + __func__, StateToSet, priv->rtllib->RfOffReason); PHY_SetRFPowerState(dev, StateToSet); if (StateToSet == eRfOn) { @@ -245,15 +245,15 @@ bool rtl92e_set_rf_state(struct net_device *dev, } } else { RT_TRACE((COMP_PS | COMP_RF), - "rtl92e_set_rf_state(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", - StateToSet, ChangeSource, priv->rtllib->RfOffReason); + "%s: Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", + __func__, StateToSet, ChangeSource, priv->rtllib->RfOffReason); } spin_lock_irqsave(&priv->rf_ps_lock, flag); priv->RFChangeInProgress = false; spin_unlock_irqrestore(&priv->rf_ps_lock, flag); - RT_TRACE((COMP_PS | COMP_RF), "<===rtl92e_set_rf_state()\n"); + RT_TRACE((COMP_PS | COMP_RF), "<===%s\n", __func__); return bActionAllowed; } @@ -732,7 +732,7 @@ static int _rtl92e_sta_up(struct net_device *dev, bool is_silent_reset) struct r8192_priv *priv = rtllib_priv(dev); struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) (&priv->rtllib->PowerSaveControl); - bool init_status = true; + bool init_status; priv->bDriverIsGoingToUnload = false; priv->bdisable_nic = false; diff --git a/drivers/staging/rtl8192e/rtl819x_BAProc.c b/drivers/staging/rtl8192e/rtl819x_BAProc.c index 816d31c1d5c7..2d5e4a0330c6 100644 --- a/drivers/staging/rtl8192e/rtl819x_BAProc.c +++ b/drivers/staging/rtl8192e/rtl819x_BAProc.c @@ -119,8 +119,8 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst, } #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("rtllib_ADDBA(): ", DUMP_PREFIX_NONE, skb->data, - skb->len); + print_hex_dump_bytes("%s: ", DUMP_PREFIX_NONE, skb->data, + __func__, skb->len); #endif return skb; } @@ -170,8 +170,8 @@ static struct sk_buff *rtllib_DELBA(struct rtllib_device *ieee, u8 *dst, tag += 2; #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("rtllib_DELBA(): ", DUMP_PREFIX_NONE, skb->data, - skb->len); + print_hex_dump_bytes("%s: ", DUMP_PREFIX_NONE, skb->data, + __func__, skb->len); #endif return skb; } @@ -235,7 +235,7 @@ int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb) } #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("rtllib_rx_ADDBAReq(): ", DUMP_PREFIX_NONE, + print_hex_dump_bytes("%s: ", DUMP_PREFIX_NONE, __func__, skb->data, skb->len); #endif @@ -433,8 +433,8 @@ int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb) } #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("rtllib_rx_DELBA(): ", DUMP_PREFIX_NONE, skb->data, - skb->len); + print_hex_dump_bytes("%s: ", DUMP_PREFIX_NONE, skb->data, + __func__, skb->len); #endif delba = (struct rtllib_hdr_3addr *)skb->data; dst = (u8 *)(&delba->addr2[0]); diff --git a/drivers/staging/rtl8192e/rtl819x_HTProc.c b/drivers/staging/rtl8192e/rtl819x_HTProc.c index f02263af9624..d83d72594312 100644 --- a/drivers/staging/rtl8192e/rtl819x_HTProc.c +++ b/drivers/staging/rtl8192e/rtl819x_HTProc.c @@ -545,7 +545,7 @@ void HTOnAssocRsp(struct rtllib_device *ieee) #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("HTOnAssocRsp(): ", DUMP_PREFIX_NONE, + print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, pPeerHTCap, sizeof(struct ht_capab_ele)); #endif HTSetConnectBwMode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth), diff --git a/drivers/staging/rtl8192e/rtl819x_TSProc.c b/drivers/staging/rtl8192e/rtl819x_TSProc.c index 672bf0987943..47b2669a3a8e 100644 --- a/drivers/staging/rtl8192e/rtl819x_TSProc.c +++ b/drivers/staging/rtl8192e/rtl819x_TSProc.c @@ -440,7 +440,7 @@ void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr) { struct ts_common_info *pTS, *pTmpTS; - netdev_info(ieee->dev, "===========>RemovePeerTS, %pM\n", Addr); + netdev_info(ieee->dev, "===========>%s, %pM\n", __func__, Addr); list_for_each_entry_safe(pTS, pTmpTS, &ieee->Tx_TS_Pending_List, List) { if (memcmp(pTS->Addr, Addr, 6) == 0) { diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h index 328f410daa03..b84f00b8d18b 100644 --- a/drivers/staging/rtl8192e/rtllib.h +++ b/drivers/staging/rtl8192e/rtllib.h @@ -728,14 +728,14 @@ struct rtllib_pspoll_hdr { struct rtllib_hdr { __le16 frame_ctl; __le16 duration_id; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_1addr { __le16 frame_ctl; __le16 duration_id; u8 addr1[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_2addr { @@ -743,7 +743,7 @@ struct rtllib_hdr_2addr { __le16 duration_id; u8 addr1[ETH_ALEN]; u8 addr2[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_3addr { @@ -753,7 +753,7 @@ struct rtllib_hdr_3addr { u8 addr2[ETH_ALEN]; u8 addr3[ETH_ALEN]; __le16 seq_ctl; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_4addr { @@ -764,7 +764,7 @@ struct rtllib_hdr_4addr { u8 addr3[ETH_ALEN]; __le16 seq_ctl; u8 addr4[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_3addrqos { @@ -775,7 +775,7 @@ struct rtllib_hdr_3addrqos { u8 addr3[ETH_ALEN]; __le16 seq_ctl; __le16 qos_ctl; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_hdr_4addrqos { @@ -787,13 +787,13 @@ struct rtllib_hdr_4addrqos { __le16 seq_ctl; u8 addr4[ETH_ALEN]; __le16 qos_ctl; - u8 payload[0]; + u8 payload[]; } __packed; struct rtllib_info_element { u8 id; u8 len; - u8 data[0]; + u8 data[]; } __packed; struct rtllib_authentication { @@ -802,7 +802,7 @@ struct rtllib_authentication { __le16 transaction; __le16 status; /*challenge*/ - struct rtllib_info_element info_element[0]; + struct rtllib_info_element info_element[]; } __packed; struct rtllib_disauth { @@ -818,7 +818,7 @@ struct rtllib_disassoc { struct rtllib_probe_request { struct rtllib_hdr_3addr header; /* SSID, supported rates */ - struct rtllib_info_element info_element[0]; + struct rtllib_info_element info_element[]; } __packed; struct rtllib_probe_response { @@ -829,7 +829,7 @@ struct rtllib_probe_response { /* SSID, supported rates, FH params, DS params, * CF params, IBSS params, TIM (if beacon), RSN */ - struct rtllib_info_element info_element[0]; + struct rtllib_info_element info_element[]; } __packed; /* Alias beacon for probe_response */ @@ -840,7 +840,7 @@ struct rtllib_assoc_request_frame { __le16 capability; __le16 listen_interval; /* SSID, supported rates, RSN */ - struct rtllib_info_element info_element[0]; + struct rtllib_info_element info_element[]; } __packed; struct rtllib_assoc_response_frame { @@ -848,7 +848,7 @@ struct rtllib_assoc_response_frame { __le16 capability; __le16 status; __le16 aid; - struct rtllib_info_element info_element[0]; /* supported rates */ + struct rtllib_info_element info_element[]; /* supported rates */ } __packed; struct rtllib_txb { @@ -859,7 +859,7 @@ struct rtllib_txb { u16 reserved; __le16 frag_size; __le16 payload_size; - struct sk_buff *fragments[0]; + struct sk_buff *fragments[]; }; #define MAX_SUBFRAME_COUNT 64 @@ -1792,7 +1792,7 @@ struct rtllib_device { /* This must be the last item so that it points to the data * allocated beyond this structure by alloc_rtllib */ - u8 priv[0]; + u8 priv[]; }; #define IEEE_A (1<<0) diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c index 0bae0a0a4cbe..d31b5e1c8df4 100644 --- a/drivers/staging/rtl8192e/rtllib_rx.c +++ b/drivers/staging/rtl8192e/rtllib_rx.c @@ -2092,7 +2092,7 @@ int rtllib_parse_info_param(struct rtllib_device *ieee, MAX_RATES_LENGTH); for (i = 0; i < network->rates_len; i++) { network->rates[i] = info_element->data[i]; - p += snprintf(p, sizeof(rates_str) - + p += scnprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates[i]); if (rtllib_is_ofdm_rate @@ -2120,7 +2120,7 @@ int rtllib_parse_info_param(struct rtllib_device *ieee, MAX_RATES_EX_LENGTH); for (i = 0; i < network->rates_ex_len; i++) { network->rates_ex[i] = info_element->data[i]; - p += snprintf(p, sizeof(rates_str) - + p += scnprintf(p, sizeof(rates_str) - (p - rates_str), "%02X ", network->rates_ex[i]); if (rtllib_is_ofdm_rate diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c index 8cddb2e12dc4..79d7ad7c0a4a 100644 --- a/drivers/staging/rtl8192e/rtllib_tx.c +++ b/drivers/staging/rtl8192e/rtllib_tx.c @@ -241,7 +241,7 @@ static int rtllib_classify(struct sk_buff *skb, u8 bIsAmsdu) return 0; #ifdef VERBOSE_DEBUG - print_hex_dump_bytes("rtllib_classify(): ", DUMP_PREFIX_NONE, skb->data, + print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, skb->data, skb->len); #endif ip = ip_hdr(skb); diff --git a/drivers/staging/rtl8192e/rtllib_wx.c b/drivers/staging/rtl8192e/rtllib_wx.c index beb40967936a..7e7df50164fb 100644 --- a/drivers/staging/rtl8192e/rtllib_wx.c +++ b/drivers/staging/rtl8192e/rtllib_wx.c @@ -114,7 +114,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee, /* Add basic and extended rates */ max_rate = 0; p = custom; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); for (i = 0, j = 0; i < network->rates_len;) { if (j < network->rates_ex_len && ((network->rates_ex[j] & 0x7F) < @@ -124,12 +124,12 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee, rate = network->rates[i++] & 0x7F; if (rate > max_rate) max_rate = rate; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); } for (; j < network->rates_ex_len; j++) { rate = network->rates_ex[j] & 0x7F; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); if (rate > max_rate) max_rate = rate; @@ -226,7 +226,7 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee, */ iwe.cmd = IWEVCUSTOM; p = custom; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), " Last beacon: %lums ago", (jiffies - network->last_scanned) / (HZ / 100)); iwe.u.data.length = p - custom; diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h index 9576b647f6b1..39f4ddd86796 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h @@ -886,14 +886,14 @@ enum ieee80211_mfie { struct rtl_80211_hdr { __le16 frame_ctl; __le16 duration_id; - u8 payload[0]; + u8 payload[]; } __packed; struct rtl_80211_hdr_1addr { __le16 frame_ctl; __le16 duration_id; u8 addr1[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtl_80211_hdr_2addr { @@ -901,7 +901,7 @@ struct rtl_80211_hdr_2addr { __le16 duration_id; u8 addr1[ETH_ALEN]; u8 addr2[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtl_80211_hdr_3addr { @@ -911,7 +911,7 @@ struct rtl_80211_hdr_3addr { u8 addr2[ETH_ALEN]; u8 addr3[ETH_ALEN]; __le16 seq_ctl; - u8 payload[0]; + u8 payload[]; } __packed; struct rtl_80211_hdr_4addr { @@ -922,7 +922,7 @@ struct rtl_80211_hdr_4addr { u8 addr3[ETH_ALEN]; __le16 seq_ctl; u8 addr4[ETH_ALEN]; - u8 payload[0]; + u8 payload[]; } __packed; struct rtl_80211_hdr_3addrqos { @@ -951,7 +951,7 @@ struct rtl_80211_hdr_4addrqos { struct ieee80211_info_element { u8 id; u8 len; - u8 data[0]; + u8 data[]; } __packed; struct ieee80211_authentication { @@ -960,7 +960,7 @@ struct ieee80211_authentication { __le16 transaction; __le16 status; /*challenge*/ - struct ieee80211_info_element info_element[0]; + struct ieee80211_info_element info_element[]; } __packed; struct ieee80211_disassoc { @@ -971,7 +971,7 @@ struct ieee80211_disassoc { struct ieee80211_probe_request { struct rtl_80211_hdr_3addr header; /* SSID, supported rates */ - struct ieee80211_info_element info_element[0]; + struct ieee80211_info_element info_element[]; } __packed; struct ieee80211_probe_response { @@ -982,7 +982,7 @@ struct ieee80211_probe_response { /* SSID, supported rates, FH params, DS params, * CF params, IBSS params, TIM (if beacon), RSN */ - struct ieee80211_info_element info_element[0]; + struct ieee80211_info_element info_element[]; } __packed; /* Alias beacon for probe_response */ @@ -993,7 +993,7 @@ struct ieee80211_assoc_request_frame { __le16 capability; __le16 listen_interval; /* SSID, supported rates, RSN */ - struct ieee80211_info_element info_element[0]; + struct ieee80211_info_element info_element[]; } __packed; struct ieee80211_reassoc_request_frame { @@ -1002,7 +1002,7 @@ struct ieee80211_reassoc_request_frame { __le16 listen_interval; u8 current_ap[ETH_ALEN]; /* SSID, supported rates, RSN */ - struct ieee80211_info_element info_element[0]; + struct ieee80211_info_element info_element[]; } __packed; struct ieee80211_assoc_response_frame { @@ -1010,7 +1010,7 @@ struct ieee80211_assoc_response_frame { __le16 capability; __le16 status; __le16 aid; - struct ieee80211_info_element info_element[0]; /* supported rates */ + struct ieee80211_info_element info_element[]; /* supported rates */ } __packed; struct ieee80211_txb { @@ -1021,7 +1021,7 @@ struct ieee80211_txb { u16 reserved; __le16 frag_size; __le16 payload_size; - struct sk_buff *fragments[0]; + struct sk_buff *fragments[]; }; #define MAX_TX_AGG_COUNT 16 @@ -2007,7 +2007,7 @@ struct ieee80211_device { /* This must be the last item so that it points to the data * allocated beyond this structure by alloc_ieee80211 */ - u8 priv[0]; + u8 priv[]; }; #define IEEE_A (1<<0) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c index 6f4710171151..ffe624ed0c0c 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c @@ -388,20 +388,20 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) keyidx = pos[3]; if (!(keyidx & BIT(5))) { if (net_ratelimit()) { - printk(KERN_DEBUG "TKIP: received packet without ExtIV" + netdev_dbg(skb->dev, "TKIP: received packet without ExtIV" " flag from %pM\n", hdr->addr2); } return -2; } keyidx >>= 6; if (tkey->key_idx != keyidx) { - printk(KERN_DEBUG "TKIP: RX tkey->key_idx=%d frame " + netdev_dbg(skb->dev, "TKIP: RX tkey->key_idx=%d frame " "keyidx=%d priv=%p\n", tkey->key_idx, keyidx, priv); return -6; } if (!tkey->key_set) { if (net_ratelimit()) { - printk(KERN_DEBUG "TKIP: received packet from %pM" + netdev_dbg(skb->dev, "TKIP: received packet from %pM" " with keyid=%d that does not have a configured" " key\n", hdr->addr2, keyidx); } @@ -417,7 +417,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) if (iv32 < tkey->rx_iv32 || (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) { if (net_ratelimit()) { - printk(KERN_DEBUG "TKIP: replay detected: STA=%pM" + netdev_dbg(skb->dev, "TKIP: replay detected: STA=%pM" " previous TSC %08x%04x received TSC " "%08x%04x\n", hdr->addr2, tkey->rx_iv32, tkey->rx_iv16, iv32, iv16); @@ -445,7 +445,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) skcipher_request_zero(req); if (err) { if (net_ratelimit()) { - printk(KERN_DEBUG ": TKIP: failed to decrypt " + netdev_dbg(skb->dev, "TKIP: failed to decrypt " "received packet from %pM\n", hdr->addr2); } @@ -468,7 +468,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) tkey->rx_phase1_done = 0; } if (net_ratelimit()) { - printk(KERN_DEBUG "TKIP: ICV error detected: STA=" + netdev_dbg(skb->dev, "TKIP: ICV error detected: STA=" "%pM\n", hdr->addr2); } tkey->dot11RSNAStatsTKIPICVErrors++; @@ -559,7 +559,7 @@ static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len, void *pri hdr = (struct rtl_80211_hdr_4addr *)skb->data; if (skb_tailroom(skb) < 8 || skb->len < hdr_len) { - printk(KERN_DEBUG "Invalid packet for Michael MIC add " + netdev_dbg(skb->dev, "Invalid packet for Michael MIC add " "(tailroom=%d hdr_len=%d skb->len=%d)\n", skb_tailroom(skb), hdr_len, skb->len); return -1; @@ -628,10 +628,9 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx, struct rtl_80211_hdr_4addr *hdr; hdr = (struct rtl_80211_hdr_4addr *)skb->data; - printk(KERN_DEBUG "%s: Michael MIC verification failed for " + netdev_dbg(skb->dev, "Michael MIC verification failed for " "MSDU from %pM keyidx=%d\n", - skb->dev ? skb->dev->name : "N/A", hdr->addr2, - keyidx); + hdr->addr2, keyidx); if (skb->dev) ieee80211_michael_mic_failure(skb->dev, hdr, keyidx); tkey->dot11RSNAStatsTKIPLocalMICFailures++; diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c index aa9dab8a4ae8..a5a1b14f5a40 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c @@ -68,8 +68,7 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee) sizeof(struct ieee80211_network), GFP_KERNEL); if (!ieee->networks) { - printk(KERN_WARNING "%s: Out of memory allocating beacons\n", - ieee->dev->name); + netdev_warn(ieee->dev, "Out of memory allocating beacons\n"); return -ENOMEM; } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c index 90692db81b71..d8eb907ff301 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c @@ -131,7 +131,7 @@ static void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p) *tag++ = 0x00; *tag_p = tag; - printk(KERN_ALERT "This is enable turbo mode IE process\n"); + netdev_alert(ieee->dev, "This is enable turbo mode IE process\n"); } #endif @@ -1270,14 +1270,15 @@ static void ieee80211_associate_step2(struct ieee80211_device *ieee) static void ieee80211_associate_complete_wq(struct work_struct *work) { struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_complete_wq); - printk(KERN_INFO "Associated successfully\n"); + + netdev_info(ieee->dev, "Associated successfully\n"); if (ieee80211_is_54g(&ieee->current_network) && (ieee->modulation & IEEE80211_OFDM_MODULATION)) { ieee->rate = 108; - printk(KERN_INFO"Using G rates:%d\n", ieee->rate); + netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate); } else { ieee->rate = 22; - printk(KERN_INFO"Using B rates:%d\n", ieee->rate); + netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate); } if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { printk("Successfully associated, ht enabled\n"); @@ -1391,12 +1392,13 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE); ieee->current_network.ssid_len = tmp_ssid_len; - printk(KERN_INFO"Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d\n", - ieee->current_network.ssid, - ieee->current_network.channel, - ieee->current_network.qos_data.supported, - ieee->pHTInfo->bEnableHT, - ieee->current_network.bssht.bdSupportHT); + netdev_info(ieee->dev, + "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d\n", + ieee->current_network.ssid, + ieee->current_network.channel, + ieee->current_network.qos_data.supported, + ieee->pHTInfo->bEnableHT, + ieee->current_network.bssht.bdSupportHT); //ieee->pHTInfo->IOTAction = 0; HTResetIOTSetting(ieee->pHTInfo); @@ -1421,11 +1423,13 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee (ieee->modulation & IEEE80211_OFDM_MODULATION)) { ieee->rate = 108; ieee->SetWirelessMode(ieee->dev, IEEE_G); - printk(KERN_INFO"Using G rates\n"); + netdev_info(ieee->dev, + "Using G rates\n"); } else { ieee->rate = 22; ieee->SetWirelessMode(ieee->dev, IEEE_B); - printk(KERN_INFO"Using B rates\n"); + netdev_info(ieee->dev, + "Using B rates\n"); } memset(ieee->dot11HTOperationalRateSet, 0, 16); //HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); @@ -1622,7 +1626,7 @@ ieee80211_rx_assoc_rq(struct ieee80211_device *ieee, struct sk_buff *skb) if (assoc_rq_parse(skb, dest) != -1) ieee80211_resp_to_assoc_rq(ieee, dest); - printk(KERN_INFO"New client associated: %pM\n", dest); + netdev_info(ieee->dev, "New client associated: %pM\n", dest); //FIXME } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c index b1baaa18b129..f434a26cdb2f 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c @@ -459,8 +459,8 @@ int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee, else ieee->raw_tx = 0; - printk(KERN_INFO"raw TX is %s\n", - ieee->raw_tx ? "enabled" : "disabled"); + netdev_info(ieee->dev, "raw TX is %s\n", + ieee->raw_tx ? "enabled" : "disabled"); if (ieee->iw_mode == IW_MODE_MONITOR) { if (prev == 0 && ieee->raw_tx) { diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c index f0b6b8372f91..0ee054d82832 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c @@ -180,9 +180,8 @@ int ieee80211_encrypt_fragment( struct rtl_80211_hdr_3addrqos *header; header = (struct rtl_80211_hdr_3addrqos *)frag->data; - printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " - "TX packet to %pM\n", - ieee->dev->name, header->addr1); + netdev_dbg(ieee->dev, "TKIP countermeasures: dropped " + "TX packet to %pM\n", header->addr1); } return -1; } @@ -204,8 +203,8 @@ int ieee80211_encrypt_fragment( atomic_dec(&crypt->refcnt); if (res < 0) { - printk(KERN_INFO "%s: Encryption failed: len=%d.\n", - ieee->dev->name, frag->len); + netdev_info(ieee->dev, "Encryption failed: len=%d.\n", + frag->len); ieee->ieee_stats.tx_discards++; return -1; } @@ -557,16 +556,15 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) */ if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)) || ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) { - printk(KERN_WARNING "%s: No xmit handler.\n", - ieee->dev->name); + netdev_warn(ieee->dev, "No xmit handler.\n"); goto success; } if (likely(ieee->raw_tx == 0)) { if (unlikely(skb->len < SNAP_SIZE + sizeof(u16))) { - printk(KERN_WARNING "%s: skb too small (%d).\n", - ieee->dev->name, skb->len); + netdev_warn(ieee->dev, "skb too small (%d).\n", + skb->len); goto success; } @@ -685,8 +683,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) */ txb = ieee80211_alloc_txb(nr_frags, frag_size + ieee->tx_headroom, GFP_ATOMIC); if (unlikely(!txb)) { - printk(KERN_WARNING "%s: Could not allocate TXB\n", - ieee->dev->name); + netdev_warn(ieee->dev, "Could not allocate TXB\n"); goto failed; } txb->encrypted = encrypt; @@ -779,15 +776,14 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev) } } else { if (unlikely(skb->len < sizeof(struct rtl_80211_hdr_3addr))) { - printk(KERN_WARNING "%s: skb too small (%d).\n", - ieee->dev->name, skb->len); + netdev_warn(ieee->dev, "skb too small (%d).\n", + skb->len); goto success; } txb = ieee80211_alloc_txb(1, skb->len, GFP_ATOMIC); if (!txb) { - printk(KERN_WARNING "%s: Could not allocate TXB\n", - ieee->dev->name); + netdev_warn(ieee->dev, "Could not allocate TXB\n"); goto failed; } diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c index 33c596f9ec96..22373c0afebc 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c @@ -356,9 +356,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(dev, "could not initialize WEP: " + "load module ieee80211_crypt_wep\n"); return -EOPNOTSUPP; } *crypt = new_crypt; @@ -436,7 +435,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; diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c index 5cee1031a27c..3aabb401b15a 100644 --- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c +++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c @@ -380,7 +380,7 @@ bool GetTs( } IEEE80211_DEBUG(IEEE80211_DL_TS, "to init current TS, UP:%d, Dir:%d, addr:%pM\n", UP, Dir, Addr); - // Prepare TS Info releated field + // Prepare TS Info related field pTSInfo->uc_traffic_type = 0; // Traffic type: WMM is reserved in this field pTSInfo->uc_tsid = UP; // TSID pTSInfo->uc_direction = Dir; // Direction: if there is DirectLink, this need additional consideration. diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c index 89dd1fb0b38d..fcfb9024a83f 100644 --- a/drivers/staging/rtl8192u/r8192U_core.c +++ b/drivers/staging/rtl8192u/r8192U_core.c @@ -613,13 +613,13 @@ static void rtl8192_proc_init_one(struct net_device *dev) if (!dir) return; - proc_create_single("stats-rx", S_IFREG | S_IRUGO, dir, + proc_create_single("stats-rx", S_IFREG | 0444, dir, proc_get_stats_rx); - proc_create_single("stats-tx", S_IFREG | S_IRUGO, dir, + proc_create_single("stats-tx", S_IFREG | 0444, dir, proc_get_stats_tx); - proc_create_single("stats-ap", S_IFREG | S_IRUGO, dir, + proc_create_single("stats-ap", S_IFREG | 0444, dir, proc_get_stats_ap); - proc_create_single("registers", S_IFREG | S_IRUGO, dir, + proc_create_single("registers", S_IFREG | 0444, dir, proc_get_registers); } @@ -4877,50 +4877,50 @@ void EnableHWSecurityConfig8192(struct net_device *dev) write_nic_byte(dev, SECR, SECR_value); } -void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, - u8 *MacAddr, u8 DefaultKey, u32 *KeyContent) +void setKey(struct net_device *dev, u8 entryno, u8 keyindex, u16 keytype, + u8 *macaddr, u8 defaultkey, u32 *keycontent) { - u32 TargetCommand = 0; - u32 TargetContent = 0; - u16 usConfig = 0; + u32 target_command = 0; + u32 target_content = 0; + u16 us_config = 0; u8 i; - if (EntryNo >= TOTAL_CAM_ENTRY) - RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n"); + if (entryno >= TOTAL_CAM_ENTRY) + RT_TRACE(COMP_ERR, "cam entry exceeds in %s\n", __func__); RT_TRACE(COMP_SEC, - "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", - dev, EntryNo, KeyIndex, KeyType, MacAddr); + "====>to %s, dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", + __func__, dev, entryno, keyindex, keytype, macaddr); - if (DefaultKey) - usConfig |= BIT(15) | (KeyType << 2); + if (defaultkey) + us_config |= BIT(15) | (keytype << 2); else - usConfig |= BIT(15) | (KeyType << 2) | KeyIndex; + us_config |= BIT(15) | (keytype << 2) | keyindex; for (i = 0; i < CAM_CONTENT_COUNT; i++) { - TargetCommand = i + CAM_CONTENT_COUNT * EntryNo; - TargetCommand |= BIT(31) | BIT(16); + target_command = i + CAM_CONTENT_COUNT * entryno; + target_command |= BIT(31) | BIT(16); if (i == 0) { /* MAC|Config */ - TargetContent = (u32)(*(MacAddr + 0)) << 16 | - (u32)(*(MacAddr + 1)) << 24 | - (u32)usConfig; + target_content = (u32)(*(macaddr + 0)) << 16 | + (u32)(*(macaddr + 1)) << 24 | + (u32)us_config; - write_nic_dword(dev, WCAMI, TargetContent); - write_nic_dword(dev, RWCAM, TargetCommand); + write_nic_dword(dev, WCAMI, target_content); + write_nic_dword(dev, RWCAM, target_command); } else if (i == 1) { /* MAC */ - TargetContent = (u32)(*(MacAddr + 2)) | - (u32)(*(MacAddr + 3)) << 8 | - (u32)(*(MacAddr + 4)) << 16 | - (u32)(*(MacAddr + 5)) << 24; - write_nic_dword(dev, WCAMI, TargetContent); - write_nic_dword(dev, RWCAM, TargetCommand); + target_content = (u32)(*(macaddr + 2)) | + (u32)(*(macaddr + 3)) << 8 | + (u32)(*(macaddr + 4)) << 16 | + (u32)(*(macaddr + 5)) << 24; + write_nic_dword(dev, WCAMI, target_content); + write_nic_dword(dev, RWCAM, target_command); } else { /* Key Material */ - if (KeyContent) { + if (keycontent) { write_nic_dword(dev, WCAMI, - *(KeyContent + i - 2)); - write_nic_dword(dev, RWCAM, TargetCommand); + *(keycontent + i - 2)); + write_nic_dword(dev, RWCAM, target_command); } } } diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c index 0118edb0b9ab..100532598781 100644 --- a/drivers/staging/rtl8192u/r8192U_wx.c +++ b/drivers/staging/rtl8192u/r8192U_wx.c @@ -588,7 +588,7 @@ static int r8192_wx_set_enc(struct net_device *dev, hwkey); /* KeyContent */ } else { - printk("wrong type in WEP, not WEP40 and WEP104\n"); + netdev_warn(dev, "wrong type in WEP, not WEP40 and WEP104\n"); } } diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c index 555e52522be6..37b99cf4b35f 100644 --- a/drivers/staging/rtl8192u/r819xU_phy.c +++ b/drivers/staging/rtl8192u/r819xU_phy.c @@ -1531,7 +1531,7 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev) rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1); rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1); rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand, - priv->nCur40MhzPrimeSC>>1); + priv->nCur40MhzPrimeSC >> 1); rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0); rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00, priv->nCur40MhzPrimeSC); diff --git a/drivers/staging/rtl8712/Kconfig b/drivers/staging/rtl8712/Kconfig index b6dcda77db1f..c62747c90968 100644 --- a/drivers/staging/rtl8712/Kconfig +++ b/drivers/staging/rtl8712/Kconfig @@ -6,13 +6,16 @@ config R8712U select WEXT_PRIV select FW_LOADER help - This option adds the Realtek RTL8712 USB device such as the D-Link DWA-130. + This option adds the Realtek RTL8712 USB device such as the + D-Link DWA-130. + If built as a module, it will be called r8712u. config R8712_TX_AGGR bool "Realtek RTL8712U Transmit Aggregation code" depends on R8712U && BROKEN help - This option provides transmit aggregation for the Realtek RTL8712 USB device. + This option provides transmit aggregation for the Realtek + RTL8712 USB device. diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h index 8098f6905554..dabaa8fd34fb 100644 --- a/drivers/staging/rtl8712/ieee80211.h +++ b/drivers/staging/rtl8712/ieee80211.h @@ -535,7 +535,7 @@ struct ieee80211_info_element_hdr { struct ieee80211_info_element { u8 id; u8 len; - u8 data[0]; + u8 data[]; } __packed; /* @@ -597,7 +597,7 @@ struct ieee80211_txb { u16 reserved; u16 frag_size; u16 payload_size; - struct sk_buff *fragments[0]; + struct sk_buff *fragments[]; }; /* SWEEP TABLE ENTRIES NUMBER*/ diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h index 98d7fbfce1a5..254182a6ce8e 100644 --- a/drivers/staging/rtl8712/rtl871x_cmd.h +++ b/drivers/staging/rtl8712/rtl871x_cmd.h @@ -478,7 +478,7 @@ struct drvint_cmd_parm { unsigned char *pbuf; }; -/*------------------- Below are used for RF/BB tunning ---------------------*/ +/*------------------- Below are used for RF/BB tuning ---------------------*/ struct setantenna_parm { u8 tx_antset; diff --git a/drivers/staging/rtl8712/rtl871x_mp.c b/drivers/staging/rtl8712/rtl871x_mp.c index 1a39a96b726f..24020257bc58 100644 --- a/drivers/staging/rtl8712/rtl871x_mp.c +++ b/drivers/staging/rtl8712/rtl871x_mp.c @@ -44,9 +44,9 @@ static int init_mp_priv(struct mp_priv *pmp_priv) pmp_priv->pallocated_mp_xmitframe_buf = kmalloc(NR_MP_XMITFRAME * sizeof(struct mp_xmit_frame) + 4, GFP_ATOMIC); - if (!pmp_priv->pallocated_mp_xmitframe_buf) { + if (!pmp_priv->pallocated_mp_xmitframe_buf) return -ENOMEM; - } + pmp_priv->pmp_xmtframe_buf = pmp_priv->pallocated_mp_xmitframe_buf + 4 - ((addr_t)(pmp_priv->pallocated_mp_xmitframe_buf) & 3); diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.h b/drivers/staging/rtl8712/rtl871x_mp_ioctl.h index 64e2ae436625..59fa6664d868 100644 --- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.h +++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.h @@ -48,7 +48,7 @@ struct eeprom_rw_param { struct EFUSE_ACCESS_STRUCT { u16 start_addr; u16 cnts; - u8 data[0]; + u8 data[]; }; struct burst_rw_reg { @@ -324,7 +324,7 @@ struct mp_ioctl_handler { struct mp_ioctl_param { unsigned int subcode; unsigned int len; - unsigned char data[0]; + unsigned char data[]; }; #define GEN_MP_IOCTL_SUBCODE(code) _MP_IOCTL_ ## code ## _CMD_ diff --git a/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h b/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h index d479f739ff08..ca5072e11e22 100644 --- a/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h +++ b/drivers/staging/rtl8712/rtl871x_mp_phy_regdef.h @@ -30,7 +30,7 @@ /*--------------------------Define Parameters-------------------------------*/ /*============================================================ - * 8192S Regsiter offset definition + * 8192S Register offset definition *============================================================ * * diff --git a/drivers/staging/rtl8712/rtl871x_recv.h b/drivers/staging/rtl8712/rtl871x_recv.h index 0146a774e19d..e93f356ed2b0 100644 --- a/drivers/staging/rtl8712/rtl871x_recv.h +++ b/drivers/staging/rtl8712/rtl871x_recv.h @@ -53,7 +53,7 @@ struct rx_pkt_attrib { u8 privacy; /* in frame_ctrl field */ u8 bdecrypted; int hdrlen; /* the WLAN Header Len */ - int encrypt; /* 0 no encrypt. != 0 encrypt algorith */ + int encrypt; /* 0 no encrypt. != 0 encrypt algorithm */ int iv_len; int icv_len; int priority; @@ -105,7 +105,7 @@ struct recv_priv { u8 *precv_buf; /* 4 alignment */ struct __queue free_recv_buf_queue; u32 free_recv_buf_queue_cnt; - /* For the phy informatiom */ + /* For the phy information */ s8 rssi; u8 signal; u8 noise; diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c index 7117d16a30f9..a76e81330756 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ap.c +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c @@ -2417,7 +2417,7 @@ void stop_ap_mode(struct adapter *padapter) paclnode = LIST_CONTAINOR(plist, struct rtw_wlan_acl_node, list); plist = get_next(plist); - if (paclnode->valid == true) { + if (paclnode->valid) { paclnode->valid = false; list_del_init(&paclnode->list); diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c index 13a9b54b4561..efb5135ad743 100644 --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c @@ -194,14 +194,16 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv) pcmdpriv->rsp_buf = pcmdpriv->rsp_allocated_buf + 4 - ((SIZE_PTR)(pcmdpriv->rsp_allocated_buf) & 3); - pcmdpriv->cmd_issued_cnt = pcmdpriv->cmd_done_cnt = pcmdpriv->rsp_cnt = 0; + pcmdpriv->cmd_issued_cnt = 0; + pcmdpriv->cmd_done_cnt = 0; + pcmdpriv->rsp_cnt = 0; mutex_init(&pcmdpriv->sctx_mutex); exit: return res; } -static void c2h_wk_callback(_workitem *work); +static void c2h_wk_callback(_workitem * work); int rtw_init_evt_priv(struct evt_priv *pevtpriv) { /* allocate DMA-able/Non-Page memory for cmd_buf and rsp_buf */ @@ -360,11 +362,7 @@ exit: struct cmd_obj *rtw_dequeue_cmd(struct cmd_priv *pcmdpriv) { - struct cmd_obj *cmd_obj; - - cmd_obj = _rtw_dequeue_cmd(&pcmdpriv->cmd_queue); - - return cmd_obj; + return _rtw_dequeue_cmd(&pcmdpriv->cmd_queue); } void rtw_free_cmd_obj(struct cmd_obj *pcmd) @@ -520,7 +518,7 @@ post_process: rtw_free_cmd_obj(pcmd); } else { /* todo: !!! fill rsp_buf to pcmd->rsp if (pcmd->rsp!= NULL) */ - pcmd_callback(pcmd->padapter, pcmd);/* need conider that free cmd_obj in rtw_cmd_callback */ + pcmd_callback(pcmd->padapter, pcmd);/* need consider that free cmd_obj in rtw_cmd_callback */ } } else { RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("%s: cmdcode = 0x%x callback not defined!\n", __func__, pcmd->cmdcode)); @@ -989,7 +987,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_ memcpy(&psetstakey_para->key, &psecuritypriv->dot118021XGrpKey[psecuritypriv->dot118021XGrpKeyid].skey, 16); } - /* jeff: set this becasue at least sw key is ready */ + /* jeff: set this because at least sw key is ready */ padapter->securitypriv.busetkipkey = true; if (enqueue) { @@ -2138,7 +2136,8 @@ void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj * goto exit; } - psta->aid = psta->mac_id = passocsta_rsp->cam_id; + psta->aid = passocsta_rsp->cam_id; + psta->mac_id = passocsta_rsp->cam_id; spin_lock_bh(&pmlmepriv->lock); diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c index 3b8848182221..8794638468e6 100644 --- a/drivers/staging/rtl8723bs/core/rtw_efuse.c +++ b/drivers/staging/rtl8723bs/core/rtw_efuse.c @@ -43,9 +43,8 @@ Efuse_Read1ByteFromFakeContent( u16 Offset, u8 *Value) { - if (Offset >= EFUSE_MAX_HW_SIZE) { + if (Offset >= EFUSE_MAX_HW_SIZE) return false; - } /* DbgPrint("Read fake content, offset = %d\n", Offset); */ if (fakeEfuseBank == 0) *Value = fakeEfuseContent[Offset]; @@ -65,14 +64,12 @@ Efuse_Write1ByteToFakeContent( u16 Offset, u8 Value) { - if (Offset >= EFUSE_MAX_HW_SIZE) { + if (Offset >= EFUSE_MAX_HW_SIZE) return false; - } if (fakeEfuseBank == 0) fakeEfuseContent[Offset] = Value; - else { + else fakeBTEfuseContent[fakeEfuseBank-1][Offset] = Value; - } return true; } @@ -244,10 +241,8 @@ u16 Address) while (!(Bytetemp & 0x80)) { Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3); k++; - if (k == 1000) { - k = 0; + if (k == 1000) break; - } } return rtw_read8(Adapter, EFUSE_CTRL); } else @@ -271,8 +266,7 @@ bool bPseudoTest) /* DBG_871X("===> EFUSE_OneByteRead() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */ if (bPseudoTest) { - bResult = Efuse_Read1ByteFromFakeContent(padapter, addr, data); - return bResult; + return Efuse_Read1ByteFromFakeContent(padapter, addr, data); } /* <20130121, Kordan> For SMIC EFUSE specificatoin. */ @@ -324,8 +318,7 @@ bool bPseudoTest) /* DBG_871X("===> EFUSE_OneByteWrite() start, 0x34 = 0x%X\n", rtw_read32(padapter, EFUSE_TEST)); */ if (bPseudoTest) { - bResult = Efuse_Write1ByteToFakeContent(padapter, addr, data); - return bResult; + return Efuse_Write1ByteToFakeContent(padapter, addr, data); } diff --git a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c index 6018d877a8a6..ca98274ae390 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ieee80211.c +++ b/drivers/staging/rtl8723bs/core/rtw_ieee80211.c @@ -217,7 +217,7 @@ u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, u * rtw_ies_remove_ie - Find matching IEs and remove * @ies: Address of IEs to search * @ies_len: Pointer of length of ies, will update to new length - * @offset: The offset to start scarch + * @offset: The offset to start search * @eid: Element ID to match * @oui: OUI to match * @oui_len: OUI length diff --git a/drivers/staging/rtl8723bs/core/rtw_io.c b/drivers/staging/rtl8723bs/core/rtw_io.c index 57168578663a..c3f63f903547 100644 --- a/drivers/staging/rtl8723bs/core/rtw_io.c +++ b/drivers/staging/rtl8723bs/core/rtw_io.c @@ -37,7 +37,6 @@ jackson@realtek.com.tw u8 _rtw_read8(struct adapter *adapter, u32 addr) { - u8 r_val; /* struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue; */ struct io_priv *pio_priv = &adapter->iopriv; struct intf_hdl *pintfhdl = &(pio_priv->intf); @@ -45,8 +44,7 @@ u8 _rtw_read8(struct adapter *adapter, u32 addr) _read8 = pintfhdl->io_ops._read8; - r_val = _read8(pintfhdl, addr); - return r_val; + return _read8(pintfhdl, addr); } u16 _rtw_read16(struct adapter *adapter, u32 addr) @@ -142,13 +140,10 @@ u32 _rtw_write_port(struct adapter *adapter, u32 addr, u32 cnt, u8 *pmem) u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); struct io_priv *pio_priv = &adapter->iopriv; struct intf_hdl *pintfhdl = &(pio_priv->intf); - u32 ret; _write_port = pintfhdl->io_ops._write_port; - ret = _write_port(pintfhdl, addr, cnt, pmem); - - return ret; + return _write_port(pintfhdl, addr, cnt, pmem); } int rtw_init_io_priv(struct adapter *padapter, void (*set_intf_ops)(struct adapter *padapter, struct _io_ops *pops)) diff --git a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c index eb08569db5ea..8b5f6a66bfb8 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c +++ b/drivers/staging/rtl8723bs/core/rtw_ioctl_set.c @@ -439,7 +439,7 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter, if ((*pold_state == Ndis802_11Infrastructure) || (*pold_state == Ndis802_11IBSS)) { if (check_fwstate(pmlmepriv, _FW_LINKED) == true) { - rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have chked whether issue dis-assoc_cmd or not */ + rtw_indicate_disconnect(padapter); /* will clr Linked_state; before this function, we must have checked whether issue dis-assoc_cmd or not */ } } diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme.c b/drivers/staging/rtl8723bs/core/rtw_mlme.c index 71fcb466019a..d7a58af76ea0 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme.c @@ -2772,16 +2772,7 @@ void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len, u8 channe /* maybe needs check if ap supports rx ampdu. */ if (!(phtpriv->ampdu_enable) && pregistrypriv->ampdu_enable == 1) { - if (pregistrypriv->wifi_spec == 1) { - /* remove this part because testbed AP should disable RX AMPDU */ - /* phtpriv->ampdu_enable = false; */ - phtpriv->ampdu_enable = true; - } else { - phtpriv->ampdu_enable = true; - } - } else if (pregistrypriv->ampdu_enable == 2) { - /* remove this part because testbed AP should disable RX AMPDU */ - /* phtpriv->ampdu_enable = true; */ + phtpriv->ampdu_enable = true; } /* check Max Rx A-MPDU Size */ diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c index c642825ca8ef..8f9da1d49343 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c @@ -219,6 +219,7 @@ static RT_CHANNEL_PLAN_MAP RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03, 0x02}; int rtw_ch_set_search_ch(RT_CHANNEL_INFO *ch_set, const u32 ch) { int i; + for (i = 0; ch_set[i].ChannelNum != 0; i++) { if (ch == ch_set[i].ChannelNum) break; @@ -2184,6 +2185,7 @@ unsigned int OnAction_sa_query(struct adapter *padapter, union recv_frame *precv } if (0) { int pp; + printk("pattrib->pktlen = %d =>", pattrib->pkt_len); for (pp = 0; pp < pattrib->pkt_len; pp++) printk(" %02x ", pframe[pp]); @@ -2486,6 +2488,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms) /* DBG_871X("ie len =%d\n", cur_network->IELength); */ { int len_diff; + memcpy(pframe, cur_network->IEs, cur_network->IELength); len_diff = update_hidden_ssid( pframe+_BEACON_IE_OFFSET_ @@ -2500,6 +2503,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms) u8 *wps_ie; uint wps_ielen; u8 sr = 0; + wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof(struct ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_, pattrib->pktlen-sizeof(struct ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen); if (wps_ie && wps_ielen > 0) { @@ -2700,6 +2704,7 @@ void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p if (ssid_ie && cur_network->Ssid.SsidLength) { uint remainder_ielen; u8 *remainder_ie; + remainder_ie = ssid_ie+2; remainder_ielen = (pframe-remainder_ie); @@ -4280,6 +4285,7 @@ void site_survey(struct adapter *padapter) { struct rtw_ieee80211_channel *ch; + if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) { ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx]; survey_channel = ch->hw_value; @@ -4323,6 +4329,7 @@ void site_survey(struct adapter *padapter) if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */ { int i; + for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) { if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) { /* IOT issue, When wifi_spec is not set, send one probe req without WPS IE. */ @@ -4351,6 +4358,7 @@ void site_survey(struct adapter *padapter) #if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR) { struct noise_info info; + info.bPauseDIG = false; info.IGIValue = 0; info.max_time = channel_scan_time_ms/2;/* ms */ @@ -4518,6 +4526,7 @@ u8 collect_bss_info(struct adapter *padapter, union recv_frame *precv_frame, str p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset); if (p) { struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2); + bssid->Configuration.DSConfig = HT_info->primary_channel; } else { /* use current channel */ bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter); @@ -4551,6 +4560,7 @@ u8 collect_bss_info(struct adapter *padapter, union recv_frame *precv_frame, str p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset); if (p && len > 0) { struct HT_caps_element *pHT_caps; + pHT_caps = (struct HT_caps_element *)(p + 2); if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info) & BIT(14)) @@ -4584,6 +4594,7 @@ void start_create_ibss(struct adapter *padapter) struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); + pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig; pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork); @@ -5388,6 +5399,7 @@ static void rtw_mlmeext_disconnect(struct adapter *padapter) /* wakeup macid after disconnect. */ { struct sta_info *psta; + psta = rtw_get_stainfo(&padapter->stapriv, get_my_bssid(pnetwork)); if (psta) rtw_hal_macid_wakeup(padapter, psta->mac_id); @@ -5425,6 +5437,7 @@ void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res) struct sta_priv *pstapriv = &padapter->stapriv; u8 join_type; struct sta_info *psta; + if (join_res < 0) { join_type = 1; rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type)); @@ -6047,6 +6060,7 @@ u8 createbss_hdl(struct adapter *padapter, u8 *pbuf) if (pmlmeinfo->state == WIFI_FW_AP_STATE) { struct wlan_bssid_ex *network = &padapter->mlmepriv.cur_network.network; + start_bss_network(padapter, (u8 *)network); return H2C_SUCCESS; } @@ -6810,6 +6824,7 @@ u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf) if ((padapter->rtw_wdev != NULL) && (padapter->rtw_wdev->wiphy)) { struct regulatory_request request; + request.initiator = NL80211_REGDOM_SET_BY_DRIVER; rtw_reg_notifier(padapter->rtw_wdev->wiphy, &request); } diff --git a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c index 30137f0bd984..6ac9184d59a6 100644 --- a/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c +++ b/drivers/staging/rtl8723bs/core/rtw_pwrctrl.c @@ -1193,7 +1193,7 @@ inline void rtw_set_ips_deny(struct adapter *padapter, u32 ms) /* * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend * @adapter: pointer to struct adapter structure -* @ips_deffer_ms: the ms wiil prevent from falling into IPS after wakeup +* @ips_deffer_ms: the ms will prevent from falling into IPS after wakeup * Return _SUCCESS or _FAIL */ @@ -1390,10 +1390,5 @@ void rtw_ps_deny_cancel(struct adapter *padapter, enum PS_DENY_REASON reason) */ u32 rtw_ps_deny_get(struct adapter *padapter) { - u32 deny; - - - deny = adapter_to_pwrctl(padapter)->ps_deny; - - return deny; + return adapter_to_pwrctl(padapter)->ps_deny; } diff --git a/drivers/staging/rtl8723bs/core/rtw_recv.c b/drivers/staging/rtl8723bs/core/rtw_recv.c index 7fa8c84cf5f4..5245098b9ecf 100644 --- a/drivers/staging/rtl8723bs/core/rtw_recv.c +++ b/drivers/staging/rtl8723bs/core/rtw_recv.c @@ -1179,7 +1179,7 @@ sint validate_recv_ctrl_frame(struct adapter *padapter, union recv_frame *precv_ /* DBG_871X("after handling ps-poll, tim =%x\n", pstapriv->tim_bitmap); */ - /* upate BCN for TIM IE */ + /* update BCN for TIM IE */ /* update_BCNTIM(padapter); */ update_beacon(padapter, _TIM_IE_, NULL, true); } @@ -1205,7 +1205,7 @@ sint validate_recv_ctrl_frame(struct adapter *padapter, union recv_frame *precv_ pstapriv->tim_bitmap &= ~BIT(psta->aid); - /* upate BCN for TIM IE */ + /* update BCN for TIM IE */ /* update_BCNTIM(padapter); */ update_beacon(padapter, _TIM_IE_, NULL, true); } @@ -1953,7 +1953,7 @@ static int amsdu_to_msdu(struct adapter *padapter, union recv_frame *prframe) for (i = 0; i < nr_subframes; i++) { sub_pkt = subframes[i]; - /* Indicat the packets to upper layer */ + /* Indicate the packets to upper layer */ if (sub_pkt) { rtw_os_recv_indicate_pkt(padapter, sub_pkt, &prframe->u.hdr.attrib); } @@ -2606,14 +2606,14 @@ static void rtw_signal_stat_timer_hdl(struct timer_list *t) if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */ avg_signal_strength = recvpriv->signal_strength_data.avg_val; num_signal_strength = recvpriv->signal_strength_data.total_num; - /* after avg_vals are accquired, we can re-stat the signal values */ + /* after avg_vals are acquired, we can re-stat the signal values */ recvpriv->signal_strength_data.update_req = 1; } if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */ avg_signal_qual = recvpriv->signal_qual_data.avg_val; num_signal_qual = recvpriv->signal_qual_data.total_num; - /* after avg_vals are accquired, we can re-stat the signal values */ + /* after avg_vals are acquired, we can re-stat the signal values */ recvpriv->signal_qual_data.update_req = 1; } diff --git a/drivers/staging/rtl8723bs/core/rtw_security.c b/drivers/staging/rtl8723bs/core/rtw_security.c index 9c4607114cea..5ebf691bd743 100644 --- a/drivers/staging/rtl8723bs/core/rtw_security.c +++ b/drivers/staging/rtl8723bs/core/rtw_security.c @@ -434,7 +434,6 @@ void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_cod rtw_secmicappend(&micdata, &header[16], 6); else rtw_secmicappend(&micdata, &header[10], 6); - } rtw_secmicappend(&micdata, &priority[0], 4); @@ -723,7 +722,6 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) TKIP_SW_ENC_CNT_INC(psecuritypriv, pattrib->ra); } - } return res; } @@ -829,11 +827,9 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("%s: stainfo == NULL!!!\n", __func__)); res = _FAIL; } - } exit: return res; - } @@ -1219,7 +1215,6 @@ static void construct_mic_header2( if (!qc_exists && a4_exists) { for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */ - } if (qc_exists && !a4_exists) { @@ -1234,7 +1229,6 @@ static void construct_mic_header2( mic_header2[14] = mpdu[30] & 0x0f; mic_header2[15] = mpdu[31] & 0x00; } - } /************************************************/ @@ -1413,7 +1407,6 @@ static sint aes_cipher(u8 *key, uint hdrlen, } bitwise_xor(aes_out, padded_buffer, chain_buffer); aes128k128d(key, chain_buffer, aes_out); - } for (j = 0 ; j < 8; j++) @@ -1719,7 +1712,6 @@ static sint aes_decipher(u8 *key, uint hdrlen, } bitwise_xor(aes_out, padded_buffer, chain_buffer); aes128k128d(key, chain_buffer, aes_out); - } for (j = 0; j < 8; j++) diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c index 9590e6f351c1..110338dbe372 100644 --- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c +++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c @@ -326,20 +326,20 @@ inline void rtw_set_oper_ch(struct adapter *adapter, u8 ch) dvobj->on_oper_ch_time = jiffies; #ifdef DBG_CH_SWITCH - cnt += snprintf(msg+cnt, len-cnt, "switch to ch %3u", ch); + cnt += scnprintf(msg+cnt, len-cnt, "switch to ch %3u", ch); for (i = 0; i < dvobj->iface_nums; i++) { struct adapter *iface = dvobj->padapters[i]; - cnt += snprintf(msg+cnt, len-cnt, " ["ADPT_FMT":", ADPT_ARG(iface)); + cnt += scnprintf(msg+cnt, len-cnt, " ["ADPT_FMT":", ADPT_ARG(iface)); if (iface->mlmeextpriv.cur_channel == ch) - cnt += snprintf(msg+cnt, len-cnt, "C"); + cnt += scnprintf(msg+cnt, len-cnt, "C"); else - cnt += snprintf(msg+cnt, len-cnt, "_"); + cnt += scnprintf(msg+cnt, len-cnt, "_"); if (iface->wdinfo.listen_channel == ch && !rtw_p2p_chk_state(&iface->wdinfo, P2P_STATE_NONE)) - cnt += snprintf(msg+cnt, len-cnt, "L"); + cnt += scnprintf(msg+cnt, len-cnt, "L"); else - cnt += snprintf(msg+cnt, len-cnt, "_"); - cnt += snprintf(msg+cnt, len-cnt, "]"); + cnt += scnprintf(msg+cnt, len-cnt, "_"); + cnt += scnprintf(msg+cnt, len-cnt, "]"); } DBG_871X(FUNC_ADPT_FMT" %s\n", FUNC_ADPT_ARG(adapter), msg); @@ -1503,7 +1503,7 @@ void update_beacon_info(struct adapter *padapter, u8 *pframe, uint pkt_len, stru switch (pIE->ElementID) { case _VENDOR_SPECIFIC_IE_: - /* to update WMM paramter set while receiving beacon */ + /* to update WMM parameter set while receiving beacon */ if (!memcmp(pIE->data, WMM_PARA_OUI, 6) && pIE->Length == WLAN_WMM_LEN) /* WMM */ if (WMM_param_handler(padapter, pIE)) report_wmm_edca_update(padapter); diff --git a/drivers/staging/rtl8723bs/core/rtw_xmit.c b/drivers/staging/rtl8723bs/core/rtw_xmit.c index fdb585ff5925..571353404a95 100644 --- a/drivers/staging/rtl8723bs/core/rtw_xmit.c +++ b/drivers/staging/rtl8723bs/core/rtw_xmit.c @@ -1180,7 +1180,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, _pkt *pkt, struct xmit_fram mpdu_len -= pattrib->icv_len; if (bmcst) { - /* don't do fragment to broadcat/multicast packets */ + /* don't do fragment to broadcast/multicast packets */ mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen); } else { mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len); @@ -2303,7 +2303,7 @@ sint xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_fr pstapriv->tim_bitmap |= BIT(psta->aid); if (update_tim) - /* upate BCN for TIM IE */ + /* update BCN for TIM IE */ update_beacon(padapter, _TIM_IE_, NULL, true); } diff --git a/drivers/staging/rtl8723bs/hal/Hal8723BReg.h b/drivers/staging/rtl8723bs/hal/Hal8723BReg.h index ce02457922b7..b9aca99478db 100644 --- a/drivers/staging/rtl8723bs/hal/Hal8723BReg.h +++ b/drivers/staging/rtl8723bs/hal/Hal8723BReg.h @@ -415,13 +415,13 @@ #define IMR_BCNDMAINT3_8723B BIT23 /* Beacon DMA Interrupt 3 */ #define IMR_BCNDMAINT2_8723B BIT22 /* Beacon DMA Interrupt 2 */ #define IMR_BCNDMAINT1_8723B BIT21 /* Beacon DMA Interrupt 1 */ -#define IMR_BCNDOK7_8723B BIT20 /* Beacon Queue DMA OK Interrup 7 */ -#define IMR_BCNDOK6_8723B BIT19 /* Beacon Queue DMA OK Interrup 6 */ -#define IMR_BCNDOK5_8723B BIT18 /* Beacon Queue DMA OK Interrup 5 */ -#define IMR_BCNDOK4_8723B BIT17 /* Beacon Queue DMA OK Interrup 4 */ -#define IMR_BCNDOK3_8723B BIT16 /* Beacon Queue DMA OK Interrup 3 */ -#define IMR_BCNDOK2_8723B BIT15 /* Beacon Queue DMA OK Interrup 2 */ -#define IMR_BCNDOK1_8723B BIT14 /* Beacon Queue DMA OK Interrup 1 */ +#define IMR_BCNDOK7_8723B BIT20 /* Beacon Queue DMA OK Interrupt 7 */ +#define IMR_BCNDOK6_8723B BIT19 /* Beacon Queue DMA OK Interrupt 6 */ +#define IMR_BCNDOK5_8723B BIT18 /* Beacon Queue DMA OK Interrupt 5 */ +#define IMR_BCNDOK4_8723B BIT17 /* Beacon Queue DMA OK Interrupt 4 */ +#define IMR_BCNDOK3_8723B BIT16 /* Beacon Queue DMA OK Interrupt 3 */ +#define IMR_BCNDOK2_8723B BIT15 /* Beacon Queue DMA OK Interrupt 2 */ +#define IMR_BCNDOK1_8723B BIT14 /* Beacon Queue DMA OK Interrupt 1 */ #define IMR_ATIMEND_E_8723B BIT13 /* ATIM Window End Extension for Win7 */ #define IMR_TXERR_8723B BIT11 /* Tx Error Flag Interrupt Status, write 1 clear. */ #define IMR_RXERR_8723B BIT10 /* Rx Error Flag INT Status, Write 1 clear */ diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c index dd349c506da8..c60e8c58d9cc 100644 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c +++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b1Ant.c @@ -1807,7 +1807,7 @@ static void halbtc8723b1ant_TdmaDurationAdjustForAcl( result = 0; WaitCount = 0; } else { - /* accquire the BT TRx retry count from BT_Info byte2 */ + /* acquire the BT TRx retry count from BT_Info byte2 */ retryCount = pCoexSta->btRetryCnt; btInfoExt = pCoexSta->btInfoExt; /* BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount)); */ diff --git a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c b/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c index 02da0a883594..2779dba92bab 100644 --- a/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c +++ b/drivers/staging/rtl8723bs/hal/HalBtc8723b2Ant.c @@ -1610,8 +1610,6 @@ static void halbtc8723b2ant_TdmaDurationAdjust( HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13); else if (maxInterval == 2) HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14); - else if (maxInterval == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); else HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15); } else { @@ -1619,8 +1617,6 @@ static void halbtc8723b2ant_TdmaDurationAdjust( HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9); else if (maxInterval == 2) HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10); - else if (maxInterval == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); else HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11); } @@ -1630,8 +1626,6 @@ static void halbtc8723b2ant_TdmaDurationAdjust( HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5); else if (maxInterval == 2) HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6); - else if (maxInterval == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); else HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7); } else { @@ -1639,8 +1633,6 @@ static void halbtc8723b2ant_TdmaDurationAdjust( HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1); else if (maxInterval == 2) HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2); - else if (maxInterval == 3) - HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); else HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3); } @@ -1654,7 +1646,7 @@ static void halbtc8723b2ant_TdmaDurationAdjust( result = 0; WaitCount = 0; } else { - /* accquire the BT TRx retry count from BT_Info byte2 */ + /* acquire the BT TRx retry count from BT_Info byte2 */ retryCount = pCoexSta->btRetryCnt; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount)); BTC_PRINT( diff --git a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h b/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h index 7150d54d49ab..c758d143c57f 100644 --- a/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h +++ b/drivers/staging/rtl8723bs/hal/HalBtcOutSrc.h @@ -44,14 +44,14 @@ #define BTC_ANT_WIFI_AT_CPL_MAIN 0 #define BTC_ANT_WIFI_AT_CPL_AUX 1 -typedef enum _BTC_POWERSAVE_TYPE{ +typedef enum _BTC_POWERSAVE_TYPE { BTC_PS_WIFI_NATIVE = 0, /* wifi original power save behavior */ BTC_PS_LPS_ON = 1, BTC_PS_LPS_OFF = 2, BTC_PS_MAX } BTC_POWERSAVE_TYPE, *PBTC_POWERSAVE_TYPE; -typedef enum _BTC_BT_REG_TYPE{ +typedef enum _BTC_BT_REG_TYPE { BTC_BT_REG_RF = 0, BTC_BT_REG_MODEM = 1, BTC_BT_REG_BLUEWIZE = 2, @@ -60,7 +60,7 @@ typedef enum _BTC_BT_REG_TYPE{ BTC_BT_REG_MAX } BTC_BT_REG_TYPE, *PBTC_BT_REG_TYPE; -typedef enum _BTC_CHIP_INTERFACE{ +typedef enum _BTC_CHIP_INTERFACE { BTC_INTF_UNKNOWN = 0, BTC_INTF_PCI = 1, BTC_INTF_USB = 2, diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf.c b/drivers/staging/rtl8723bs/hal/HalPhyRf.c index 357802db9aed..7b435840746d 100644 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf.c +++ b/drivers/staging/rtl8723bs/hal/HalPhyRf.c @@ -92,7 +92,7 @@ void ODM_TXPowerTrackingCallback_ThermalMeter(struct adapter *Adapter) u8 *deltaSwingTableIdx_TUP_B; u8 *deltaSwingTableIdx_TDOWN_B; - /* 4 2. Initilization (7 steps in total) */ + /* 4 2. Initialization (7 steps in total) */ ConfigureTxpowerTrack(pDM_Odm, &c); @@ -213,7 +213,7 @@ void ODM_TXPowerTrackingCallback_ThermalMeter(struct adapter *Adapter) /* 3 7. If necessary, move the index of swing table to adjust Tx power. */ if (delta > 0 && pDM_Odm->RFCalibrateInfo.TxPowerTrackControl) { - /* delta" here is used to record the absolute value of differrence. */ + /* delta" here is used to record the absolute value of difference. */ delta = ThermalValue > pHalData->EEPROMThermalMeter ? (ThermalValue - pHalData->EEPROMThermalMeter) : diff --git a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c b/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c index c24156873fed..3b34a516075f 100644 --- a/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c +++ b/drivers/staging/rtl8723bs/hal/HalPwrSeqCmd.c @@ -118,7 +118,7 @@ u8 HalPwrSeqCmdParsing( &GET_PWR_CFG_MASK(PwrCfgCmd) ); - /* Write the value back to sytem register */ + /* Write the value back to system register */ rtw_write8(padapter, offset, value); } break; diff --git a/drivers/staging/rtl8723bs/hal/hal_com.c b/drivers/staging/rtl8723bs/hal/hal_com.c index 109bd85b0cd8..02676da5c166 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com.c +++ b/drivers/staging/rtl8723bs/hal/hal_com.c @@ -961,10 +961,7 @@ exit: u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type) { - - u8 raid; - raid = (network_type & WIRELESS_11B) ? RATEID_IDX_B : RATEID_IDX_G; - return raid; + return (network_type & WIRELESS_11B) ? RATEID_IDX_B : RATEID_IDX_G; } void rtw_hal_update_sta_rate_mask(struct adapter *padapter, struct sta_info *psta) diff --git a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c index eb7de3617d83..767e2a784f78 100644 --- a/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c +++ b/drivers/staging/rtl8723bs/hal/hal_com_phycfg.c @@ -1498,9 +1498,7 @@ s8 PHY_GetTxPowerByRate( return value; } - value = pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex]; - - return value; + return pHalData->TxPwrByRateOffset[Band][RFPath][TxNum][rateIndex]; } diff --git a/drivers/staging/rtl8723bs/hal/hal_intf.c b/drivers/staging/rtl8723bs/hal/hal_intf.c index 7d8f21f32fb9..23df729acb7b 100644 --- a/drivers/staging/rtl8723bs/hal/hal_intf.c +++ b/drivers/staging/rtl8723bs/hal/hal_intf.c @@ -365,7 +365,7 @@ void rtw_hal_dm_watchdog_in_lps(struct adapter *padapter) { if (adapter_to_pwrctl(padapter)->bFwCurrentInPSMode == true) { if (padapter->HalFunc.hal_dm_watchdog_in_lps) - padapter->HalFunc.hal_dm_watchdog_in_lps(padapter); /* this fuction caller is in interrupt context */ + padapter->HalFunc.hal_dm_watchdog_in_lps(padapter); /* this function caller is in interrupt context */ } } diff --git a/drivers/staging/rtl8723bs/hal/odm.h b/drivers/staging/rtl8723bs/hal/odm.h index fba3b9e1491b..b77d1fe33a28 100644 --- a/drivers/staging/rtl8723bs/hal/odm.h +++ b/drivers/staging/rtl8723bs/hal/odm.h @@ -849,7 +849,7 @@ typedef struct _ODM_PATH_DIVERSITY_ { u32 PathB_Cnt[ODM_ASSOCIATE_ENTRY_NUM]; } PATHDIV_T, *pPATHDIV_T; -typedef enum _BASEBAND_CONFIG_PHY_REG_PG_VALUE_TYPE{ +typedef enum _BASEBAND_CONFIG_PHY_REG_PG_VALUE_TYPE { PHY_REG_PG_RELATIVE_VALUE = 0, PHY_REG_PG_EXACT_VALUE = 1 } PHY_REG_PG_TYPE; diff --git a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c index 95edd148ac24..3ea1972545e5 100644 --- a/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c +++ b/drivers/staging/rtl8723bs/hal/odm_CfoTracking.c @@ -40,16 +40,11 @@ static void odm_SetCrystalCap(void *pDM_VOID, u8 CrystalCap) static u8 odm_GetDefaultCrytaltalCap(void *pDM_VOID) { PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID; - u8 CrystalCap = 0x20; struct adapter *Adapter = pDM_Odm->Adapter; struct hal_com_data *pHalData = GET_HAL_DATA(Adapter); - CrystalCap = pHalData->CrystalCap; - - CrystalCap = CrystalCap & 0x3f; - - return CrystalCap; + return pHalData->CrystalCap & 0x3f; } static void odm_SetATCStatus(void *pDM_VOID, bool ATCStatus) @@ -303,7 +298,7 @@ void ODM_CfoTracking(void *pDM_VOID) void ODM_ParsingCFO(void *pDM_VOID, void *pPktinfo_VOID, s8 *pcfotail) { PDM_ODM_T pDM_Odm = (PDM_ODM_T)pDM_VOID; - struct odm_packet_info *pPktinfo = (struct odm_packet_info *)pPktinfo_VOID; + struct odm_packet_info *pPktinfo = pPktinfo_VOID; PCFO_TRACKING pCfoTrack = &pDM_Odm->DM_CfoTrack; u8 i; diff --git a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c b/drivers/staging/rtl8723bs/hal/odm_HWConfig.c index 71919a3d81ab..9c190b1024d8 100644 --- a/drivers/staging/rtl8723bs/hal/odm_HWConfig.c +++ b/drivers/staging/rtl8723bs/hal/odm_HWConfig.c @@ -103,10 +103,10 @@ static void odm_RxPhyStatus92CSeries_Parsing( pDM_Odm->PhyDbgInfo.NumQryPhyStatusCCK++; /* */ /* (1)Hardware does not provide RSSI for CCK */ - /* (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) */ + /* (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) */ /* */ - cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a ; + cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a; /* 2011.11.28 LukeLee: 88E use different LNA & VGA gain table */ /* The RSSI formula should be modified according to the gain table */ @@ -178,7 +178,7 @@ static void odm_RxPhyStatus92CSeries_Parsing( /* */ - /* (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) */ + /* (2)PWDB, Average PWDB calculated by hardware (for rate adaptive) */ /* */ rx_pwr_all = (((pPhyStaRpt->cck_sig_qual_ofdm_pwdb_all) >> 1)&0x7f)-110; diff --git a/drivers/staging/rtl8723bs/hal/odm_debug.h b/drivers/staging/rtl8723bs/hal/odm_debug.h index 3e58cb806c8c..a7381173d1a3 100644 --- a/drivers/staging/rtl8723bs/hal/odm_debug.h +++ b/drivers/staging/rtl8723bs/hal/odm_debug.h @@ -13,7 +13,7 @@ /* Define the debug levels */ /* */ /* 1. DBG_TRACE and DBG_LOUD are used for normal cases. */ -/* So that, they can help SW engineer to develope or trace states changed */ +/* So that, they can help SW engineer to developed or trace states changed */ /* and also help HW enginner to trace every operation to and from HW, */ /* e.g IO, Tx, Rx. */ /* */ @@ -34,7 +34,7 @@ #define ODM_DBG_SERIOUS 2 /* */ -/* Abnormal, rare, or unexpeted cases. */ +/* Abnormal, rare, or unexpected cases. */ /* For example, */ /* IRP/Packet/OID canceled, */ /* device suprisely unremoved and so on. */ diff --git a/drivers/staging/rtl8723bs/hal/odm_types.h b/drivers/staging/rtl8723bs/hal/odm_types.h index 28f42c9c3dd7..c79fc1813c3f 100644 --- a/drivers/staging/rtl8723bs/hal/odm_types.h +++ b/drivers/staging/rtl8723bs/hal/odm_types.h @@ -28,7 +28,7 @@ typedef enum _HAL_STATUS { /* */ -/* Declare for ODM spin lock defintion temporarily fro compile pass. */ +/* Declare for ODM spin lock definition temporarily from compile pass. */ /* */ typedef enum _RT_SPINLOCK_TYPE { RT_TX_SPINLOCK = 1, diff --git a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c index 71b5a50b6ef6..fd2b74003faf 100644 --- a/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c +++ b/drivers/staging/rtl8723bs/hal/rtl8723b_cmd.c @@ -146,7 +146,7 @@ static void ConstructBeacon(struct adapter *padapter, u8 *pframe, u32 *pLength) SetFrameSubType(pframe, WIFI_BEACON); pframe += sizeof(struct ieee80211_hdr_3addr); - pktlen = sizeof (struct ieee80211_hdr_3addr); + pktlen = sizeof(struct ieee80211_hdr_3addr); /* timestamp will be inserted by hardware */ pframe += 8; @@ -823,8 +823,11 @@ static void ConstructProbeRsp(struct adapter *padapter, u8 *pframe, u32 *pLength } #endif /* CONFIG_AP_WOWLAN */ -/* To check if reserved page content is destroyed by beacon beacuse beacon is too large. */ -/* 2010.06.23. Added by tynli. */ +/* + * To check if reserved page content is destroyed by beacon because beacon + * is too large. + */ +/* 2010.06.23. Added by tynli. */ void CheckFwRsvdPageContent(struct adapter *Adapter) { } @@ -1409,16 +1412,20 @@ void rtl8723b_set_ap_wowlan_cmd(struct adapter *padapter, u8 enable) } #endif /* CONFIG_AP_WOWLAN */ -/* */ -/* Description: Fill the reserved packets that FW will use to RSVD page. */ -/* Now we just send 4 types packet to rsvd page. */ -/* (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. */ -/* Input: */ -/* bDLFinished - false: At the first time we will send all the packets as a large packet to Hw, */ -/* so we need to set the packet length to total lengh. */ -/* true: At the second time, we should send the first packet (default:beacon) */ -/* to Hw again and set the lengh in descriptor to the real beacon lengh. */ -/* 2009.10.15 by tynli. */ +/* + * Description: Fill the reserved packets that FW will use to RSVD page. + * Now we just send 4 types packet to rsvd page. + * (1)Beacon, (2)Ps-poll, (3)Null data, (4)ProbeRsp. + * + * Input: + * + * bDLFinished - false: At the first time we will send all the packets as + * a large packet to Hw, so we need to set the packet length to total length. + * + * true: At the second time, we should send the first packet (default:beacon) + * to Hw again and set the length in descriptor to the real beacon length. + */ +/* 2009.10.15 by tynli. */ static void rtl8723b_set_FwRsvdPagePkt( struct adapter *padapter, bool bDLFinished ) @@ -1599,7 +1606,7 @@ static void rtl8723b_set_FwRsvdPagePkt( #ifdef CONFIG_GTK_OL BufIndex += (CurtPktPageNum*PageSize); - /* if the ap staion info. exists, get the kek, kck from staion info. */ + /* if the ap station info. exists, get the kek, kck from station info. */ psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); if (!psta) { memset(kek, 0, RTW_KEK_LEN); @@ -1652,7 +1659,7 @@ static void rtl8723b_set_FwRsvdPagePkt( TotalPacketLen = BufIndex-TxDescLen + 256; /* extension memory for FW */ #else - TotalPacketLen = BufIndex-TxDescLen + sizeof (union pn48); /* IV len */ + TotalPacketLen = BufIndex - TxDescLen + sizeof(union pn48); /* IV len */ #endif /* CONFIG_GTK_OL */ } else #endif /* CONFIG_WOWLAN */ @@ -1791,18 +1798,19 @@ error: } #ifdef CONFIG_AP_WOWLAN -/* */ -/* Description: Fill the reserved packets that FW will use to RSVD page. */ -/* Now we just send 2 types packet to rsvd page. (1)Beacon, (2)ProbeRsp. */ -/* */ -/* Input: bDLFinished */ -/* */ -/* false: At the first time we will send all the packets as a large packet to Hw, */ -/* so we need to set the packet length to total lengh. */ -/* */ -/* true: At the second time, we should send the first packet (default:beacon) */ -/* to Hw again and set the lengh in descriptor to the real beacon lengh. */ -/* 2009.10.15 by tynli. */ +/* + * Description: Fill the reserved packets that FW will use to RSVD page. + * Now we just send 2 types packet to rsvd page. (1)Beacon, (2)ProbeRsp. + * + * Input: bDLFinished + * + * false: At the first time we will send all the packets as a large packet to + * Hw, so we need to set the packet length to total length. + * + * true: At the second time, we should send the first packet (default:beacon) + * to Hw again and set the length in descriptor to the real beacon length. + */ +/* 2009.10.15 by tynli. */ static void rtl8723b_set_AP_FwRsvdPagePkt( struct adapter *padapter, bool bDLFinished ) diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c index 1e8b61443408..c3051ebaeb78 100644 --- a/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c +++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_recv.c @@ -192,7 +192,7 @@ static inline union recv_frame *try_alloc_recvframe(struct recv_priv *precvpriv, rtw_enqueue_recvbuf_to_head(precvbuf, &precvpriv->recv_buf_pending_queue); - /* The case of can't allocte recvframe should be temporary, */ + /* The case of can't allocate recvframe should be temporary, */ /* schedule again and hope recvframe is available next time. */ tasklet_schedule(&precvpriv->recv_tasklet); } @@ -480,10 +480,8 @@ initbuferror: precvpriv->precv_buf = NULL; } - if (precvpriv->pallocated_recv_buf) { - kfree(precvpriv->pallocated_recv_buf); - precvpriv->pallocated_recv_buf = NULL; - } + kfree(precvpriv->pallocated_recv_buf); + precvpriv->pallocated_recv_buf = NULL; exit: return res; @@ -518,8 +516,6 @@ void rtl8723bs_free_recv_priv(struct adapter *padapter) precvpriv->precv_buf = NULL; } - if (precvpriv->pallocated_recv_buf) { - kfree(precvpriv->pallocated_recv_buf); - precvpriv->pallocated_recv_buf = NULL; - } + kfree(precvpriv->pallocated_recv_buf); + precvpriv->pallocated_recv_buf = NULL; } diff --git a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c index b6d56cfb0a19..44799c4a9f35 100644 --- a/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c +++ b/drivers/staging/rtl8723bs/hal/rtl8723bs_xmit.c @@ -282,7 +282,7 @@ static s32 xmit_xmitframes(struct adapter *padapter, struct xmit_priv *pxmitpriv /* check xmit_buf size enough or not */ txlen = txdesc_size + rtw_wlan_pkt_size(pxmitframe); - if( !pxmitbuf || + if (!pxmitbuf || ((_RND(pxmitbuf->len, 8) + txlen) > max_xmit_len) || (k >= (rtw_hal_sdio_max_txoqt_free_space(padapter) - 1)) ) { diff --git a/drivers/staging/rtl8723bs/hal/sdio_halinit.c b/drivers/staging/rtl8723bs/hal/sdio_halinit.c index e813382e78a6..7853af53051d 100644 --- a/drivers/staging/rtl8723bs/hal/sdio_halinit.c +++ b/drivers/staging/rtl8723bs/hal/sdio_halinit.c @@ -235,7 +235,7 @@ static void _InitQueueReservedPage(struct adapter *padapter) if (pHalData->OutEpQueueSel & TX_SELE_LQ) numLQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_LPQ_8723B : NORMAL_PAGE_NUM_LPQ_8723B; - /* NOTE: This step shall be proceed before writting REG_RQPN. */ + /* NOTE: This step shall be proceed before writing REG_RQPN. */ if (pHalData->OutEpQueueSel & TX_SELE_NQ) numNQ = bWiFiConfig ? WMM_NORMAL_PAGE_NUM_NPQ_8723B : NORMAL_PAGE_NUM_NPQ_8723B; @@ -551,18 +551,8 @@ static void HalRxAggr8723BSdio(struct adapter *padapter) pregistrypriv = &padapter->registrypriv; - if (pregistrypriv->wifi_spec) { - /* 2010.04.27 hpfan */ - /* Adjust RxAggrTimeout to close to zero disable RxAggr, suggested by designer */ - /* Timeout value is calculated by 34 / (2^n) */ - valueDMATimeout = 0x06; - valueDMAPageCount = 0x06; - } else { - /* 20130530, Isaac@SD1 suggest 3 kinds of parameter */ - /* TX/RX Balance */ - valueDMATimeout = 0x06; - valueDMAPageCount = 0x06; - } + valueDMATimeout = 0x06; + valueDMAPageCount = 0x06; rtw_write8(padapter, REG_RXDMA_AGG_PG_TH + 1, valueDMATimeout); rtw_write8(padapter, REG_RXDMA_AGG_PG_TH, valueDMAPageCount); diff --git a/drivers/staging/rtl8723bs/include/HalVerDef.h b/drivers/staging/rtl8723bs/include/HalVerDef.h index 160f34efbfd5..c548fb126683 100644 --- a/drivers/staging/rtl8723bs/include/HalVerDef.h +++ b/drivers/staging/rtl8723bs/include/HalVerDef.h @@ -20,7 +20,7 @@ typedef enum tag_HAL_IC_Type_Definition CHIP_8821 = 7, CHIP_8723B = 8, CHIP_8192E = 9, -}HAL_IC_TYPE_E; +} HAL_IC_TYPE_E; /* HAL_CHIP_TYPE_E */ typedef enum tag_HAL_CHIP_Type_Definition @@ -28,7 +28,7 @@ typedef enum tag_HAL_CHIP_Type_Definition TEST_CHIP = 0, NORMAL_CHIP = 1, FPGA = 2, -}HAL_CHIP_TYPE_E; +} HAL_CHIP_TYPE_E; /* HAL_CUT_VERSION_E */ typedef enum tag_HAL_Cut_Version_Definition @@ -44,7 +44,7 @@ typedef enum tag_HAL_Cut_Version_Definition I_CUT_VERSION = 8, J_CUT_VERSION = 9, K_CUT_VERSION = 10, -}HAL_CUT_VERSION_E; +} HAL_CUT_VERSION_E; /* HAL_Manufacturer */ typedef enum tag_HAL_Manufacturer_Version_Definition @@ -52,7 +52,7 @@ typedef enum tag_HAL_Manufacturer_Version_Definition CHIP_VENDOR_TSMC = 0, CHIP_VENDOR_UMC = 1, CHIP_VENDOR_SMIC = 2, -}HAL_VENDOR_E; +} HAL_VENDOR_E; typedef enum tag_HAL_RF_Type_Definition { @@ -64,7 +64,7 @@ typedef enum tag_HAL_RF_Type_Definition RF_TYPE_3T3R = 5, RF_TYPE_3T4R = 6, RF_TYPE_4T4R = 7, -}HAL_RF_TYPE_E; +} HAL_RF_TYPE_E; typedef struct tag_HAL_VERSION { @@ -74,14 +74,14 @@ typedef struct tag_HAL_VERSION HAL_VENDOR_E VendorType; HAL_RF_TYPE_E RFType; u8 ROMVer; -}HAL_VERSION,*PHAL_VERSION; +} HAL_VERSION, *PHAL_VERSION; /* VERSION_8192C VersionID; */ /* HAL_VERSION VersionID; */ /* Get element */ -#define GET_CVID_IC_TYPE(version) ((HAL_IC_TYPE_E)((version).ICType) ) -#define GET_CVID_CHIP_TYPE(version) ((HAL_CHIP_TYPE_E)((version).ChipType) ) +#define GET_CVID_IC_TYPE(version) ((HAL_IC_TYPE_E)((version).ICType)) +#define GET_CVID_CHIP_TYPE(version) ((HAL_CHIP_TYPE_E)((version).ChipType)) #define GET_CVID_RF_TYPE(version) ((HAL_RF_TYPE_E)((version).RFType)) #define GET_CVID_MANUFACTUER(version) ((HAL_VENDOR_E)((version).VendorType)) #define GET_CVID_CUT_VERSION(version) ((HAL_CUT_VERSION_E)((version).CUTVersion)) @@ -93,8 +93,8 @@ typedef struct tag_HAL_VERSION /* HAL_VERSION VersionID */ /* HAL_CHIP_TYPE_E */ -#define IS_TEST_CHIP(version) ((GET_CVID_CHIP_TYPE(version) ==TEST_CHIP)? true: false) -#define IS_NORMAL_CHIP(version) ((GET_CVID_CHIP_TYPE(version) ==NORMAL_CHIP)? true: false) +#define IS_TEST_CHIP(version) ((GET_CVID_CHIP_TYPE(version) == TEST_CHIP) ? true : false) +#define IS_NORMAL_CHIP(version) ((GET_CVID_CHIP_TYPE(version) == NORMAL_CHIP) ? true : false) /* HAL_CUT_VERSION_E */ #define IS_A_CUT(version) ((GET_CVID_CUT_VERSION(version) == A_CUT_VERSION) ? true : false) @@ -107,13 +107,13 @@ typedef struct tag_HAL_VERSION #define IS_K_CUT(version) ((GET_CVID_CUT_VERSION(version) == K_CUT_VERSION) ? true : false) /* HAL_VENDOR_E */ -#define IS_CHIP_VENDOR_TSMC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_TSMC)? true: false) -#define IS_CHIP_VENDOR_UMC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_UMC)? true: false) -#define IS_CHIP_VENDOR_SMIC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_SMIC)? true: false) +#define IS_CHIP_VENDOR_TSMC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_TSMC) ? true : false) +#define IS_CHIP_VENDOR_UMC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_UMC) ? true : false) +#define IS_CHIP_VENDOR_SMIC(version) ((GET_CVID_MANUFACTUER(version) == CHIP_VENDOR_SMIC) ? true : false) /* HAL_RF_TYPE_E */ -#define IS_1T1R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T1R)? true : false) -#define IS_1T2R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T2R)? true : false) -#define IS_2T2R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_2T2R)? true : false) +#define IS_1T1R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T1R) ? true : false) +#define IS_1T2R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_1T2R) ? true : false) +#define IS_2T2R(version) ((GET_CVID_RF_TYPE(version) == RF_TYPE_2T2R) ? true : false) #endif diff --git a/drivers/staging/rtl8723bs/include/cmd_osdep.h b/drivers/staging/rtl8723bs/include/cmd_osdep.h index d3af9f44ad59..5506f513dc01 100644 --- a/drivers/staging/rtl8723bs/include/cmd_osdep.h +++ b/drivers/staging/rtl8723bs/include/cmd_osdep.h @@ -10,8 +10,8 @@ int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv); int rtw_init_evt_priv(struct evt_priv *pevtpriv); -extern void _rtw_free_evt_priv (struct evt_priv *pevtpriv); -extern void _rtw_free_cmd_priv (struct cmd_priv *pcmdpriv); +extern void _rtw_free_evt_priv(struct evt_priv *pevtpriv); +extern void _rtw_free_cmd_priv(struct cmd_priv *pcmdpriv); int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj); extern struct cmd_obj *_rtw_dequeue_cmd(struct __queue *queue); diff --git a/drivers/staging/rtl8723bs/include/drv_types.h b/drivers/staging/rtl8723bs/include/drv_types.h index 6ec9087f2eb1..dba75216cbfe 100644 --- a/drivers/staging/rtl8723bs/include/drv_types.h +++ b/drivers/staging/rtl8723bs/include/drv_types.h @@ -77,7 +77,7 @@ enum _NIC_VERSION { #define SPEC_DEV_ID_RF_CONFIG_2T2R BIT(4) #define SPEC_DEV_ID_ASSIGN_IFNAME BIT(5) -struct specific_device_id{ +struct specific_device_id { u32 flags; @@ -151,8 +151,8 @@ struct registry_priv u8 lowrate_two_xmit; - u8 rf_config ; - u8 low_power ; + u8 rf_config; + u8 low_power; u8 wifi_spec;/* !turbo_mode */ @@ -498,11 +498,11 @@ enum ADAPTER_TYPE { MAX_ADAPTER = 0xFF, }; -typedef enum _DRIVER_STATE{ +typedef enum _DRIVER_STATE { DRIVER_NORMAL = 0, DRIVER_DISAPPEAR = 1, DRIVER_REPLACE_DONGLE = 2, -}DRIVER_STATE; +} DRIVER_STATE; struct adapter { int DriverState;/* for disable driver using module, use dongle to replace module. */ diff --git a/drivers/staging/rtl8723bs/include/hal_com.h b/drivers/staging/rtl8723bs/include/hal_com.h index f5c3ce5da70c..a46626d0509a 100644 --- a/drivers/staging/rtl8723bs/include/hal_com.h +++ b/drivers/staging/rtl8723bs/include/hal_com.h @@ -111,54 +111,54 @@ #define DESC_RATEVHTSS4MCS9 0x53 #define HDATA_RATE(rate)\ -(rate ==DESC_RATE1M)?"CCK_1M":\ -(rate ==DESC_RATE2M)?"CCK_2M":\ -(rate ==DESC_RATE5_5M)?"CCK5_5M":\ -(rate ==DESC_RATE11M)?"CCK_11M":\ -(rate ==DESC_RATE6M)?"OFDM_6M":\ -(rate ==DESC_RATE9M)?"OFDM_9M":\ -(rate ==DESC_RATE12M)?"OFDM_12M":\ -(rate ==DESC_RATE18M)?"OFDM_18M":\ -(rate ==DESC_RATE24M)?"OFDM_24M":\ -(rate ==DESC_RATE36M)?"OFDM_36M":\ -(rate ==DESC_RATE48M)?"OFDM_48M":\ -(rate ==DESC_RATE54M)?"OFDM_54M":\ -(rate ==DESC_RATEMCS0)?"MCS0":\ -(rate ==DESC_RATEMCS1)?"MCS1":\ -(rate ==DESC_RATEMCS2)?"MCS2":\ -(rate ==DESC_RATEMCS3)?"MCS3":\ -(rate ==DESC_RATEMCS4)?"MCS4":\ -(rate ==DESC_RATEMCS5)?"MCS5":\ -(rate ==DESC_RATEMCS6)?"MCS6":\ -(rate ==DESC_RATEMCS7)?"MCS7":\ -(rate ==DESC_RATEMCS8)?"MCS8":\ -(rate ==DESC_RATEMCS9)?"MCS9":\ -(rate ==DESC_RATEMCS10)?"MCS10":\ -(rate ==DESC_RATEMCS11)?"MCS11":\ -(rate ==DESC_RATEMCS12)?"MCS12":\ -(rate ==DESC_RATEMCS13)?"MCS13":\ -(rate ==DESC_RATEMCS14)?"MCS14":\ -(rate ==DESC_RATEMCS15)?"MCS15":\ -(rate ==DESC_RATEVHTSS1MCS0)?"VHTSS1MCS0":\ -(rate ==DESC_RATEVHTSS1MCS1)?"VHTSS1MCS1":\ -(rate ==DESC_RATEVHTSS1MCS2)?"VHTSS1MCS2":\ -(rate ==DESC_RATEVHTSS1MCS3)?"VHTSS1MCS3":\ -(rate ==DESC_RATEVHTSS1MCS4)?"VHTSS1MCS4":\ -(rate ==DESC_RATEVHTSS1MCS5)?"VHTSS1MCS5":\ -(rate ==DESC_RATEVHTSS1MCS6)?"VHTSS1MCS6":\ -(rate ==DESC_RATEVHTSS1MCS7)?"VHTSS1MCS7":\ -(rate ==DESC_RATEVHTSS1MCS8)?"VHTSS1MCS8":\ -(rate ==DESC_RATEVHTSS1MCS9)?"VHTSS1MCS9":\ -(rate ==DESC_RATEVHTSS2MCS0)?"VHTSS2MCS0":\ -(rate ==DESC_RATEVHTSS2MCS1)?"VHTSS2MCS1":\ -(rate ==DESC_RATEVHTSS2MCS2)?"VHTSS2MCS2":\ -(rate ==DESC_RATEVHTSS2MCS3)?"VHTSS2MCS3":\ -(rate ==DESC_RATEVHTSS2MCS4)?"VHTSS2MCS4":\ -(rate ==DESC_RATEVHTSS2MCS5)?"VHTSS2MCS5":\ -(rate ==DESC_RATEVHTSS2MCS6)?"VHTSS2MCS6":\ -(rate ==DESC_RATEVHTSS2MCS7)?"VHTSS2MCS7":\ -(rate ==DESC_RATEVHTSS2MCS8)?"VHTSS2MCS8":\ -(rate ==DESC_RATEVHTSS2MCS9)?"VHTSS2MCS9":"UNKNOW" +(rate == DESC_RATE1M) ? "CCK_1M" : \ +(rate == DESC_RATE2M) ? "CCK_2M" : \ +(rate == DESC_RATE5_5M) ? "CCK5_5M" : \ +(rate == DESC_RATE11M) ? "CCK_11M" : \ +(rate == DESC_RATE6M) ? "OFDM_6M" : \ +(rate == DESC_RATE9M) ? "OFDM_9M" : \ +(rate == DESC_RATE12M) ? "OFDM_12M" : \ +(rate == DESC_RATE18M) ? "OFDM_18M" : \ +(rate == DESC_RATE24M) ? "OFDM_24M" : \ +(rate == DESC_RATE36M) ? "OFDM_36M" : \ +(rate == DESC_RATE48M) ? "OFDM_48M" : \ +(rate == DESC_RATE54M) ? "OFDM_54M" : \ +(rate == DESC_RATEMCS0) ? "MCS0" : \ +(rate == DESC_RATEMCS1) ? "MCS1" : \ +(rate == DESC_RATEMCS2) ? "MCS2" : \ +(rate == DESC_RATEMCS3) ? "MCS3" : \ +(rate == DESC_RATEMCS4) ? "MCS4" : \ +(rate == DESC_RATEMCS5) ? "MCS5" : \ +(rate == DESC_RATEMCS6) ? "MCS6" : \ +(rate == DESC_RATEMCS7) ? "MCS7" : \ +(rate == DESC_RATEMCS8) ? "MCS8" : \ +(rate == DESC_RATEMCS9) ? "MCS9" : \ +(rate == DESC_RATEMCS10) ? "MCS10" : \ +(rate == DESC_RATEMCS11) ? "MCS11" : \ +(rate == DESC_RATEMCS12) ? "MCS12" : \ +(rate == DESC_RATEMCS13) ? "MCS13" : \ +(rate == DESC_RATEMCS14) ? "MCS14" : \ +(rate == DESC_RATEMCS15) ? "MCS15" : \ +(rate == DESC_RATEVHTSS1MCS0) ? "VHTSS1MCS0" : \ +(rate == DESC_RATEVHTSS1MCS1) ? "VHTSS1MCS1" : \ +(rate == DESC_RATEVHTSS1MCS2) ? "VHTSS1MCS2" : \ +(rate == DESC_RATEVHTSS1MCS3) ? "VHTSS1MCS3" : \ +(rate == DESC_RATEVHTSS1MCS4) ? "VHTSS1MCS4" : \ +(rate == DESC_RATEVHTSS1MCS5) ? "VHTSS1MCS5" : \ +(rate == DESC_RATEVHTSS1MCS6) ? "VHTSS1MCS6" : \ +(rate == DESC_RATEVHTSS1MCS7) ? "VHTSS1MCS7" : \ +(rate == DESC_RATEVHTSS1MCS8) ? "VHTSS1MCS8" : \ +(rate == DESC_RATEVHTSS1MCS9) ? "VHTSS1MCS9" : \ +(rate == DESC_RATEVHTSS2MCS0) ? "VHTSS2MCS0" : \ +(rate == DESC_RATEVHTSS2MCS1) ? "VHTSS2MCS1" : \ +(rate == DESC_RATEVHTSS2MCS2) ? "VHTSS2MCS2" : \ +(rate == DESC_RATEVHTSS2MCS3) ? "VHTSS2MCS3" : \ +(rate == DESC_RATEVHTSS2MCS4) ? "VHTSS2MCS4" : \ +(rate == DESC_RATEVHTSS2MCS5) ? "VHTSS2MCS5" : \ +(rate == DESC_RATEVHTSS2MCS6) ? "VHTSS2MCS6" : \ +(rate == DESC_RATEVHTSS2MCS7) ? "VHTSS2MCS7" : \ +(rate == DESC_RATEVHTSS2MCS8) ? "VHTSS2MCS8" : \ +(rate == DESC_RATEVHTSS2MCS9) ? "VHTSS2MCS9" : "UNKNOW" enum{ @@ -235,7 +235,7 @@ s32 c2h_evt_read_88xx(struct adapter *adapter, u8 *buf); u8 rtw_get_mgntframe_raid(struct adapter *adapter, unsigned char network_type); void rtw_hal_update_sta_rate_mask(struct adapter *padapter, struct sta_info *psta); -void hw_var_port_switch (struct adapter *adapter); +void hw_var_port_switch(struct adapter *adapter); void SetHwReg(struct adapter *padapter, u8 variable, u8 *val); void GetHwReg(struct adapter *padapter, u8 variable, u8 *val); diff --git a/drivers/staging/rtl8723bs/include/hal_com_h2c.h b/drivers/staging/rtl8723bs/include/hal_com_h2c.h index 7dbae5e2050e..b951bc288b89 100644 --- a/drivers/staging/rtl8723bs/include/hal_com_h2c.h +++ b/drivers/staging/rtl8723bs/include/hal_com_h2c.h @@ -11,7 +11,7 @@ /* H2C CMD DEFINITION ------------------------------------------------ */ /* */ /* 88e, 8723b, 8812, 8821, 92e use the same FW code base */ -enum h2c_cmd{ +enum h2c_cmd { /* Common Class: 000 */ H2C_RSVD_PAGE = 0x00, H2C_MEDIA_STATUS_RPT = 0x01, @@ -96,9 +96,9 @@ enum h2c_cmd{ #define H2C_PROBERSP_RSVDPAGE_LEN 5 #ifdef CONFIG_WOWLAN -#define eqMacAddr(a, b) (((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0) -#define cpMacAddr(des, src) ((des)[0]=(src)[0], (des)[1]=(src)[1], (des)[2]=(src)[2], (des)[3]=(src)[3], (des)[4]=(src)[4], (des)[5]=(src)[5]) -#define cpIpAddr(des, src) ((des)[0]=(src)[0], (des)[1]=(src)[1], (des)[2]=(src)[2], (des)[3]=(src)[3]) +#define eqMacAddr(a, b) (((a)[0] == (b)[0] && (a)[1] == (b)[1] && (a)[2] == (b)[2] && (a)[3] == (b)[3] && (a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1 : 0) +#define cpMacAddr(des, src) ((des)[0] = (src)[0], (des)[1] = (src)[1], (des)[2] = (src)[2], (des)[3] = (src)[3], (des)[4] = (src)[4], (des)[5] = (src)[5]) +#define cpIpAddr(des, src) ((des)[0] = (src)[0], (des)[1] = (src)[1], (des)[2] = (src)[2], (des)[3] = (src)[3]) /* */ /* ARP packet */ diff --git a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h b/drivers/staging/rtl8723bs/include/hal_com_phycfg.h index e9a3006a3e20..9fff4aa36546 100644 --- a/drivers/staging/rtl8723bs/include/hal_com_phycfg.h +++ b/drivers/staging/rtl8723bs/include/hal_com_phycfg.h @@ -177,7 +177,7 @@ u8 Channel, bool *bIn24G ); -s8 phy_get_tx_pwr_lmt (struct adapter *adapter, u32 RegPwrTblSel, +s8 phy_get_tx_pwr_lmt(struct adapter *adapter, u32 RegPwrTblSel, enum BAND_TYPE Band, enum CHANNEL_WIDTH Bandwidth, u8 RfPath, u8 DataRate, diff --git a/drivers/staging/rtl8723bs/include/hal_com_reg.h b/drivers/staging/rtl8723bs/include/hal_com_reg.h index 31a187b35810..37fa59a352d6 100644 --- a/drivers/staging/rtl8723bs/include/hal_com_reg.h +++ b/drivers/staging/rtl8723bs/include/hal_com_reg.h @@ -707,13 +707,13 @@ Default: 00b. /* ALL CCK Rate */ -#define RATE_ALL_CCK RATR_1M|RATR_2M|RATR_55M|RATR_11M -#define RATE_ALL_OFDM_AG RATR_6M|RATR_9M|RATR_12M|RATR_18M|RATR_24M|\ - RATR_36M|RATR_48M|RATR_54M -#define RATE_ALL_OFDM_1SS RATR_MCS0|RATR_MCS1|RATR_MCS2|RATR_MCS3 |\ - RATR_MCS4|RATR_MCS5|RATR_MCS6 |RATR_MCS7 -#define RATE_ALL_OFDM_2SS RATR_MCS8|RATR_MCS9 |RATR_MCS10|RATR_MCS11|\ - RATR_MCS12|RATR_MCS13|RATR_MCS14|RATR_MCS15 +#define RATE_ALL_CCK RATR_1M | RATR_2M | RATR_55M | RATR_11M +#define RATE_ALL_OFDM_AG RATR_6M | RATR_9M | RATR_12M | RATR_18M | RATR_24M |\ + RATR_36M | RATR_48M | RATR_54M +#define RATE_ALL_OFDM_1SS RATR_MCS0 | RATR_MCS1 | RATR_MCS2 | RATR_MCS3 |\ + RATR_MCS4 | RATR_MCS5 | RATR_MCS6 | RATR_MCS7 +#define RATE_ALL_OFDM_2SS RATR_MCS8 | RATR_MCS9 | RATR_MCS10 | RATR_MCS11 |\ + RATR_MCS12 | RATR_MCS13 | RATR_MCS14 | RATR_MCS15 #define RATE_BITMAP_ALL 0xFFFFF diff --git a/drivers/staging/rtl8723bs/include/hal_intf.h b/drivers/staging/rtl8723bs/include/hal_intf.h index 24926ebaf950..1de5acaef8ff 100644 --- a/drivers/staging/rtl8723bs/include/hal_intf.h +++ b/drivers/staging/rtl8723bs/include/hal_intf.h @@ -296,7 +296,7 @@ enum wowlan_subcode { WOWLAN_AP_DISABLE = 13 }; -struct wowlan_ioctl_param{ +struct wowlan_ioctl_param { unsigned int subcode; unsigned int subcode_value; unsigned int wakeup_reason; diff --git a/drivers/staging/rtl8723bs/include/hal_phy.h b/drivers/staging/rtl8723bs/include/hal_phy.h index c6b9bf139ef6..ed0caa0574e3 100644 --- a/drivers/staging/rtl8723bs/include/hal_phy.h +++ b/drivers/staging/rtl8723bs/include/hal_phy.h @@ -25,7 +25,7 @@ #define RF6052_MAX_REG_92C 0x7F #define RF6052_MAX_REG \ - (RF6052_MAX_REG_88E > RF6052_MAX_REG_92C) ? RF6052_MAX_REG_88E: RF6052_MAX_REG_92C + (RF6052_MAX_REG_88E > RF6052_MAX_REG_92C) ? RF6052_MAX_REG_88E : RF6052_MAX_REG_92C #define GET_RF6052_REAL_MAX_REG(_Adapter) RF6052_MAX_REG_92C diff --git a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h b/drivers/staging/rtl8723bs/include/hal_phy_cfg.h index b40868b2e76f..419ddb0733aa 100644 --- a/drivers/staging/rtl8723bs/include/hal_phy_cfg.h +++ b/drivers/staging/rtl8723bs/include/hal_phy_cfg.h @@ -58,9 +58,9 @@ u32 Data ); /* MAC/BB/RF HAL config */ -int PHY_BBConfig8723B(struct adapter *Adapter ); +int PHY_BBConfig8723B(struct adapter *Adapter); -int PHY_RFConfig8723B(struct adapter *Adapter ); +int PHY_RFConfig8723B(struct adapter *Adapter); s32 PHY_MACConfig8723B(struct adapter *padapter); diff --git a/drivers/staging/rtl8723bs/include/hal_pwr_seq.h b/drivers/staging/rtl8723bs/include/hal_pwr_seq.h index 130a94879805..28aca047dce6 100644 --- a/drivers/staging/rtl8723bs/include/hal_pwr_seq.h +++ b/drivers/staging/rtl8723bs/include/hal_pwr_seq.h @@ -46,9 +46,9 @@ {0x0001, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_DELAY, 1, PWRSEQ_DELAY_MS},/*Delay 1ms*/ \ {0x0000, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT5, 0}, /*0x00[5] = 1b'0 release analog Ips to digital , 1:isolation*/ \ {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, (BIT4|BIT3|BIT2), 0},/* disable SW LPS 0x04[10]= 0 and WLSUS_EN 0x04[11]= 0*/ \ - {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0 , BIT0},/* Disable USB suspend */ \ + {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, BIT0},/* Disable USB suspend */ \ {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT1, BIT1},/* wait till 0x04[17] = 1 power ready*/ \ - {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0 , 0},/* Enable USB suspend */ \ + {0x0075, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, 0},/* Enable USB suspend */ \ {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, BIT0},/* release WLON reset 0x04[16]= 1*/ \ {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, 0},/* disable HWPDN 0x04[15]= 0*/ \ {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK, PWR_BASEADDR_MAC, PWR_CMD_WRITE, (BIT4|BIT3), 0},/* disable WL suspend*/ \ diff --git a/drivers/staging/rtl8723bs/include/ieee80211.h b/drivers/staging/rtl8723bs/include/ieee80211.h index 2110552b8e59..7243e656d589 100644 --- a/drivers/staging/rtl8723bs/include/ieee80211.h +++ b/drivers/staging/rtl8723bs/include/ieee80211.h @@ -98,8 +98,8 @@ enum { #define WPA_SELECTOR_LEN 4 -extern u8 RTW_WPA_OUI_TYPE[] ; -extern u16 RTW_WPA_VERSION ; +extern u8 RTW_WPA_OUI_TYPE[]; +extern u16 RTW_WPA_VERSION; extern u8 WPA_AUTH_KEY_MGMT_NONE[]; extern u8 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X[]; extern u8 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X[]; @@ -139,7 +139,7 @@ typedef enum _RATEID_IDX_ { RATEID_IDX_VHT_1SS = 10, } RATEID_IDX, *PRATEID_IDX; -typedef enum _RATR_TABLE_MODE{ +typedef enum _RATR_TABLE_MODE { RATR_INX_WIRELESS_NGB = 0, /* BGN 40 Mhz 2SS 1SS */ RATR_INX_WIRELESS_NG = 1, /* GN or N */ RATR_INX_WIRELESS_NB = 2, /* BGN 20 Mhz 2SS 1SS or BN */ @@ -149,7 +149,7 @@ typedef enum _RATR_TABLE_MODE{ RATR_INX_WIRELESS_B = 6, RATR_INX_WIRELESS_MC = 7, RATR_INX_WIRELESS_AC_N = 8, -}RATR_TABLE_MODE, *PRATR_TABLE_MODE; +} RATR_TABLE_MODE, *PRATR_TABLE_MODE; enum NETWORK_TYPE @@ -248,7 +248,7 @@ struct ieee_param_ex { u8 data[0]; }; -struct sta_data{ +struct sta_data { u16 aid; u16 capability; int flags; @@ -439,7 +439,7 @@ struct ieee80211_snap_hdr { #define IEEE80211_OFDM_SHIFT_MASK_A 4 -enum MGN_RATE{ +enum MGN_RATE { MGN_1M = 0x02, MGN_2M = 0x04, MGN_5_5M = 0x0B, @@ -906,7 +906,7 @@ enum rtw_ieee80211_spectrum_mgmt_actioncode { RTW_WLAN_ACTION_SPCT_EXT_CHL_SWITCH = 5, }; -enum _PUBLIC_ACTION{ +enum _PUBLIC_ACTION { ACT_PUBLIC_BSSCOEXIST = 0, /* 20/40 BSS Coexistence */ ACT_PUBLIC_DSE_ENABLE = 1, ACT_PUBLIC_DSE_DEENABLE = 2, @@ -953,7 +953,7 @@ enum rtw_ieee80211_back_parties { }; /* VHT features action code */ -enum rtw_ieee80211_vht_actioncode{ +enum rtw_ieee80211_vht_actioncode { RTW_WLAN_ACTION_VHT_COMPRESSED_BEAMFORMING = 0, RTW_WLAN_ACTION_VHT_GROUPID_MANAGEMENT = 1, RTW_WLAN_ACTION_VHT_OPMODE_NOTIFICATION = 2, @@ -1128,7 +1128,7 @@ u8 *rtw_get_ie(u8*pbuf, sint index, sint *len, sint limit); u8 *rtw_get_ie_ex(u8 *in_ie, uint in_len, u8 eid, u8 *oui, u8 oui_len, u8 *ie, uint *ielen); int rtw_ies_remove_ie(u8 *ies, uint *ies_len, uint offset, u8 eid, u8 *oui, u8 oui_len); -void rtw_set_supported_rate(u8 *SupportedRates, uint mode) ; +void rtw_set_supported_rate(u8 *SupportedRates, uint mode); unsigned char *rtw_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit); unsigned char *rtw_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit); @@ -1142,8 +1142,8 @@ void rtw_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie u8 rtw_is_wps_ie(u8 *ie_ptr, uint *wps_ielen); u8 *rtw_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen); -u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_attr, u32 *len_attr); -u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id , u8 *buf_content, uint *len_content); +u8 *rtw_get_wps_attr(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_attr, u32 *len_attr); +u8 *rtw_get_wps_attr_content(u8 *wps_ie, uint wps_ielen, u16 target_attr_id, u8 *buf_content, uint *len_content); /** * for_each_ie - iterate over continuous IEs diff --git a/drivers/staging/rtl8723bs/include/osdep_intf.h b/drivers/staging/rtl8723bs/include/osdep_intf.h index fa16139fcce6..c59c1384944b 100644 --- a/drivers/staging/rtl8723bs/include/osdep_intf.h +++ b/drivers/staging/rtl8723bs/include/osdep_intf.h @@ -50,7 +50,7 @@ void rtw_reset_drv_sw(struct adapter *padapter); void rtw_dev_unload(struct adapter *padapter); u32 rtw_start_drv_threads(struct adapter *padapter); -void rtw_stop_drv_threads (struct adapter *padapter); +void rtw_stop_drv_threads(struct adapter *padapter); void rtw_cancel_all_timer(struct adapter *padapter); int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); diff --git a/drivers/staging/rtl8723bs/include/osdep_service.h b/drivers/staging/rtl8723bs/include/osdep_service.h index a40cf7b60a69..5f681899bbec 100644 --- a/drivers/staging/rtl8723bs/include/osdep_service.h +++ b/drivers/staging/rtl8723bs/include/osdep_service.h @@ -80,7 +80,7 @@ enum mstat_f { #define mstat_tf_idx(flags) ((flags)&0xff) #define mstat_ff_idx(flags) (((flags)&0xff00) >> 8) -typedef enum mstat_status{ +typedef enum mstat_status { MSTAT_ALLOC_SUCCESS = 0, MSTAT_ALLOC_FAIL, MSTAT_FREE @@ -117,7 +117,7 @@ static inline void thread_enter(char *name) static inline void flush_signals_thread(void) { - if (signal_pending (current)) + if (signal_pending(current)) { flush_signals(current); } @@ -134,14 +134,14 @@ static inline int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *par } #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r)) -#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2) +#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0 : 1)) << 2) static inline u32 _RND4(u32 sz) { u32 val; - val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2; + val = ((sz >> 2) + ((sz & 3) ? 1 : 0)) << 2; return val; @@ -152,7 +152,7 @@ static inline u32 _RND8(u32 sz) u32 val; - val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3; + val = ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3; return val; diff --git a/drivers/staging/rtl8723bs/include/osdep_service_linux.h b/drivers/staging/rtl8723bs/include/osdep_service_linux.h index a2d9de866c4b..1710fa3eeb71 100644 --- a/drivers/staging/rtl8723bs/include/osdep_service_linux.h +++ b/drivers/staging/rtl8723bs/include/osdep_service_linux.h @@ -80,7 +80,7 @@ static inline struct list_head *get_list_head(struct __queue *queue) static inline void _set_timer(_timer *ptimer, u32 delay_time) { - mod_timer(ptimer , (jiffies+(delay_time*HZ/1000))); + mod_timer(ptimer, (jiffies + (delay_time * HZ / 1000))); } static inline void _cancel_timer(_timer *ptimer, u8 *bcancelled) diff --git a/drivers/staging/rtl8723bs/include/recv_osdep.h b/drivers/staging/rtl8723bs/include/recv_osdep.h index 1056f615d0f9..e85aafc93f6d 100644 --- a/drivers/staging/rtl8723bs/include/recv_osdep.h +++ b/drivers/staging/rtl8723bs/include/recv_osdep.h @@ -9,7 +9,7 @@ extern sint _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter); -extern void _rtw_free_recv_priv (struct recv_priv *precvpriv); +extern void _rtw_free_recv_priv(struct recv_priv *precvpriv); extern s32 rtw_recv_entry(union recv_frame *precv_frame); @@ -19,7 +19,7 @@ extern void rtw_recv_returnpacket(_nic_hdl cnxt, _pkt *preturnedpkt); extern void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup); int rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter); -void rtw_free_recv_priv (struct recv_priv *precvpriv); +void rtw_free_recv_priv(struct recv_priv *precvpriv); void rtw_os_recv_resource_alloc(struct adapter *padapter, union recv_frame *precvframe); diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h b/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h index ecfd2d383ac2..3bfb0e9be582 100644 --- a/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h +++ b/drivers/staging/rtl8723bs/include/rtl8723b_cmd.h @@ -11,7 +11,7 @@ /* H2C CMD DEFINITION ------------------------------------------------ */ /* */ -enum h2c_cmd_8723B{ +enum h2c_cmd_8723B { /* Common Class: 000 */ H2C_8723B_RSVD_PAGE = 0x00, H2C_8723B_MEDIA_STATUS_RPT = 0x01, diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_rf.h b/drivers/staging/rtl8723bs/include/rtl8723b_rf.h index 987b9f12a4f4..d712c6d36a08 100644 --- a/drivers/staging/rtl8723bs/include/rtl8723b_rf.h +++ b/drivers/staging/rtl8723bs/include/rtl8723b_rf.h @@ -8,7 +8,7 @@ #define __RTL8723B_RF_H__ -int PHY_RF6052_Config8723B(struct adapter *Adapter ); +int PHY_RF6052_Config8723B(struct adapter *Adapter); void PHY_RF6052SetBandwidth8723B(struct adapter *Adapter, diff --git a/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h b/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h index 23a6069c3e5d..320ca65e5faa 100644 --- a/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h +++ b/drivers/staging/rtl8723bs/include/rtl8723b_xmit.h @@ -176,7 +176,7 @@ typedef struct txdesc_8723b u32 txbf_path:1; u32 seq:12; u32 final_data_rate:8; -}TXDESC_8723B, *PTXDESC_8723B; +} TXDESC_8723B, *PTXDESC_8723B; #ifndef __INC_HAL8723BDESC_H #define __INC_HAL8723BDESC_H diff --git a/drivers/staging/rtl8723bs/include/rtw_byteorder.h b/drivers/staging/rtl8723bs/include/rtw_byteorder.h index f76fbfbed4c7..c3a65f971793 100644 --- a/drivers/staging/rtl8723bs/include/rtw_byteorder.h +++ b/drivers/staging/rtl8723bs/include/rtw_byteorder.h @@ -7,7 +7,7 @@ #ifndef _RTL871X_BYTEORDER_H_ #define _RTL871X_BYTEORDER_H_ -#if defined (__LITTLE_ENDIAN) +#if defined(__LITTLE_ENDIAN) #include <linux/byteorder/little_endian.h> #else # include <linux/byteorder/big_endian.h> diff --git a/drivers/staging/rtl8723bs/include/rtw_cmd.h b/drivers/staging/rtl8723bs/include/rtw_cmd.h index b83824ca2e31..3e025a652e38 100644 --- a/drivers/staging/rtl8723bs/include/rtw_cmd.h +++ b/drivers/staging/rtl8723bs/include/rtw_cmd.h @@ -75,7 +75,7 @@ do {\ INIT_LIST_HEAD(&pcmd->list);\ pcmd->cmdcode = code;\ pcmd->parmbuf = (u8 *)(pparm);\ - pcmd->cmdsz = sizeof (*pparm);\ + pcmd->cmdsz = sizeof(*pparm);\ pcmd->rsp = NULL;\ pcmd->rspsz = 0;\ } while (0) @@ -129,9 +129,9 @@ extern void rtw_free_cmd_obj(struct cmd_obj *pcmd); void rtw_stop_cmd_thread(struct adapter *adapter); int rtw_cmd_thread(void *context); -extern void rtw_free_cmd_priv (struct cmd_priv *pcmdpriv); +extern void rtw_free_cmd_priv(struct cmd_priv *pcmdpriv); -extern void rtw_free_evt_priv (struct evt_priv *pevtpriv); +extern void rtw_free_evt_priv(struct evt_priv *pevtpriv); extern void rtw_evt_notify_isr(struct evt_priv *pevtpriv); enum rtw_drvextra_cmd_id @@ -163,10 +163,10 @@ enum LPS_CTRL_TYPE { LPS_CTRL_SCAN = 0, LPS_CTRL_JOINBSS = 1, - LPS_CTRL_CONNECT =2, - LPS_CTRL_DISCONNECT =3, - LPS_CTRL_SPECIAL_PACKET =4, - LPS_CTRL_LEAVE =5, + LPS_CTRL_CONNECT = 2, + LPS_CTRL_DISCONNECT = 3, + LPS_CTRL_SPECIAL_PACKET = 4, + LPS_CTRL_LEAVE = 5, LPS_CTRL_TRAFFIC_BUSY = 6, }; @@ -692,40 +692,40 @@ struct getratable_rsp { /* to get TX, RX retry count */ -struct gettxretrycnt_parm{ +struct gettxretrycnt_parm { unsigned int rsvd; }; -struct gettxretrycnt_rsp{ +struct gettxretrycnt_rsp { unsigned long tx_retrycnt; }; -struct getrxretrycnt_parm{ +struct getrxretrycnt_parm { unsigned int rsvd; }; -struct getrxretrycnt_rsp{ +struct getrxretrycnt_rsp { unsigned long rx_retrycnt; }; /* to get BCNOK, BCNERR count */ -struct getbcnokcnt_parm{ +struct getbcnokcnt_parm { unsigned int rsvd; }; -struct getbcnokcnt_rsp{ +struct getbcnokcnt_rsp { unsigned long bcnokcnt; }; -struct getbcnerrcnt_parm{ +struct getbcnerrcnt_parm { unsigned int rsvd; }; -struct getbcnerrcnt_rsp{ +struct getbcnerrcnt_rsp { unsigned long bcnerrcnt; }; /* to get current TX power level */ -struct getcurtxpwrlevel_parm{ +struct getcurtxpwrlevel_parm { unsigned int rsvd; }; -struct getcurtxpwrlevel_rsp{ +struct getcurtxpwrlevel_rsp { unsigned short tx_power; }; @@ -883,56 +883,56 @@ struct _cmd_callback { enum rtw_h2c_cmd { - GEN_CMD_CODE(_Read_MACREG) , /*0*/ - GEN_CMD_CODE(_Write_MACREG) , - GEN_CMD_CODE(_Read_BBREG) , - GEN_CMD_CODE(_Write_BBREG) , - GEN_CMD_CODE(_Read_RFREG) , - GEN_CMD_CODE(_Write_RFREG) , /*5*/ - GEN_CMD_CODE(_Read_EEPROM) , - GEN_CMD_CODE(_Write_EEPROM) , - GEN_CMD_CODE(_Read_EFUSE) , - GEN_CMD_CODE(_Write_EFUSE) , - - GEN_CMD_CODE(_Read_CAM) , /*10*/ - GEN_CMD_CODE(_Write_CAM) , + GEN_CMD_CODE(_Read_MACREG), /*0*/ + GEN_CMD_CODE(_Write_MACREG), + GEN_CMD_CODE(_Read_BBREG), + GEN_CMD_CODE(_Write_BBREG), + GEN_CMD_CODE(_Read_RFREG), + GEN_CMD_CODE(_Write_RFREG), /*5*/ + GEN_CMD_CODE(_Read_EEPROM), + GEN_CMD_CODE(_Write_EEPROM), + GEN_CMD_CODE(_Read_EFUSE), + GEN_CMD_CODE(_Write_EFUSE), + + GEN_CMD_CODE(_Read_CAM), /*10*/ + GEN_CMD_CODE(_Write_CAM), GEN_CMD_CODE(_setBCNITV), GEN_CMD_CODE(_setMBIDCFG), GEN_CMD_CODE(_JoinBss), /*14*/ - GEN_CMD_CODE(_DisConnect) , /*15*/ - GEN_CMD_CODE(_CreateBss) , - GEN_CMD_CODE(_SetOpMode) , + GEN_CMD_CODE(_DisConnect), /*15*/ + GEN_CMD_CODE(_CreateBss), + GEN_CMD_CODE(_SetOpMode), GEN_CMD_CODE(_SiteSurvey), /*18*/ - GEN_CMD_CODE(_SetAuth) , - - GEN_CMD_CODE(_SetKey) , /*20*/ - GEN_CMD_CODE(_SetStaKey) , - GEN_CMD_CODE(_SetAssocSta) , - GEN_CMD_CODE(_DelAssocSta) , - GEN_CMD_CODE(_SetStaPwrState) , - GEN_CMD_CODE(_SetBasicRate) , /*25*/ - GEN_CMD_CODE(_GetBasicRate) , - GEN_CMD_CODE(_SetDataRate) , - GEN_CMD_CODE(_GetDataRate) , - GEN_CMD_CODE(_SetPhyInfo) , - - GEN_CMD_CODE(_GetPhyInfo) , /*30*/ - GEN_CMD_CODE(_SetPhy) , - GEN_CMD_CODE(_GetPhy) , - GEN_CMD_CODE(_readRssi) , - GEN_CMD_CODE(_readGain) , - GEN_CMD_CODE(_SetAtim) , /*35*/ - GEN_CMD_CODE(_SetPwrMode) , + GEN_CMD_CODE(_SetAuth), + + GEN_CMD_CODE(_SetKey), /*20*/ + GEN_CMD_CODE(_SetStaKey), + GEN_CMD_CODE(_SetAssocSta), + GEN_CMD_CODE(_DelAssocSta), + GEN_CMD_CODE(_SetStaPwrState), + GEN_CMD_CODE(_SetBasicRate), /*25*/ + GEN_CMD_CODE(_GetBasicRate), + GEN_CMD_CODE(_SetDataRate), + GEN_CMD_CODE(_GetDataRate), + GEN_CMD_CODE(_SetPhyInfo), + + GEN_CMD_CODE(_GetPhyInfo), /*30*/ + GEN_CMD_CODE(_SetPhy), + GEN_CMD_CODE(_GetPhy), + GEN_CMD_CODE(_readRssi), + GEN_CMD_CODE(_readGain), + GEN_CMD_CODE(_SetAtim), /*35*/ + GEN_CMD_CODE(_SetPwrMode), GEN_CMD_CODE(_JoinbssRpt), - GEN_CMD_CODE(_SetRaTable) , - GEN_CMD_CODE(_GetRaTable) , + GEN_CMD_CODE(_SetRaTable), + GEN_CMD_CODE(_GetRaTable), GEN_CMD_CODE(_GetCCXReport), /*40*/ GEN_CMD_CODE(_GetDTMReport), GEN_CMD_CODE(_GetTXRateStatistics), GEN_CMD_CODE(_SetUsbSuspend), GEN_CMD_CODE(_SetH2cLbk), - GEN_CMD_CODE(_AddBAReq) , /*45*/ + GEN_CMD_CODE(_AddBAReq), /*45*/ GEN_CMD_CODE(_SetChannel), /*46*/ GEN_CMD_CODE(_SetTxPower), GEN_CMD_CODE(_SwitchAntenna), diff --git a/drivers/staging/rtl8723bs/include/rtw_debug.h b/drivers/staging/rtl8723bs/include/rtw_debug.h index 22fc5d730d7b..c90adfb87261 100644 --- a/drivers/staging/rtl8723bs/include/rtw_debug.h +++ b/drivers/staging/rtl8723bs/include/rtw_debug.h @@ -131,13 +131,13 @@ #define _MODULE_DEFINE_ _module_efuse_ #endif -#define RT_TRACE(_Comp, _Level, Fmt) do{}while (0) -#define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) do{}while (0) +#define RT_TRACE(_Comp, _Level, Fmt) do {} while (0) +#define RT_PRINT_DATA(_Comp, _Level, _TitleString, _HexData, _HexDataLen) do {} while (0) #define DBG_871X(x, ...) do {} while (0) #define MSG_8192C(x, ...) do {} while (0) -#define DBG_8192C(x,...) do {} while (0) -#define DBG_871X_LEVEL(x,...) do {} while (0) +#define DBG_8192C(x, ...) do {} while (0) +#define DBG_871X_LEVEL(x, ...) do {} while (0) #undef _dbgdump @@ -161,8 +161,8 @@ _dbgdump(DRIVER_PREFIX"ERROR " fmt, ##arg);\ else \ _dbgdump(DRIVER_PREFIX fmt, ##arg);\ - }\ - }while (0) + } \ + } while (0) /* without driver-defined prefix */ #undef _DBG_871X_LEVEL @@ -173,8 +173,8 @@ _dbgdump("ERROR " fmt, ##arg);\ else \ _dbgdump(fmt, ##arg);\ - }\ - }while (0) + } \ + } while (0) #define RTW_DBGDUMP NULL /* 'stream' for _dbgdump */ @@ -203,17 +203,17 @@ #undef DBG_871X #define DBG_871X(...) do {\ _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while (0) + } while (0) #undef MSG_8192C #define MSG_8192C(...) do {\ _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while (0) + } while (0) #undef DBG_8192C #define DBG_8192C(...) do {\ _dbgdump(DRIVER_PREFIX __VA_ARGS__);\ - }while (0) + } while (0) #endif /* defined(_dbgdump) */ #endif /* DEBUG */ @@ -227,8 +227,8 @@ if ((_Comp & GlobalDebugComponents) && (_Level <= GlobalDebugLevel)) {\ _dbgdump("%s [0x%08x,%d]", DRIVER_PREFIX, (unsigned int)_Comp, _Level);\ _dbgdump Fmt;\ - }\ - }while (0) + } \ + } while (0) #endif /* defined(_dbgdump) && defined(_MODULE_DEFINE_) */ @@ -242,7 +242,7 @@ u8 *ptr = (u8 *)_HexData; \ _dbgdump("%s", DRIVER_PREFIX); \ _dbgdump(_TitleString); \ - for (__i = 0; __i<(int)_HexDataLen; __i++) \ + for (__i = 0; __i < (int)_HexDataLen; __i++) \ { \ _dbgdump("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" "); \ if (((__i + 1) % 16) == 0) _dbgdump("\n"); \ diff --git a/drivers/staging/rtl8723bs/include/rtw_eeprom.h b/drivers/staging/rtl8723bs/include/rtw_eeprom.h index 1fcd79fa1c21..704c6461333a 100644 --- a/drivers/staging/rtl8723bs/include/rtw_eeprom.h +++ b/drivers/staging/rtl8723bs/include/rtw_eeprom.h @@ -91,7 +91,7 @@ typedef enum _RT_CUSTOMER_ID RT_CID_819x_ALPHA_Dlink = 44,/* add by ylb 20121012 for customer led for alpha */ RT_CID_WNC_NEC = 45,/* add by page for NEC */ RT_CID_DNI_BUFFALO = 46,/* add by page for NEC */ -}RT_CUSTOMER_ID, *PRT_CUSTOMER_ID; +} RT_CUSTOMER_ID, *PRT_CUSTOMER_ID; struct eeprom_priv { diff --git a/drivers/staging/rtl8723bs/include/rtw_efuse.h b/drivers/staging/rtl8723bs/include/rtw_efuse.h index 9d9a5a3e336d..4abcbbc8f513 100644 --- a/drivers/staging/rtl8723bs/include/rtw_efuse.h +++ b/drivers/staging/rtl8723bs/include/rtw_efuse.h @@ -57,15 +57,15 @@ enum _EFUSE_DEF_TYPE { #define EFUSE_MAX_WORD_UNIT 4 /*------------------------------Define structure----------------------------*/ -typedef struct PG_PKT_STRUCT_A{ +typedef struct PG_PKT_STRUCT_A { u8 offset; u8 word_en; u8 data[8]; u8 word_cnts; -}PGPKT_STRUCT,*PPGPKT_STRUCT; +} PGPKT_STRUCT, *PPGPKT_STRUCT; /*------------------------------Define structure----------------------------*/ -typedef struct _EFUSE_HAL{ +typedef struct _EFUSE_HAL { u8 fakeEfuseBank; u32 fakeEfuseUsedBytes; u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE]; @@ -82,7 +82,7 @@ typedef struct _EFUSE_HAL{ u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE]; u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN]; u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN]; -}EFUSE_HAL, *PEFUSE_HAL; +} EFUSE_HAL, *PEFUSE_HAL; /*------------------------Export global variable----------------------------*/ diff --git a/drivers/staging/rtl8723bs/include/rtw_event.h b/drivers/staging/rtl8723bs/include/rtw_event.h index ee80aa21eb10..aeaabab780e5 100644 --- a/drivers/staging/rtl8723bs/include/rtw_event.h +++ b/drivers/staging/rtl8723bs/include/rtw_event.h @@ -82,7 +82,7 @@ struct fwevent { #define C2HEVENT_SZ 32 -struct event_node{ +struct event_node { unsigned char *node; unsigned char evt_code; unsigned short evt_sz; diff --git a/drivers/staging/rtl8723bs/include/rtw_ht.h b/drivers/staging/rtl8723bs/include/rtw_ht.h index 952c804dd0fd..4c224c128327 100644 --- a/drivers/staging/rtl8723bs/include/rtw_ht.h +++ b/drivers/staging/rtl8723bs/include/rtw_ht.h @@ -38,7 +38,7 @@ struct ht_priv }; -typedef enum AGGRE_SIZE{ +typedef enum AGGRE_SIZE { HT_AGG_SIZE_8K = 0, HT_AGG_SIZE_16K = 1, HT_AGG_SIZE_32K = 2, @@ -47,9 +47,9 @@ typedef enum AGGRE_SIZE{ VHT_AGG_SIZE_256K = 5, VHT_AGG_SIZE_512K = 6, VHT_AGG_SIZE_1024K = 7, -}AGGRE_SIZE_E, *PAGGRE_SIZE_E; +} AGGRE_SIZE_E, *PAGGRE_SIZE_E; -typedef enum _RT_HT_INF0_CAP{ +typedef enum _RT_HT_INF0_CAP { RT_HT_CAP_USE_TURBO_AGGR = 0x01, RT_HT_CAP_USE_LONG_PREAMBLE = 0x02, RT_HT_CAP_USE_AMPDU = 0x04, @@ -58,13 +58,13 @@ typedef enum _RT_HT_INF0_CAP{ RT_HT_CAP_USE_92SE = 0x20, RT_HT_CAP_USE_88C_92C = 0x40, RT_HT_CAP_USE_AP_CLIENT_MODE = 0x80, /* AP team request to reserve this bit, by Emily */ -}RT_HT_INF0_CAPBILITY, *PRT_HT_INF0_CAPBILITY; +} RT_HT_INF0_CAPBILITY, *PRT_HT_INF0_CAPBILITY; -typedef enum _RT_HT_INF1_CAP{ +typedef enum _RT_HT_INF1_CAP { RT_HT_CAP_USE_VIDEO_CLIENT = 0x01, RT_HT_CAP_USE_JAGUAR_BCUT = 0x02, RT_HT_CAP_USE_JAGUAR_CCUT = 0x04, -}RT_HT_INF1_CAPBILITY, *PRT_HT_INF1_CAPBILITY; +} RT_HT_INF1_CAPBILITY, *PRT_HT_INF1_CAPBILITY; #define LDPC_HT_ENABLE_RX BIT0 #define LDPC_HT_ENABLE_TX BIT1 diff --git a/drivers/staging/rtl8723bs/include/rtw_io.h b/drivers/staging/rtl8723bs/include/rtw_io.h index 99d104b3647a..2581b5165d1b 100644 --- a/drivers/staging/rtl8723bs/include/rtw_io.h +++ b/drivers/staging/rtl8723bs/include/rtw_io.h @@ -168,7 +168,7 @@ struct reg_protocol_rd { u32 Byte2Access : 1; u32 Byte1Access : 1; - u32 BurstMode :1 ; + u32 BurstMode :1; u32 FixOrContinuous : 1; u32 Reserved4 : 16; @@ -224,7 +224,7 @@ struct reg_protocol_wt { u32 Byte2Access : 1; u32 Byte1Access : 1; - u32 BurstMode :1 ; + u32 BurstMode :1; u32 FixOrContinuous : 1; u32 Reserved4 : 16; @@ -259,7 +259,7 @@ struct io_queue { struct intf_hdl intf; }; -struct io_priv{ +struct io_priv { struct adapter *padapter; diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme.h b/drivers/staging/rtl8723bs/include/rtw_mlme.h index 362737b83c3a..14e4bce28856 100644 --- a/drivers/staging/rtl8723bs/include/rtw_mlme.h +++ b/drivers/staging/rtl8723bs/include/rtw_mlme.h @@ -85,7 +85,7 @@ typedef enum _RT_SCAN_TYPE { SCAN_PASSIVE, SCAN_ACTIVE, SCAN_MIX, -}RT_SCAN_TYPE, *PRT_SCAN_TYPE; +} RT_SCAN_TYPE, *PRT_SCAN_TYPE; enum _BAND { GHZ24_50 = 0, @@ -135,7 +135,7 @@ struct sitesurvey_ctrl { _timer sitesurvey_ctrl_timer; }; -typedef struct _RT_LINK_DETECT_T{ +typedef struct _RT_LINK_DETECT_T { u32 NumTxOkInPeriod; u32 NumRxOkInPeriod; u32 NumRxUnicastOkInPeriod; @@ -148,62 +148,62 @@ typedef struct _RT_LINK_DETECT_T{ /* u8 TrafficBusyState; */ u8 TrafficTransitionCount; u32 LowPowerTransitionCount; -}RT_LINK_DETECT_T, *PRT_LINK_DETECT_T; +} RT_LINK_DETECT_T, *PRT_LINK_DETECT_T; struct profile_info { u8 ssidlen; - u8 ssid[ WLAN_SSID_MAXLEN ]; - u8 peermac[ ETH_ALEN ]; + u8 ssid[WLAN_SSID_MAXLEN]; + u8 peermac[ETH_ALEN]; }; -struct tx_invite_req_info{ +struct tx_invite_req_info { u8 token; u8 benable; - u8 go_ssid[ WLAN_SSID_MAXLEN ]; + u8 go_ssid[WLAN_SSID_MAXLEN]; u8 ssidlen; - u8 go_bssid[ ETH_ALEN ]; - u8 peer_macaddr[ ETH_ALEN ]; + u8 go_bssid[ETH_ALEN]; + u8 peer_macaddr[ETH_ALEN]; u8 operating_ch; /* This information will be set by using the p2p_set op_ch =x */ u8 peer_ch; /* The listen channel for peer P2P device */ }; -struct tx_invite_resp_info{ +struct tx_invite_resp_info { u8 token; /* Used to record the dialog token of p2p invitation request frame. */ }; -struct tx_provdisc_req_info{ +struct tx_provdisc_req_info { u16 wps_config_method_request; /* Used when sending the provisioning request frame */ u16 peer_channel_num[2]; /* The channel number which the receiver stands. */ struct ndis_802_11_ssid ssid; - u8 peerDevAddr[ ETH_ALEN ]; /* Peer device address */ - u8 peerIFAddr[ ETH_ALEN ]; /* Peer interface address */ + u8 peerDevAddr[ETH_ALEN]; /* Peer device address */ + u8 peerIFAddr[ETH_ALEN]; /* Peer interface address */ u8 benable; /* This provision discovery request frame is trigger to send or not */ }; -struct rx_provdisc_req_info{ /* When peer device issue prov_disc_req first, we should store the following informations */ - u8 peerDevAddr[ ETH_ALEN ]; /* Peer device address */ +struct rx_provdisc_req_info { /* When peer device issue prov_disc_req first, we should store the following informations */ + u8 peerDevAddr[ETH_ALEN]; /* Peer device address */ u8 strconfig_method_desc_of_prov_disc_req[4]; /* description for the config method located in the provisioning discovery request frame. */ /* The UI must know this information to know which config method the remote p2p device is requiring. */ }; -struct tx_nego_req_info{ +struct tx_nego_req_info { u16 peer_channel_num[2]; /* The channel number which the receiver stands. */ - u8 peerDevAddr[ ETH_ALEN ]; /* Peer device address */ + u8 peerDevAddr[ETH_ALEN]; /* Peer device address */ u8 benable; /* This negoitation request frame is trigger to send or not */ }; -struct group_id_info{ - u8 go_device_addr[ ETH_ALEN ]; /* The GO's device address of this P2P group */ - u8 ssid[ WLAN_SSID_MAXLEN ]; /* The SSID of this P2P group */ +struct group_id_info { + u8 go_device_addr[ETH_ALEN]; /* The GO's device address of this P2P group */ + u8 ssid[WLAN_SSID_MAXLEN]; /* The SSID of this P2P group */ }; -struct scan_limit_info{ +struct scan_limit_info { u8 scan_op_ch_only; /* When this flag is set, the driver should just scan the operation channel */ u8 operation_ch[2]; /* Store the operation channel of invitation request frame */ }; -struct cfg80211_wifidirect_info{ +struct cfg80211_wifidirect_info { _timer remain_on_ch_timer; u8 restore_channel; struct ieee80211_channel remain_on_ch_channel; @@ -213,7 +213,7 @@ struct cfg80211_wifidirect_info{ unsigned long last_ro_ch_time; /* this will be updated at the beginning and end of ro_ch */ }; -struct wifidirect_info{ +struct wifidirect_info { struct adapter * padapter; _timer find_phase_timer; _timer restore_p2p_state_timer; @@ -225,7 +225,7 @@ struct wifidirect_info{ struct tx_provdisc_req_info tx_prov_disc_info; struct rx_provdisc_req_info rx_prov_disc_info; struct tx_invite_req_info invitereq_info; - struct profile_info profileinfo[ P2P_MAX_PERSISTENT_GROUP_NUM ]; /* Store the profile information of persistent group */ + struct profile_info profileinfo[P2P_MAX_PERSISTENT_GROUP_NUM]; /* Store the profile information of persistent group */ struct tx_invite_resp_info inviteresp_info; struct tx_nego_req_info nego_req_info; struct group_id_info groupid_info; /* Store the group id information when doing the group negotiation handshake. */ @@ -243,17 +243,17 @@ struct wifidirect_info{ u8 support_rate[8]; u8 p2p_wildcard_ssid[P2P_WILDCARD_SSID_LEN]; u8 intent; /* should only include the intent value. */ - u8 p2p_peer_interface_addr[ ETH_ALEN ]; - u8 p2p_peer_device_addr[ ETH_ALEN ]; + u8 p2p_peer_interface_addr[ETH_ALEN]; + u8 p2p_peer_device_addr[ETH_ALEN]; u8 peer_intent; /* Included the intent value and tie breaker value. */ - u8 device_name[ WPS_MAX_DEVICE_NAME_LEN ]; /* Device name for displaying on searching device screen */ + u8 device_name[WPS_MAX_DEVICE_NAME_LEN]; /* Device name for displaying on searching device screen */ u8 device_name_len; u8 profileindex; /* Used to point to the index of profileinfo array */ u8 peer_operating_ch; u8 find_phase_state_exchange_cnt; u16 device_password_id_for_nego; /* The device password ID for group negotation */ u8 negotiation_dialog_token; - u8 nego_ssid[ WLAN_SSID_MAXLEN ]; /* SSID information for group negotitation */ + u8 nego_ssid[WLAN_SSID_MAXLEN]; /* SSID information for group negotitation */ u8 nego_ssidlen; u8 p2p_group_ssid[WLAN_SSID_MAXLEN]; u8 p2p_group_ssid_len; @@ -287,13 +287,13 @@ struct wifidirect_info{ u8 driver_interface; /* Indicate DRIVER_WEXT or DRIVER_CFG80211 */ }; -struct tdls_ss_record{ /* signal strength record */ +struct tdls_ss_record { /* signal strength record */ u8 macaddr[ETH_ALEN]; u8 rx_pwd_ba11; u8 is_tdls_sta; /* true: direct link sta, false: else */ }; -struct tdls_info{ +struct tdls_info { u8 ap_prohibited; u8 link_established; u8 sta_cnt; @@ -489,7 +489,7 @@ int event_thread(void *context); extern void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall); extern int rtw_init_mlme_priv(struct adapter *adapter);/* (struct mlme_priv *pmlmepriv); */ -extern void rtw_free_mlme_priv (struct mlme_priv *pmlmepriv); +extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv); extern sint rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv); @@ -526,7 +526,7 @@ static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state) { pmlmepriv->fw_state |= state; /* FOR HW integration */ - if (_FW_UNDER_SURVEY ==state) { + if (_FW_UNDER_SURVEY == state) { pmlmepriv->bScanInProcess = true; } } @@ -535,7 +535,7 @@ static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state) { pmlmepriv->fw_state &= ~state; /* FOR HW integration */ - if (_FW_UNDER_SURVEY ==state) { + if (_FW_UNDER_SURVEY == state) { pmlmepriv->bScanInProcess = false; } } diff --git a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h index 73e8ec09b6e1..6c1ed6211c7e 100644 --- a/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +++ b/drivers/staging/rtl8723bs/include/rtw_mlme_ext.h @@ -182,7 +182,7 @@ typedef enum _RT_CHANNEL_DOMAIN /* Add new channel plan above this line =============== */ RT_CHANNEL_DOMAIN_MAX, RT_CHANNEL_DOMAIN_REALTEK_DEFINE = 0x7F, -}RT_CHANNEL_DOMAIN, *PRT_CHANNEL_DOMAIN; +} RT_CHANNEL_DOMAIN, *PRT_CHANNEL_DOMAIN; typedef enum _RT_CHANNEL_DOMAIN_2G { @@ -195,7 +195,7 @@ typedef enum _RT_CHANNEL_DOMAIN_2G RT_CHANNEL_DOMAIN_2G_NULL = 0x06, /* Add new channel plan above this line =============== */ RT_CHANNEL_DOMAIN_2G_MAX, -}RT_CHANNEL_DOMAIN_2G, *PRT_CHANNEL_DOMAIN_2G; +} RT_CHANNEL_DOMAIN_2G, *PRT_CHANNEL_DOMAIN_2G; typedef enum _RT_CHANNEL_DOMAIN_5G { @@ -237,33 +237,33 @@ typedef enum _RT_CHANNEL_DOMAIN_5G RT_CHANNEL_DOMAIN_5G_JAPAN_NO_DFS = 0x21, RT_CHANNEL_DOMAIN_5G_FCC4_NO_DFS = 0x22, RT_CHANNEL_DOMAIN_5G_MAX, -}RT_CHANNEL_DOMAIN_5G, *PRT_CHANNEL_DOMAIN_5G; +} RT_CHANNEL_DOMAIN_5G, *PRT_CHANNEL_DOMAIN_5G; -#define rtw_is_channel_plan_valid(chplan) (chplan<RT_CHANNEL_DOMAIN_MAX || chplan == RT_CHANNEL_DOMAIN_REALTEK_DEFINE) +#define rtw_is_channel_plan_valid(chplan) (chplan < RT_CHANNEL_DOMAIN_MAX || chplan == RT_CHANNEL_DOMAIN_REALTEK_DEFINE) typedef struct _RT_CHANNEL_PLAN { unsigned char Channel[MAX_CHANNEL_NUM]; unsigned char Len; -}RT_CHANNEL_PLAN, *PRT_CHANNEL_PLAN; +} RT_CHANNEL_PLAN, *PRT_CHANNEL_PLAN; typedef struct _RT_CHANNEL_PLAN_2G { unsigned char Channel[MAX_CHANNEL_NUM_2G]; unsigned char Len; -}RT_CHANNEL_PLAN_2G, *PRT_CHANNEL_PLAN_2G; +} RT_CHANNEL_PLAN_2G, *PRT_CHANNEL_PLAN_2G; typedef struct _RT_CHANNEL_PLAN_5G { unsigned char Channel[MAX_CHANNEL_NUM_5G]; unsigned char Len; -}RT_CHANNEL_PLAN_5G, *PRT_CHANNEL_PLAN_5G; +} RT_CHANNEL_PLAN_5G, *PRT_CHANNEL_PLAN_5G; typedef struct _RT_CHANNEL_PLAN_MAP { unsigned char Index2G; unsigned char Index5G; -}RT_CHANNEL_PLAN_MAP, *PRT_CHANNEL_PLAN_MAP; +} RT_CHANNEL_PLAN_MAP, *PRT_CHANNEL_PLAN_MAP; enum Associated_AP { @@ -299,7 +299,7 @@ typedef enum _HT_IOT_PEER HT_IOT_PEER_REALTEK_JAGUAR_BCUTAP = 16, HT_IOT_PEER_REALTEK_JAGUAR_CCUTAP = 17, HT_IOT_PEER_MAX = 18 -}HT_IOT_PEER_E, *PHTIOT_PEER_E; +} HT_IOT_PEER_E, *PHTIOT_PEER_E; enum SCAN_STATE @@ -353,7 +353,7 @@ struct ss_res #define WIFI_FW_ASSOC_STATE 0x00002000 #define WIFI_FW_ASSOC_SUCCESS 0x00004000 -#define WIFI_FW_LINKING_STATE (WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE | WIFI_FW_AUTH_SUCCESS |WIFI_FW_ASSOC_STATE) +#define WIFI_FW_LINKING_STATE (WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE | WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE) struct FW_Sta_Info { @@ -434,7 +434,7 @@ typedef struct _RT_CHANNEL_INFO { u8 ChannelNum; /* The channel number. */ RT_SCAN_TYPE ScanType; /* Scan type such as passive or active scan. */ -}RT_CHANNEL_INFO, *PRT_CHANNEL_INFO; +} RT_CHANNEL_INFO, *PRT_CHANNEL_INFO; int rtw_ch_set_search_ch(RT_CHANNEL_INFO *ch_set, const u32 ch); bool rtw_mlme_band_check(struct adapter *adapter, const u32 ch); @@ -537,7 +537,7 @@ struct mlme_ext_priv void init_mlme_default_rate_set(struct adapter *padapter); void init_mlme_ext_priv(struct adapter *padapter); int init_hw_mlme_ext(struct adapter *padapter); -void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext); +void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext); extern void init_mlme_ext_timer(struct adapter *padapter); extern void init_addba_retry_timer(struct adapter *padapter, struct sta_info *psta); extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv); @@ -571,7 +571,7 @@ void SelectChannel(struct adapter *padapter, unsigned char channel); unsigned int decide_wait_for_beacon_timeout(unsigned int bcn_interval); -void read_cam(struct adapter *padapter , u8 entry, u8 *get_key); +void read_cam(struct adapter *padapter, u8 entry, u8 *get_key); /* modify HW only */ void _write_cam(struct adapter *padapter, u8 entry, u16 ctrl, u8 *mac, u8 *key); @@ -708,8 +708,8 @@ void linked_status_chk(struct adapter *padapter); void _linked_info_dump(struct adapter *padapter); -void survey_timer_hdl (struct timer_list *t); -void link_timer_hdl (struct timer_list *t); +void survey_timer_hdl(struct timer_list *t); +void link_timer_hdl(struct timer_list *t); void addba_timer_hdl(struct timer_list *t); void sa_query_timer_hdl(struct timer_list *t); /* void reauth_timer_hdl(struct adapter *padapter); */ @@ -802,8 +802,8 @@ struct C2HEvent_Header unsigned int rsvd; }; -void rtw_dummy_event_callback(struct adapter *adapter , u8 *pbuf); -void rtw_fwdbg_event_callback(struct adapter *adapter , u8 *pbuf); +void rtw_dummy_event_callback(struct adapter *adapter, u8 *pbuf); +void rtw_fwdbg_event_callback(struct adapter *adapter, u8 *pbuf); enum rtw_c2h_event { @@ -818,10 +818,10 @@ enum rtw_c2h_event GEN_EVT_CODE(_Survey), /*8*/ GEN_EVT_CODE(_SurveyDone), /*9*/ - GEN_EVT_CODE(_JoinBss) , /*10*/ + GEN_EVT_CODE(_JoinBss), /*10*/ GEN_EVT_CODE(_AddSTA), GEN_EVT_CODE(_DelSTA), - GEN_EVT_CODE(_AtimDone) , + GEN_EVT_CODE(_AtimDone), GEN_EVT_CODE(_TX_Report), GEN_EVT_CODE(_CCX_Report), /*15*/ GEN_EVT_CODE(_DTM_Report), @@ -851,7 +851,7 @@ static struct fwevent wlanevents[] = {0, NULL}, {0, NULL}, {0, &rtw_survey_event_callback}, /*8*/ - {sizeof (struct surveydone_event), &rtw_surveydone_event_callback}, /*9*/ + {sizeof(struct surveydone_event), &rtw_surveydone_event_callback}, /*9*/ {0, &rtw_joinbss_event_callback}, /*10*/ {sizeof(struct stassoc_event), &rtw_stassoc_event_callback}, diff --git a/drivers/staging/rtl8723bs/include/rtw_mp.h b/drivers/staging/rtl8723bs/include/rtw_mp.h index bb3970d58573..e5a801b40582 100644 --- a/drivers/staging/rtl8723bs/include/rtw_mp.h +++ b/drivers/staging/rtl8723bs/include/rtw_mp.h @@ -154,7 +154,7 @@ typedef struct _MPT_CONTEXT u32 mptOutLen; u8 mptOutBuf[100]; -}MPT_CONTEXT, *PMPT_CONTEXT; +} MPT_CONTEXT, *PMPT_CONTEXT; /* endif */ /* E-Fuse */ @@ -276,7 +276,7 @@ typedef struct _IOCMD_STRUCT_ { u8 cmdclass; u16 value; u8 index; -}IOCMD_STRUCT; +} IOCMD_STRUCT; struct rf_reg_param { u32 path; @@ -315,7 +315,7 @@ extern u8 mpdatarate[NumRates]; /* MP set force data rate base on the definition. */ enum MPT_RATE_INDEX { /* CCK rate. */ - MPT_RATE_1M = 0 , /* 0 */ + MPT_RATE_1M = 0, /* 0 */ MPT_RATE_2M, MPT_RATE_55M, MPT_RATE_11M, /* 3 */ @@ -473,9 +473,9 @@ void Hal_SetBandwidth(struct adapter *padapter); void Hal_SetTxPower(struct adapter *padapter); void Hal_SetCarrierSuppressionTx(struct adapter *padapter, u8 bStart); -void Hal_SetSingleToneTx (struct adapter *padapter , u8 bStart); -void Hal_SetSingleCarrierTx (struct adapter *padapter, u8 bStart); -void Hal_SetContinuousTx (struct adapter *padapter, u8 bStart); +void Hal_SetSingleToneTx(struct adapter *padapter, u8 bStart); +void Hal_SetSingleCarrierTx(struct adapter *padapter, u8 bStart); +void Hal_SetContinuousTx(struct adapter *padapter, u8 bStart); void Hal_SetBandwidth(struct adapter *padapter); void Hal_SetDataRate(struct adapter *padapter); @@ -494,8 +494,8 @@ void Hal_TriggerRFThermalMeter(struct adapter *padapter); u8 Hal_ReadRFThermalMeter(struct adapter *padapter); void Hal_SetCCKContinuousTx(struct adapter *padapter, u8 bStart); void Hal_SetOFDMContinuousTx(struct adapter *padapter, u8 bStart); -void Hal_ProSetCrystalCap (struct adapter *padapter , u32 CrystalCapVal); -void MP_PHY_SetRFPathSwitch(struct adapter *padapter , bool bMain); +void Hal_ProSetCrystalCap(struct adapter *padapter, u32 CrystalCapVal); +void MP_PHY_SetRFPathSwitch(struct adapter *padapter, bool bMain); u32 mpt_ProQueryCalTxPower(struct adapter *padapter, u8 RfPath); void MPT_PwrCtlDM(struct adapter *padapter, u32 bstart); u8 MptToMgntRate(u32 MptRateIdx); diff --git a/drivers/staging/rtl8723bs/include/rtw_recv.h b/drivers/staging/rtl8723bs/include/rtw_recv.h index 012d8f54814f..98c3e92245b7 100644 --- a/drivers/staging/rtl8723bs/include/rtw_recv.h +++ b/drivers/staging/rtl8723bs/include/rtw_recv.h @@ -187,7 +187,7 @@ struct rx_pkt_attrib { /* These definition is used for Rx packet reordering. */ -#define SN_LESS(a, b) (((a-b)&0x800)!= 0) +#define SN_LESS(a, b) (((a - b) & 0x800) != 0) #define SN_EQUAL(a, b) (a == b) /* define REORDER_WIN_SIZE 128 */ /* define REORDER_ENTRY_NUM 128 */ @@ -369,12 +369,12 @@ struct recv_frame_hdr }; -union recv_frame{ +union recv_frame { union{ struct list_head list; struct recv_frame_hdr hdr; uint mem[RECVFRAME_HDR_ALIGN>>2]; - }u; + } u; /* uint mem[MAX_RXSZ>>2]; */ @@ -388,8 +388,8 @@ enum RX_PACKET_TYPE { C2H_PACKET }; -extern union recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ -extern union recv_frame *rtw_alloc_recvframe (struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ +extern union recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ +extern union recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue); /* get a free recv_frame from pfree_recv_queue */ extern int rtw_free_recvframe(union recv_frame *precvframe, struct __queue *pfree_recv_queue); #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue) @@ -401,7 +401,7 @@ u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter); sint rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, struct __queue *queue); sint rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue); -struct recv_buf *rtw_dequeue_recvbuf (struct __queue *queue); +struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue); void rtw_reordering_ctrl_timeout_handler(struct timer_list *t); @@ -444,7 +444,7 @@ static inline u8 *recvframe_pull(union recv_frame *precvframe, sint sz) return NULL; } - precvframe->u.hdr.len -=sz; + precvframe->u.hdr.len -= sz; return precvframe->u.hdr.rx_data; @@ -471,7 +471,7 @@ static inline u8 *recvframe_put(union recv_frame *precvframe, sint sz) return NULL; } - precvframe->u.hdr.len +=sz; + precvframe->u.hdr.len += sz; return precvframe->u.hdr.rx_tail; @@ -497,7 +497,7 @@ static inline u8 *recvframe_pull_tail(union recv_frame *precvframe, sint sz) return NULL; } - precvframe->u.hdr.len -=sz; + precvframe->u.hdr.len -= sz; return precvframe->u.hdr.rx_tail; diff --git a/drivers/staging/rtl8723bs/include/rtw_security.h b/drivers/staging/rtl8723bs/include/rtw_security.h index bea184452edd..aa60b6f867dd 100644 --- a/drivers/staging/rtl8723bs/include/rtw_security.h +++ b/drivers/staging/rtl8723bs/include/rtw_security.h @@ -208,7 +208,7 @@ struct sha256_state { }; #define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst)\ -do{\ +do {\ switch (psecuritypriv->dot11AuthAlgrthm)\ {\ case dot11AuthAlgrthm_Open:\ @@ -220,18 +220,18 @@ do{\ if (bmcst)\ encry_algo = (u8)psecuritypriv->dot118021XGrpPrivacy;\ else\ - encry_algo =(u8) psta->dot118021XPrivacy;\ + encry_algo = (u8)psta->dot118021XPrivacy;\ break;\ case dot11AuthAlgrthm_WAPI:\ encry_algo = (u8)psecuritypriv->dot11PrivacyAlgrthm;\ break;\ - }\ -}while (0) + } \ +} while (0) #define _AES_IV_LEN_ 8 #define SET_ICE_IV_LEN(iv_len, icv_len, encrypt)\ -do{\ +do {\ switch (encrypt)\ {\ case _WEP40_:\ @@ -255,19 +255,19 @@ do{\ iv_len = 0;\ icv_len = 0;\ break;\ - }\ -}while (0) + } \ +} while (0) #define GET_TKIP_PN(iv, dot11txpn)\ -do{\ - dot11txpn._byte_.TSC0 =iv[2];\ - dot11txpn._byte_.TSC1 =iv[0];\ - dot11txpn._byte_.TSC2 =iv[4];\ - dot11txpn._byte_.TSC3 =iv[5];\ - dot11txpn._byte_.TSC4 =iv[6];\ - dot11txpn._byte_.TSC5 =iv[7];\ -}while (0) +do {\ + dot11txpn._byte_.TSC0 = iv[2];\ + dot11txpn._byte_.TSC1 = iv[0];\ + dot11txpn._byte_.TSC2 = iv[4];\ + dot11txpn._byte_.TSC3 = iv[5];\ + dot11txpn._byte_.TSC4 = iv[6];\ + dot11txpn._byte_.TSC5 = iv[7];\ +} while (0) #define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1))) diff --git a/drivers/staging/rtl8723bs/include/rtw_xmit.h b/drivers/staging/rtl8723bs/include/rtw_xmit.h index ea1396005a13..cd2be0056aa1 100644 --- a/drivers/staging/rtl8723bs/include/rtw_xmit.h +++ b/drivers/staging/rtl8723bs/include/rtw_xmit.h @@ -40,17 +40,17 @@ #define HW_QUEUE_ENTRY 8 #define WEP_IV(pattrib_iv, dot11txpn, keyidx)\ -do{\ +do {\ pattrib_iv[0] = dot11txpn._byte_.TSC0;\ pattrib_iv[1] = dot11txpn._byte_.TSC1;\ pattrib_iv[2] = dot11txpn._byte_.TSC2;\ pattrib_iv[3] = ((keyidx & 0x3)<<6);\ - dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0: (dot11txpn.val+1);\ -}while (0) + dot11txpn.val = (dot11txpn.val == 0xffffff) ? 0 : (dot11txpn.val + 1);\ +} while (0) #define TKIP_IV(pattrib_iv, dot11txpn, keyidx)\ -do{\ +do {\ pattrib_iv[0] = dot11txpn._byte_.TSC1;\ pattrib_iv[1] = (dot11txpn._byte_.TSC1 | 0x20) & 0x7f;\ pattrib_iv[2] = dot11txpn._byte_.TSC0;\ @@ -59,11 +59,11 @@ do{\ pattrib_iv[5] = dot11txpn._byte_.TSC3;\ pattrib_iv[6] = dot11txpn._byte_.TSC4;\ pattrib_iv[7] = dot11txpn._byte_.TSC5;\ - dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\ -}while (0) + dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val + 1);\ +} while (0) #define AES_IV(pattrib_iv, dot11txpn, keyidx)\ -do{\ +do {\ pattrib_iv[0] = dot11txpn._byte_.TSC0;\ pattrib_iv[1] = dot11txpn._byte_.TSC1;\ pattrib_iv[2] = 0;\ @@ -72,8 +72,8 @@ do{\ pattrib_iv[5] = dot11txpn._byte_.TSC3;\ pattrib_iv[6] = dot11txpn._byte_.TSC4;\ pattrib_iv[7] = dot11txpn._byte_.TSC5;\ - dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0: (dot11txpn.val+1);\ -}while (0) + dot11txpn.val = dot11txpn.val == 0xffffffffffffULL ? 0 : (dot11txpn.val + 1);\ +} while (0) #define HWXMIT_ENTRY 4 @@ -217,7 +217,7 @@ enum { XMITBUF_CMD = 2, }; -struct submit_ctx{ +struct submit_ctx { unsigned long submit_time; /* */ u32 timeout_ms; /* <0: not synchronous, 0: wait forever, >0: up to ms waiting */ int status; /* status for operation */ @@ -274,7 +274,7 @@ struct xmit_buf u8 pg_num; u8 agg_num; -#if defined(DBG_XMIT_BUF)|| defined(DBG_XMIT_BUF_EXT) +#if defined(DBG_XMIT_BUF) || defined(DBG_XMIT_BUF_EXT) u8 no; #endif @@ -350,7 +350,7 @@ struct hw_txqueue { sint ac_tag; }; -struct agg_pkt_info{ +struct agg_pkt_info { u16 offset; u16 pkt_len; }; @@ -484,7 +484,7 @@ void rtw_init_hwxmits(struct hw_xmit *phwxmit, sint entry); s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter); -void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv); +void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv); s32 rtw_alloc_hwxmits(struct adapter *padapter); diff --git a/drivers/staging/rtl8723bs/include/sta_info.h b/drivers/staging/rtl8723bs/include/sta_info.h index 3acce5630f8e..c9aa3b5097a7 100644 --- a/drivers/staging/rtl8723bs/include/sta_info.h +++ b/drivers/staging/rtl8723bs/include/sta_info.h @@ -31,13 +31,13 @@ struct wlan_acl_pool { struct __queue acl_node_q; }; -typedef struct _RSSI_STA{ +typedef struct _RSSI_STA { s32 UndecoratedSmoothedPWDB; s32 UndecoratedSmoothedCCK; s32 UndecoratedSmoothedOFDM; u64 PacketMap; u8 ValidBit; -}RSSI_STA, *PRSSI_STA; +} RSSI_STA, *PRSSI_STA; struct stainfo_stats { @@ -304,7 +304,7 @@ struct sta_info { #define STA_RX_PKTS_DIFF_ARG(sta) \ sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \ , sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \ - , sta->sta_stats.rx_data_pkts -sta->sta_stats.last_rx_data_pkts + , sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)" @@ -374,7 +374,7 @@ int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta); struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset); extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); -extern u32 rtw_free_stainfo(struct adapter *padapter , struct sta_info *psta); +extern u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta); extern void rtw_free_all_stainfo(struct adapter *padapter); extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); extern u32 rtw_init_bcmc_stainfo(struct adapter *padapter); diff --git a/drivers/staging/rtl8723bs/include/wifi.h b/drivers/staging/rtl8723bs/include/wifi.h index 2faf83704ff0..88a6e982ce01 100644 --- a/drivers/staging/rtl8723bs/include/wifi.h +++ b/drivers/staging/rtl8723bs/include/wifi.h @@ -707,7 +707,7 @@ struct HT_caps_element unsigned char ASEL_caps; } HT_cap_element; unsigned char HT_cap[26]; - }u; + } u; } __attribute__ ((packed)); struct HT_info_element @@ -1102,7 +1102,7 @@ enum P2P_PROTO_WK_ID P2P_PRE_TX_PROVDISC_PROCESS_WK = 2, P2P_PRE_TX_NEGOREQ_PROCESS_WK = 3, P2P_PRE_TX_INVITEREQ_PROCESS_WK = 4, - P2P_AP_P2P_CH_SWITCH_PROCESS_WK =5, + P2P_AP_P2P_CH_SWITCH_PROCESS_WK = 5, P2P_RO_CH_WK = 6, }; @@ -1126,8 +1126,8 @@ enum P2P_PROTO_WK_ID #define WFD_DEVINFO_PC_TDLS 0x0080 #define WFD_DEVINFO_HDCP_SUPPORT 0x0100 -#define IP_MCAST_MAC(mac) ((mac[0]== 0x01) && (mac[1]== 0x00) && (mac[2]== 0x5e)) -#define ICMPV6_MCAST_MAC(mac) ((mac[0]== 0x33) && (mac[1]== 0x33) && (mac[2]!= 0xff)) +#define IP_MCAST_MAC(mac) ((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x5e)) +#define ICMPV6_MCAST_MAC(mac) ((mac[0] == 0x33) && (mac[1] == 0x33) && (mac[2] != 0xff)) /* Regulatroy Domain */ struct regd_pair_mapping { diff --git a/drivers/staging/rtl8723bs/include/xmit_osdep.h b/drivers/staging/rtl8723bs/include/xmit_osdep.h index a61412b54ec0..e9ff274f7474 100644 --- a/drivers/staging/rtl8723bs/include/xmit_osdep.h +++ b/drivers/staging/rtl8723bs/include/xmit_osdep.h @@ -35,8 +35,8 @@ void rtw_os_xmit_resource_free(struct adapter *padapter, struct xmit_buf *pxmitb extern uint rtw_remainder_len(struct pkt_file *pfile); extern void _rtw_open_pktfile(_pkt *pkt, struct pkt_file *pfile); -extern uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen); -extern sint rtw_endofpktfile (struct pkt_file *pfile); +extern uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen); +extern sint rtw_endofpktfile(struct pkt_file *pfile); extern void rtw_os_pkt_complete(struct adapter *padapter, _pkt *pkt); extern void rtw_os_xmit_complete(struct adapter *padapter, struct xmit_frame *pxframe); diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c index 322cabb97b99..1ba85a43f05a 100644 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c @@ -254,7 +254,7 @@ struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wl /* DBG_8192C("%s\n", __func__); */ - bssinf_len = pnetwork->network.IELength+sizeof (struct ieee80211_hdr_3addr); + bssinf_len = pnetwork->network.IELength + sizeof(struct ieee80211_hdr_3addr); if (bssinf_len > MAX_BSSINFO_LEN) { DBG_871X("%s IE Length too long > %d byte\n", __func__, MAX_BSSINFO_LEN); goto exit; @@ -263,7 +263,7 @@ struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wl { u16 wapi_len = 0; - if (rtw_get_wapi_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &wapi_len)>0) + if (rtw_get_wapi_ie(pnetwork->network.IEs, pnetwork->network.IELength, NULL, &wapi_len) > 0) { if (wapi_len > 0) { @@ -286,7 +286,7 @@ struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wl wpsie = rtw_get_wps_ie(pnetwork->network.IEs+_FIXED_IE_LENGTH_, pnetwork->network.IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen); - if (wpsie && wpsielen>0) + if (wpsie && wpsielen > 0) psr = rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL); if (sr != 0) @@ -353,7 +353,7 @@ struct cfg80211_bss *rtw_cfg80211_inform_bss(struct adapter *padapter, struct wl pbuf += sizeof(struct ieee80211_hdr_3addr); - len = sizeof (struct ieee80211_hdr_3addr); + len = sizeof(struct ieee80211_hdr_3addr); memcpy(pbuf, pnetwork->network.IEs, pnetwork->network.IELength); len += pnetwork->network.IELength; @@ -402,7 +402,7 @@ int rtw_cfg80211_check_bss(struct adapter *padapter) cfg80211_put_bss(padapter->rtw_wdev->wiphy, bss); - return (bss!= NULL); + return (bss != NULL); } void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter) @@ -424,7 +424,7 @@ void rtw_cfg80211_ibss_indicate_connect(struct adapter *padapter) struct wlan_bssid_ex *pnetwork = &(padapter->mlmeextpriv.mlmext_info.network); struct wlan_network *scanned = pmlmepriv->cur_network_scanned; - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ==true) + if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) { memcpy(&cur_network->network, pnetwork, sizeof(struct wlan_bssid_ex)); @@ -579,7 +579,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa struct sta_info *psta = NULL, *pbcmc_sta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv* psecuritypriv =&(padapter->securitypriv); + struct security_priv* psecuritypriv = &(padapter->securitypriv); struct sta_priv *pstapriv = &padapter->stapriv; DBG_8192C("%s\n", __func__); @@ -633,7 +633,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa DBG_8192C("r871x_set_encryption, wep_key_idx =%d, len =%d\n", wep_key_idx, wep_key_len); - if ((wep_key_idx >= WEP_KEYS) || (wep_key_len<= 0)) + if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) { ret = -EINVAL; goto exit; @@ -673,7 +673,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa } - if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) /* group key */ + if (!psta && check_fwstate(pmlmepriv, WIFI_AP_STATE)) /* group key */ { if (param->u.crypt.set_tx == 0) /* group key */ { @@ -681,7 +681,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { DBG_8192C("%s, set group_key, WEP\n", __func__); - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_; if (param->u.crypt.key_len == 13) @@ -696,7 +696,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ @@ -712,7 +712,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa psecuritypriv->dot118021XGrpPrivacy = _AES_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); } else { @@ -729,7 +729,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta) { pbcmc_sta->ieee8021x_blocked = false; @@ -748,7 +748,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { if (param->u.crypt.set_tx == 1) /* pairwise key */ { - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); if (strcmp(param->u.crypt.alg, "WEP") == 0) { @@ -799,7 +799,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { if (strcmp(param->u.crypt.alg, "WEP") == 0) { - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_; if (param->u.crypt.key_len == 13) @@ -811,7 +811,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ @@ -825,7 +825,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa { psecuritypriv->dot118021XGrpPrivacy = _AES_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); } else { @@ -840,7 +840,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, struct ieee_pa rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta) { pbcmc_sta->ieee8021x_blocked = false; @@ -940,7 +940,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) /* 802_1x */ { - struct sta_info * psta,*pbcmc_sta; + struct sta_info * psta, *pbcmc_sta; struct sta_priv * pstapriv = &padapter->stapriv; /* DBG_8192C("%s, : dot11AuthAlgrthm == dot11AuthAlgrthm_8021X\n", __func__); */ @@ -959,7 +959,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param psta->ieee8021x_blocked = false; - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| + if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; @@ -970,7 +970,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param DBG_8192C("%s, : param->u.crypt.set_tx == 1\n", __func__); - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); if (strcmp(param->u.crypt.alg, "TKIP") == 0)/* set mic key */ { @@ -978,7 +978,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); - padapter->securitypriv.busetkipkey =false; + padapter->securitypriv.busetkipkey = false; /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */ } @@ -991,21 +991,21 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param { if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) { - memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); - memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]), 8); - memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]), 8); + memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); + memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); + memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); padapter->securitypriv.binstallGrpkey = true; /* DEBUG_ERR((" param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ DBG_871X(" ~~~~set sta key:groupkey\n"); padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; - rtw_set_key(padapter,&padapter->securitypriv, param->u.crypt.idx, 1, true); + rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, true); } else if (strcmp(param->u.crypt.alg, "BIP") == 0) { /* DBG_871X("BIP key_len =%d , index =%d @@@@@@@@@@@@@@@@@@\n", param->u.crypt.key_len, param->u.crypt.idx); */ /* save the IGTK key, length 16 bytes */ - memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /*DBG_871X("IGTK key below:\n"); for (no = 0;no<16;no++) printk(" %02x ", padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey[no]); @@ -1017,7 +1017,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param } } - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta == NULL) { /* DEBUG_ERR(("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */ @@ -1028,7 +1028,7 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, struct ieee_param if (strcmp(param->u.crypt.alg, "none") != 0) pbcmc_sta->ieee8021x_blocked = false; - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| + if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; @@ -1270,8 +1270,8 @@ static int cfg80211_rtw_get_station(struct wiphy *wiphy, /* for Ad-Hoc/AP mode */ if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) - ||check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) - ||check_fwstate(pmlmepriv, WIFI_AP_STATE)) + || check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) + || check_fwstate(pmlmepriv, WIFI_AP_STATE)) && check_fwstate(pmlmepriv, _FW_LINKED) ) { @@ -1346,7 +1346,7 @@ static int cfg80211_rtw_change_iface(struct wiphy *wiphy, rtw_wdev->iftype = type; - if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==false) + if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == false) { rtw_wdev->iftype = old_type; ret = -EPERM; @@ -1464,7 +1464,7 @@ static int rtw_cfg80211_set_probe_req_wpsp2pie(struct adapter *padapter, char *b DBG_8192C("%s, ielen =%d\n", __func__, len); #endif - if (len>0) + if (len > 0) { if ((wps_ie = rtw_get_wps_ie(buf, len, NULL, &wps_ielen))) { @@ -1503,8 +1503,8 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy int ret = 0; struct ndis_802_11_ssid *ssid = NULL; struct rtw_ieee80211_channel ch[RTW_CHANNEL_SCAN_AMOUNT]; - u8 survey_times =3; - u8 survey_times_for_one_ch =6; + u8 survey_times = 3; + u8 survey_times_for_one_ch = 6; struct cfg80211_ssid *ssids = request->ssids; int j = 0; bool need_indicate_scan_done = false; @@ -1556,7 +1556,7 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy goto check_need_indicate_scan_done; } - if (request->ie && request->ie_len>0) + if (request->ie && request->ie_len > 0) { rtw_cfg80211_set_probe_req_wpsp2pie(padapter, (u8 *)request->ie, request->ie_len); } @@ -1610,7 +1610,7 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy /* parsing channels, n_channels */ memset(ch, 0, sizeof(struct rtw_ieee80211_channel)*RTW_CHANNEL_SCAN_AMOUNT); - for (i = 0;i<request->n_channels && i<RTW_CHANNEL_SCAN_AMOUNT;i++) { + for (i = 0; i < request->n_channels && i < RTW_CHANNEL_SCAN_AMOUNT; i++) { #ifdef DEBUG_CFG80211 DBG_871X(FUNC_ADPT_FMT CHAN_FMT"\n", FUNC_ADPT_ARG(padapter), CHAN_ARG(request->channels[i])); #endif @@ -1620,12 +1620,12 @@ static int cfg80211_rtw_scan(struct wiphy *wiphy spin_lock_bh(&pmlmepriv->lock); if (request->n_channels == 1) { - for (i = 1;i<survey_times_for_one_ch;i++) + for (i = 1; i < survey_times_for_one_ch; i++) memcpy(&ch[i], &ch[0], sizeof(struct rtw_ieee80211_channel)); _status = rtw_sitesurvey_cmd(padapter, ssid, RTW_SSID_SCAN_AMOUNT, ch, survey_times_for_one_ch); } else if (request->n_channels <= 4) { - for (j =request->n_channels-1;j>= 0;j--) - for (i = 0;i<survey_times;i++) + for (j = request->n_channels - 1; j >= 0; j--) + for (i = 0; i < survey_times; i++) { memcpy(&ch[j*survey_times+i], &ch[j], sizeof(struct rtw_ieee80211_channel)); } @@ -1699,7 +1699,7 @@ static int rtw_cfg80211_set_auth_type(struct security_priv *psecuritypriv, psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; - if (psecuritypriv->ndisauthtype>Ndis802_11AuthModeWPA) + if (psecuritypriv->ndisauthtype > Ndis802_11AuthModeWPA) psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; break; @@ -1767,7 +1767,7 @@ static int rtw_cfg80211_set_cipher(struct security_priv *psecuritypriv, u32 ciph psecuritypriv->ndisencryptstatus = ndisencryptstatus; /* if (psecuritypriv->dot11PrivacyAlgrthm >= _AES_) */ - /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */ + /* psecuritypriv->ndisauthtype = Ndis802_11AuthModeWPA2PSK; */ } return 0; @@ -1799,7 +1799,7 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel int wpa_ielen = 0; int wpa2_ielen = 0; u8 *pwpa, *pwpa2; - u8 null_addr[]= {0, 0, 0, 0, 0, 0}; + u8 null_addr[] = {0, 0, 0, 0, 0, 0}; if (pie == NULL || !ielen) { /* Treat this as normal case, but need to clear WIFI_UNDER_WPS */ @@ -1818,13 +1818,13 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel goto exit; } - memcpy(buf, pie , ielen); + memcpy(buf, pie, ielen); /* dump */ { int i; DBG_8192C("set wpa_ie(length:%zu):\n", ielen); - for (i = 0;i<ielen;i =i+8) + for (i = 0; i < ielen; i = i + 8) DBG_8192C("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]); } @@ -1835,12 +1835,12 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel } pwpa = rtw_get_wpa_ie(buf, &wpa_ielen, ielen); - if (pwpa && wpa_ielen>0) + if (pwpa && wpa_ielen > 0) { if (rtw_parse_wpa_ie(pwpa, wpa_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; - padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPAPSK; + padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; memcpy(padapter->securitypriv.supplicant_ie, &pwpa[0], wpa_ielen+2); DBG_8192C("got wpa_ie, wpa_ielen:%u\n", wpa_ielen); @@ -1848,12 +1848,12 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel } pwpa2 = rtw_get_wpa2_ie(buf, &wpa2_ielen, ielen); - if (pwpa2 && wpa2_ielen>0) + if (pwpa2 && wpa2_ielen > 0) { if (rtw_parse_wpa2_ie(pwpa2, wpa2_ielen+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; - padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPA2PSK; + padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; memcpy(padapter->securitypriv.supplicant_ie, &pwpa2[0], wpa2_ielen+2); DBG_8192C("got wpa2_ie, wpa2_ielen:%u\n", wpa2_ielen); @@ -1873,7 +1873,7 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel { case WPA_CIPHER_NONE: padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; + padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; break; case WPA_CIPHER_WEP40: padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; @@ -1897,7 +1897,7 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel { case WPA_CIPHER_NONE: padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; + padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; break; case WPA_CIPHER_WEP40: padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; @@ -1924,7 +1924,7 @@ static int rtw_cfg80211_set_wpa_ie(struct adapter *padapter, u8 *pie, size_t iel wps_ie = rtw_get_wps_ie(buf, ielen, NULL, &wps_ielen); if (wps_ie && wps_ielen > 0) { DBG_8192C("got wps_ie, wps_ielen:%u\n", wps_ielen); - padapter->securitypriv.wps_ie_len = wps_ielen<MAX_WPS_IE_LEN?wps_ielen:MAX_WPS_IE_LEN; + padapter->securitypriv.wps_ie_len = wps_ielen < MAX_WPS_IE_LEN ? wps_ielen : MAX_WPS_IE_LEN; memcpy(padapter->securitypriv.wps_ie, wps_ie, padapter->securitypriv.wps_ie_len); set_fwstate(&padapter->mlmepriv, WIFI_UNDER_WPS); } else { @@ -2027,7 +2027,7 @@ static int cfg80211_rtw_leave_ibss(struct wiphy *wiphy, struct net_device *ndev) rtw_wdev->iftype = NL80211_IFTYPE_STATION; - if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) ==false) + if (rtw_set_802_11_infrastructure_mode(padapter, Ndis802_11Infrastructure) == false) { rtw_wdev->iftype = old_type; ret = -EPERM; @@ -2185,7 +2185,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev, if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL) { - ret = -EOPNOTSUPP ; + ret = -EOPNOTSUPP; } kfree(pwep); @@ -2301,7 +2301,7 @@ static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, u8 index, blInserted = false; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(ndev); struct security_priv *psecuritypriv = &padapter->securitypriv; - u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 }; + u8 strZeroMacAddress[ETH_ALEN] = { 0x00 }; DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); @@ -2313,7 +2313,7 @@ static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, blInserted = false; /* overwrite PMKID */ - for (index = 0 ; index<NUM_PMKID_CACHE; index++) + for (index = 0 ; index < NUM_PMKID_CACHE; index++) { if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) { /* BSSID is matched, the same AP => rewrite with new PMKID. */ @@ -2337,7 +2337,7 @@ static int cfg80211_rtw_set_pmksa(struct wiphy *wiphy, memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, (u8 *)pmksa->pmkid, WLAN_PMKID_LEN); psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; - psecuritypriv->PMKIDIndex++ ; + psecuritypriv->PMKIDIndex++; if (psecuritypriv->PMKIDIndex == 16) { psecuritypriv->PMKIDIndex = 0; @@ -2357,7 +2357,7 @@ static int cfg80211_rtw_del_pmksa(struct wiphy *wiphy, DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); - for (index = 0 ; index<NUM_PMKID_CACHE; index++) + for (index = 0 ; index < NUM_PMKID_CACHE; index++) { if (!memcmp(psecuritypriv->PMKIDList[index].Bssid, (u8 *)pmksa->bssid, ETH_ALEN)) { /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */ @@ -2387,7 +2387,7 @@ static int cfg80211_rtw_flush_pmksa(struct wiphy *wiphy, DBG_871X(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev)); - memset(&psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); + memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); psecuritypriv->PMKIDIndex = 0; return 0; @@ -2575,7 +2575,7 @@ static const struct net_device_ops rtw_cfg80211_monitor_if_ops = { .ndo_start_xmit = rtw_cfg80211_monitor_if_xmit_entry, }; -static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, struct net_device **ndev) +static int rtw_cfg80211_add_monitor_if(struct adapter *padapter, char *name, struct net_device **ndev) { int ret = 0; struct net_device* mon_ndev = NULL; @@ -2734,7 +2734,7 @@ static int rtw_add_beacon(struct adapter *adapter, const u8 *head, size_t head_l if (check_fwstate(pmlmepriv, WIFI_AP_STATE) != true) return -EINVAL; - if (head_len<24) + if (head_len < 24) return -EINVAL; pbuf = rtw_zmalloc(head_len+tail_len); @@ -3276,7 +3276,7 @@ static void rtw_cfg80211_init_ht_capab(struct ieee80211_sta_ht_cap *ht_cap, enum ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); } - else if ((rf_type == RF_1T2R) || (rf_type ==RF_2T2R)) + else if ((rf_type == RF_1T2R) || (rf_type == RF_2T2R)) { ht_cap->mcs.rx_mask[0] = 0xFF; ht_cap->mcs.rx_mask[1] = 0xFF; diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c index 9b9038e7deb1..5059b874080e 100644 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c @@ -59,7 +59,7 @@ void rtw_indicate_wx_assoc_event(struct adapter *padapter) wrqu.ap_addr.sa_family = ARPHRD_ETHER; - if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ==true) + if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) memcpy(wrqu.ap_addr.sa_data, pnetwork->MacAddress, ETH_ALEN); else memcpy(wrqu.ap_addr.sa_data, pmlmepriv->cur_network.network.MacAddress, ETH_ALEN); @@ -86,11 +86,11 @@ static char *translate_scan(struct adapter *padapter, u32 ht_ielen = 0; char *custom = NULL; char *p; - u16 max_rate = 0, rate, ht_cap =false, vht_cap = false; + u16 max_rate = 0, rate, ht_cap = false, vht_cap = false; u32 i = 0; u8 bw_40MHz = 0, short_GI = 0; u16 mcs_rate = 0, vht_data_rate = 0; - u8 ie_offset = (pnetwork->network.Reserved[0] == 2? 0:12); + u8 ie_offset = (pnetwork->network.Reserved[0] == 2 ? 0 : 12); struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); u8 ss, sq; @@ -113,11 +113,11 @@ static char *translate_scan(struct adapter *padapter, } else { p = rtw_get_ie(&pnetwork->network.IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pnetwork->network.IELength-12); } - if (p && ht_ielen>0) { + if (p && ht_ielen > 0) { struct rtw_ieee80211_ht_cap *pht_capie; ht_cap = true; pht_capie = (struct rtw_ieee80211_ht_cap *)(p+2); - memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2); + memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2); bw_40MHz = (le16_to_cpu(pht_capie->cap_info) & IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0; short_GI = (le16_to_cpu(pht_capie->cap_info) & (IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; } @@ -163,7 +163,7 @@ static char *translate_scan(struct adapter *padapter, cap = le16_to_cpu(le_tmp); } - if (cap & (WLAN_CAPABILITY_IBSS |WLAN_CAPABILITY_BSS)) { + if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) { if (cap & WLAN_CAPABILITY_BSS) iwe.u.mode = IW_MODE_MASTER; else @@ -172,7 +172,7 @@ static char *translate_scan(struct adapter *padapter, start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); } - if (pnetwork->network.Configuration.DSConfig<1 /*|| pnetwork->network.Configuration.DSConfig>14*/) + if (pnetwork->network.Configuration.DSConfig < 1 /*|| pnetwork->network.Configuration.DSConfig > 14*/) pnetwork->network.Configuration.DSConfig = 1; /* Add frequency/channel */ @@ -197,12 +197,12 @@ static char *translate_scan(struct adapter *padapter, if (!custom) return start; p = custom; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); - while (pnetwork->network.SupportedRates[i]!= 0) { + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), " Rates (Mb/s): "); + while (pnetwork->network.SupportedRates[i] != 0) { rate = pnetwork->network.SupportedRates[i]&0x7F; if (rate > max_rate) max_rate = rate; - p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), + p += scnprintf(p, MAX_CUSTOM_LEN - (p - custom), "%d%s ", rate >> 1, (rate & 1) ? ".5" : ""); i++; } @@ -239,7 +239,7 @@ static char *translate_scan(struct adapter *padapter, if (!buf) return start; if (wpa_len > 0) { - p =buf; + p = buf; p += sprintf(p, "wpa_ie ="); for (i = 0; i < wpa_len; i++) p += sprintf(p, "%02x", wpa_ie[i]); @@ -258,7 +258,7 @@ static char *translate_scan(struct adapter *padapter, start = iwe_stream_add_point(info, start, stop, &iwe, buf); memset(&iwe, 0, sizeof(iwe)); - iwe.cmd =IWEVGENIE; + iwe.cmd = IWEVGENIE; iwe.u.data.length = wpa_len; start = iwe_stream_add_point(info, start, stop, &iwe, wpa_ie); } @@ -274,7 +274,7 @@ static char *translate_scan(struct adapter *padapter, start = iwe_stream_add_point(info, start, stop, &iwe, buf); memset(&iwe, 0, sizeof(iwe)); - iwe.cmd =IWEVGENIE; + iwe.cmd = IWEVGENIE; iwe.u.data.length = rsn_len; start = iwe_stream_add_point(info, start, stop, &iwe, rsn_ie); } @@ -298,13 +298,13 @@ static char *translate_scan(struct adapter *padapter, } while (cnt < total_ielen) { - if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen>2)) { + if (rtw_is_wps_ie(&ie_ptr[cnt], &wps_ielen) && (wps_ielen > 2)) { wpsie_ptr = &ie_ptr[cnt]; - iwe.cmd =IWEVGENIE; + iwe.cmd = IWEVGENIE; iwe.u.data.length = (u16)wps_ielen; start = iwe_stream_add_point(info, start, stop, &iwe, wpsie_ptr); } - cnt+=ie_ptr[cnt+1]+2; /* goto next */ + cnt += ie_ptr[cnt + 1] + 2; /* goto next */ } } @@ -352,8 +352,8 @@ static char *translate_scan(struct adapter *padapter, #if defined(CONFIG_SIGNAL_DISPLAY_DBM) && defined(CONFIG_BACKGROUND_NOISE_MONITOR) { s16 tmp_noise = 0; - rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR,&(pnetwork->network.Configuration.DSConfig), &(tmp_noise)); - iwe.u.qual.noise = tmp_noise ; + rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &(pnetwork->network.Configuration.DSConfig), &(tmp_noise)); + iwe.u.qual.noise = tmp_noise; } #else iwe.u.qual.noise = 0; /* noise level */ @@ -500,7 +500,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, DBG_871X("wep, set_tx = 1\n"); if (rtw_set_802_11_add_wep(padapter, pwep) == (u8)_FAIL) - ret = -EOPNOTSUPP ; + ret = -EOPNOTSUPP; } else { DBG_871X("wep, set_tx = 0\n"); @@ -508,12 +508,12 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, /* psecuritypriv->dot11PrivacyKeyIndex =keyid", but can rtw_set_key to fw/cam */ if (wep_key_idx >= WEP_KEYS) { - ret = -EOPNOTSUPP ; + ret = -EOPNOTSUPP; goto exit; } memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); - psecuritypriv->dot11DefKeylen[wep_key_idx]=pwep->KeyLength; + psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; rtw_set_key(padapter, psecuritypriv, wep_key_idx, 0, true); } @@ -533,20 +533,20 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, if (strcmp(param->u.crypt.alg, "none") != 0) psta->ieee8021x_blocked = false; - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| + if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; } if (param->u.crypt.set_tx == 1) { /* pairwise key */ - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */ /* DEBUG_ERR(("\nset key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8); memcpy(psta->dot11tkiprxmickey.skey, &(param->u.crypt.key[24]), 8); - padapter->securitypriv.busetkipkey =false; + padapter->securitypriv.busetkipkey = false; /* _set_timer(&padapter->securitypriv.tkip_timer, 50); */ } @@ -556,11 +556,11 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, rtw_setstakey_cmd(padapter, psta, true, true); } else { /* group key */ if (strcmp(param->u.crypt.alg, "TKIP") == 0 || strcmp(param->u.crypt.alg, "CCMP") == 0) { - memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /* only TKIP group key need to install this */ if (param->u.crypt.key_len > 16) { - memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[16]), 8); - memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey,&(param->u.crypt.key[24]), 8); + memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8); + memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8); } padapter->securitypriv.binstallGrpkey = true; /* DEBUG_ERR((" param->u.crypt.key_len =%d\n", param->u.crypt.key_len)); */ @@ -568,11 +568,11 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, padapter->securitypriv.dot118021XGrpKeyid = param->u.crypt.idx; - rtw_set_key(padapter,&padapter->securitypriv, param->u.crypt.idx, 1, true); + rtw_set_key(padapter, &padapter->securitypriv, param->u.crypt.idx, 1, true); } else if (strcmp(param->u.crypt.alg, "BIP") == 0) { /* printk("BIP key_len =%d , index =%d @@@@@@@@@@@@@@@@@@\n", param->u.crypt.key_len, param->u.crypt.idx); */ /* save the IGTK key, length 16 bytes */ - memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /*printk("IGTK key below:\n"); for (no = 0;no<16;no++) printk(" %02x ", padapter->securitypriv.dot11wBIPKey[param->u.crypt.idx].skey[no]); @@ -584,7 +584,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, } } - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta == NULL) { /* DEBUG_ERR(("Set OID_802_11_ADD_KEY: bcmc stainfo is null\n")); */ } else { @@ -592,7 +592,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, if (strcmp(param->u.crypt.alg, "none") != 0) pbcmc_sta->ieee8021x_blocked = false; - if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled)|| + if ((padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption2Enabled) || (padapter->securitypriv.ndisencryptstatus == Ndis802_11Encryption3Enabled)) { pbcmc_sta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm; } @@ -613,7 +613,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie u8 *buf = NULL; int group_cipher = 0, pairwise_cipher = 0; int ret = 0; - u8 null_addr[]= {0, 0, 0, 0, 0, 0}; + u8 null_addr[] = {0, 0, 0, 0, 0, 0}; if ((ielen > MAX_WPA_IE_LEN) || (pie == NULL)) { _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); @@ -630,13 +630,13 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie goto exit; } - memcpy(buf, pie , ielen); + memcpy(buf, pie, ielen); /* dump */ { int i; DBG_871X("\n wpa_ie(length:%d):\n", ielen); - for (i = 0;i<ielen;i =i+8) + for (i = 0; i < ielen; i = i + 8) DBG_871X("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]); } @@ -648,13 +648,13 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie if (rtw_parse_wpa_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; - padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPAPSK; + padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen); } if (rtw_parse_wpa2_ie(buf, ielen, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) { padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_8021X; - padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeWPA2PSK; + padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPA2PSK; memcpy(padapter->securitypriv.supplicant_ie, &buf[0], ielen); } @@ -666,7 +666,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie switch (group_cipher) { case WPA_CIPHER_NONE: padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; + padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; break; case WPA_CIPHER_WEP40: padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; @@ -689,7 +689,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie switch (pairwise_cipher) { case WPA_CIPHER_NONE: padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; - padapter->securitypriv.ndisencryptstatus =Ndis802_11EncryptionDisabled; + padapter->securitypriv.ndisencryptstatus = Ndis802_11EncryptionDisabled; break; case WPA_CIPHER_WEP40: padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; @@ -712,7 +712,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie _clr_fwstate_(&padapter->mlmepriv, WIFI_UNDER_WPS); {/* set wps_ie */ u16 cnt = 0; - u8 eid, wps_oui[4]={0x0, 0x50, 0xf2, 0x04}; + u8 eid, wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; while (cnt < ielen) { eid = buf[cnt]; @@ -762,7 +762,7 @@ static int rtw_wx_get_name(struct net_device *dev, struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); u32 ht_ielen = 0; char *p; - u8 ht_cap =false, vht_cap =false; + u8 ht_cap = false, vht_cap = false; struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; NDIS_802_11_RATES_EX* prates = NULL; @@ -772,7 +772,7 @@ static int rtw_wx_get_name(struct net_device *dev, if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true) { /* parsing HT_CAP_IE */ p = rtw_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_, &ht_ielen, pcur_bss->IELength-12); - if (p && ht_ielen>0) + if (p && ht_ielen > 0) ht_cap = true; prates = &pcur_bss->SupportedRates; @@ -846,7 +846,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a, union iwreq_data *wrqu, char *b) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType ; + enum NDIS_802_11_NETWORK_INFRASTRUCTURE networkType; int ret = 0; if (_FAIL == rtw_pwr_wakeup(padapter)) { @@ -878,7 +878,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a, DBG_871X("set_mode = IW_MODE_INFRA\n"); break; - default : + default: ret = -EINVAL; RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_err_, ("\n Mode: %s is not supported \n", iw_operation_mode[wrqu->mode])); goto exit; @@ -895,7 +895,7 @@ static int rtw_wx_set_mode(struct net_device *dev, struct iw_request_info *a, } */ - if (rtw_set_802_11_infrastructure_mode(padapter, networkType) ==false) { + if (rtw_set_802_11_infrastructure_mode(padapter, networkType) == false) { ret = -EPERM; goto exit; @@ -939,8 +939,8 @@ static int rtw_wx_set_pmkid(struct net_device *dev, int intReturn = false; struct security_priv *psecuritypriv = &padapter->securitypriv; struct iw_pmksa* pPMK = (struct iw_pmksa *)extra; - u8 strZeroMacAddress[ ETH_ALEN ] = { 0x00 }; - u8 strIssueBssid[ ETH_ALEN ] = { 0x00 }; + u8 strZeroMacAddress[ETH_ALEN] = { 0x00 }; + u8 strIssueBssid[ETH_ALEN] = { 0x00 }; /* There are the BSSID information in the bssid.sa_data array. @@ -960,13 +960,13 @@ static int rtw_wx_set_pmkid(struct net_device *dev, blInserted = false; /* overwrite PMKID */ - for (j = 0 ; j<NUM_PMKID_CACHE; j++) { + for (j = 0; j < NUM_PMKID_CACHE; j++) { if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) { /* BSSID is matched, the same AP => rewrite with new PMKID. */ DBG_871X("[rtw_wx_set_pmkid] BSSID exists in the PMKList.\n"); memcpy(psecuritypriv->PMKIDList[j].PMKID, pPMK->pmkid, IW_PMKID_LEN); - psecuritypriv->PMKIDList[ j ].bUsed = true; + psecuritypriv->PMKIDList[j].bUsed = true; psecuritypriv->PMKIDIndex = j+1; blInserted = true; break; @@ -981,25 +981,25 @@ static int rtw_wx_set_pmkid(struct net_device *dev, memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN); memcpy(psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].PMKID, pPMK->pmkid, IW_PMKID_LEN); - psecuritypriv->PMKIDList[ psecuritypriv->PMKIDIndex ].bUsed = true; - psecuritypriv->PMKIDIndex++ ; + psecuritypriv->PMKIDList[psecuritypriv->PMKIDIndex].bUsed = true; + psecuritypriv->PMKIDIndex++; if (psecuritypriv->PMKIDIndex == 16) psecuritypriv->PMKIDIndex = 0; } } else if (pPMK->cmd == IW_PMKSA_REMOVE) { DBG_871X("[rtw_wx_set_pmkid] IW_PMKSA_REMOVE!\n"); intReturn = true; - for (j = 0 ; j<NUM_PMKID_CACHE; j++) { + for (j = 0; j < NUM_PMKID_CACHE; j++) { if (!memcmp(psecuritypriv->PMKIDList[j].Bssid, strIssueBssid, ETH_ALEN)) { /* BSSID is matched, the same AP => Remove this PMKID information and reset it. */ eth_zero_addr(psecuritypriv->PMKIDList[j].Bssid); - psecuritypriv->PMKIDList[ j ].bUsed = false; + psecuritypriv->PMKIDList[j].bUsed = false; break; } } } else if (pPMK->cmd == IW_PMKSA_FLUSH) { DBG_871X("[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!\n"); - memset(&psecuritypriv->PMKIDList[ 0 ], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); + memset(&psecuritypriv->PMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); psecuritypriv->PMKIDIndex = 0; intReturn = true; } @@ -1093,7 +1093,7 @@ static int rtw_wx_get_range(struct net_device *dev, /* Commented by Albert 2009/10/13 */ /* The following code will proivde the security capability to network manager. */ /* If the driver doesn't provide this capability to network manager, */ -/* the WPA/WPA2 routers can't be choosen in the network manager. */ +/* the WPA/WPA2 routers can't be chosen in the network manager. */ /* #define IW_SCAN_CAPA_NONE 0x00 @@ -1106,11 +1106,11 @@ static int rtw_wx_get_range(struct net_device *dev, #define IW_SCAN_CAPA_TIME 0x40 */ - range->enc_capa = IW_ENC_CAPA_WPA|IW_ENC_CAPA_WPA2| - IW_ENC_CAPA_CIPHER_TKIP|IW_ENC_CAPA_CIPHER_CCMP; + range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | + IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; - range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE |IW_SCAN_CAPA_BSSID| - IW_SCAN_CAPA_CHANNEL|IW_SCAN_CAPA_MODE|IW_SCAN_CAPA_RATE; + range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE | IW_SCAN_CAPA_BSSID | + IW_SCAN_CAPA_CHANNEL | IW_SCAN_CAPA_MODE | IW_SCAN_CAPA_RATE; return 0; } @@ -1287,7 +1287,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, goto exit; } - if (!padapter->hw_init_completed ) { + if (!padapter->hw_init_completed) { ret = -1; goto exit; } @@ -1330,7 +1330,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, } else if (wrqu->data.length >= WEXT_CSCAN_HEADER_SIZE && !memcmp(extra, WEXT_CSCAN_HEADER, WEXT_CSCAN_HEADER_SIZE)) { - int len = wrqu->data.length -WEXT_CSCAN_HEADER_SIZE; + int len = wrqu->data.length - WEXT_CSCAN_HEADER_SIZE; char *pos = extra+WEXT_CSCAN_HEADER_SIZE; char section; char sec_len; @@ -1339,7 +1339,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, /* DBG_871X("%s COMBO_SCAN header is recognized\n", __func__); */ while (len >= 1) { - section = *(pos++); len-= 1; + section = *(pos++); len -= 1; switch (section) { case WEXT_CSCAN_SSID_SECTION: @@ -1349,9 +1349,9 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, break; } - sec_len = *(pos++); len-= 1; + sec_len = *(pos++); len -= 1; - if (sec_len>0 && sec_len<=len) { + if (sec_len > 0 && sec_len <= len) { ssid[ssid_index].SsidLength = sec_len; memcpy(ssid[ssid_index].Ssid, pos, ssid[ssid_index].SsidLength); /* DBG_871X("%s COMBO_SCAN with specific ssid:%s, %d\n", __func__ */ @@ -1359,29 +1359,29 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, ssid_index++; } - pos+=sec_len; len-=sec_len; + pos += sec_len; len -= sec_len; break; case WEXT_CSCAN_CHANNEL_SECTION: /* DBG_871X("WEXT_CSCAN_CHANNEL_SECTION\n"); */ - pos+= 1; len-= 1; + pos += 1; len -= 1; break; case WEXT_CSCAN_ACTV_DWELL_SECTION: /* DBG_871X("WEXT_CSCAN_ACTV_DWELL_SECTION\n"); */ - pos+=2; len-=2; + pos += 2; len -= 2; break; case WEXT_CSCAN_PASV_DWELL_SECTION: /* DBG_871X("WEXT_CSCAN_PASV_DWELL_SECTION\n"); */ - pos+=2; len-=2; + pos += 2; len -= 2; break; case WEXT_CSCAN_HOME_DWELL_SECTION: /* DBG_871X("WEXT_CSCAN_HOME_DWELL_SECTION\n"); */ - pos+=2; len-=2; + pos += 2; len -= 2; break; case WEXT_CSCAN_TYPE_SECTION: /* DBG_871X("WEXT_CSCAN_TYPE_SECTION\n"); */ - pos+= 1; len-= 1; + pos += 1; len -= 1; break; default: /* DBG_871X("Unknown CSCAN section %c\n", section); */ @@ -1391,7 +1391,7 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a, } - /* jeff: it has still some scan paramater to parse, we only do this now... */ + /* jeff: it has still some scan parameter to parse, we only do this now... */ _status = rtw_set_802_11_bssid_list_scan(padapter, ssid, RTW_SSID_SCAN_AMOUNT); } else { @@ -1463,7 +1463,7 @@ static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a, && rtw_mlme_band_check(padapter, pnetwork->network.Configuration.DSConfig) == true && true == rtw_validate_ssid(&(pnetwork->network.Ssid))) { - ev =translate_scan(padapter, a, pnetwork, ev, stop); + ev = translate_scan(padapter, a, pnetwork, ev, stop); } plist = get_next(plist); @@ -1481,7 +1481,7 @@ exit: DBG_871X("DBG_IOCTL %s:%d return %d\n", __func__, __LINE__, ret); #endif - return ret ; + return ret; } @@ -1570,7 +1570,7 @@ static int rtw_wx_set_essid(struct net_device *dev, pnetwork->network.Ssid.Ssid)); if ((!memcmp(dst_ssid, src_ssid, ndis_ssid.SsidLength)) && - (pnetwork->network.Ssid.SsidLength ==ndis_ssid.SsidLength)) { + (pnetwork->network.Ssid.SsidLength == ndis_ssid.SsidLength)) { RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("rtw_wx_set_essid: find match, set infra mode\n")); @@ -1651,7 +1651,7 @@ static int rtw_wx_set_rate(struct net_device *dev, u32 target_rate = wrqu->bitrate.value; u32 fixed = wrqu->bitrate.fixed; u32 ratevalue = 0; - u8 mpdatarate[NumRates]={11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; + u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, (" rtw_wx_set_rate\n")); RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("target_rate = %d, fixed = %d\n", target_rate, fixed)); @@ -1706,8 +1706,8 @@ static int rtw_wx_set_rate(struct net_device *dev, set_rate: - for (i = 0; i<NumRates; i++) { - if (ratevalue ==mpdatarate[i]) { + for (i = 0; i < NumRates; i++) { + if (ratevalue == mpdatarate[i]) { datarates[i] = mpdatarate[i]; if (fixed == 0) break; @@ -1855,7 +1855,7 @@ static int rtw_wx_set_enc(struct net_device *dev, padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ authmode = Ndis802_11AuthModeOpen; - padapter->securitypriv.ndisauthtype =authmode; + padapter->securitypriv.ndisauthtype = authmode; goto exit; } @@ -1881,7 +1881,7 @@ static int rtw_wx_set_enc(struct net_device *dev, padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; authmode = Ndis802_11AuthModeOpen; - padapter->securitypriv.ndisauthtype =authmode; + padapter->securitypriv.ndisauthtype = authmode; } else if (erq->flags & IW_ENCODE_RESTRICTED) { DBG_871X("rtw_wx_set_enc():IW_ENCODE_RESTRICTED\n"); padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption1Enabled; @@ -1891,7 +1891,7 @@ static int rtw_wx_set_enc(struct net_device *dev, padapter->securitypriv.dot11PrivacyAlgrthm = _WEP40_; padapter->securitypriv.dot118021XGrpPrivacy = _WEP40_; authmode = Ndis802_11AuthModeShared; - padapter->securitypriv.ndisauthtype =authmode; + padapter->securitypriv.ndisauthtype = authmode; } else { DBG_871X("rtw_wx_set_enc():erq->flags = 0x%x\n", erq->flags); @@ -1900,7 +1900,7 @@ static int rtw_wx_set_enc(struct net_device *dev, padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; authmode = Ndis802_11AuthModeOpen; - padapter->securitypriv.ndisauthtype =authmode; + padapter->securitypriv.ndisauthtype = authmode; } wep.KeyIndex = key; @@ -1909,7 +1909,7 @@ static int rtw_wx_set_enc(struct net_device *dev, wep.Length = wep.KeyLength + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial); } else { - wep.KeyLength = 0 ; + wep.KeyLength = 0; if (keyindex_provided == 1) { /* set key_id only, no given KeyMaterial(erq->length == 0). */ padapter->securitypriv.dot11PrivacyKeyIndex = key; @@ -2093,7 +2093,7 @@ static int rtw_wx_set_auth(struct net_device *dev, padapter->securitypriv.dot11PrivacyAlgrthm = _NO_PRIVACY_; padapter->securitypriv.dot118021XGrpPrivacy = _NO_PRIVACY_; padapter->securitypriv.dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */ - padapter->securitypriv.ndisauthtype =Ndis802_11AuthModeOpen; + padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen; } break; @@ -2181,7 +2181,7 @@ static int rtw_wx_set_enc_ext(struct net_device *dev, param->u.crypt.set_tx = 0; } - param->u.crypt.idx = (pencoding->flags&0x00FF) -1 ; + param->u.crypt.idx = (pencoding->flags & 0x00FF) - 1; if (pext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) memcpy(param->u.crypt.seq, pext->rx_seq, 8); @@ -2459,7 +2459,7 @@ static int rtw_get_ap_info(struct net_device *dev, /* pdata->length = 0;? */ pdata->flags = 0; - if (pdata->length>=32) { + if (pdata->length >= 32) { if (copy_from_user(data, pdata->pointer, 32)) { ret = -EINVAL; goto exit; @@ -2492,13 +2492,13 @@ static int rtw_get_ap_info(struct net_device *dev, DBG_871X("BSSID:" MAC_FMT "\n", MAC_ARG(bssid)); pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength-12); - if (pbuf && (wpa_ielen>0)) { + if (pbuf && (wpa_ielen > 0)) { pdata->flags = 1; break; } pbuf = rtw_get_wpa2_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength-12); - if (pbuf && (wpa_ielen>0)) { + if (pbuf && (wpa_ielen > 0)) { pdata->flags = 2; break; } @@ -2510,7 +2510,7 @@ static int rtw_get_ap_info(struct net_device *dev, spin_unlock_bh(&(pmlmepriv->scanned_queue.lock)); - if (pdata->length>=34) { + if (pdata->length >= 34) { if (copy_to_user((u8 __force __user *)pdata->pointer+32, (u8 *)&pdata->flags, 1)) { ret = -EINVAL; goto exit; @@ -2541,7 +2541,7 @@ static int rtw_set_pid(struct net_device *dev, selector = *pdata; if (selector < 3 && selector >= 0) { padapter->pid[selector] = *(pdata+1); - DBG_871X("%s set pid[%d]=%d\n", __func__, selector , padapter->pid[selector]); + DBG_871X("%s set pid[%d]=%d\n", __func__, selector, padapter->pid[selector]); } else DBG_871X("%s selector %d error\n", __func__, selector); @@ -2563,7 +2563,7 @@ static int rtw_wps_start(struct net_device *dev, u32 u32wps_start = 0; unsigned int uintRet = 0; - if ((true == padapter->bDriverStopped) ||(true ==padapter->bSurpriseRemoved) || (NULL == pdata)) { + if ((true == padapter->bDriverStopped) || (true == padapter->bSurpriseRemoved) || (NULL == pdata)) { ret = -EINVAL; goto exit; } @@ -2733,8 +2733,8 @@ static int rtw_dbg_port(struct net_device *dev, break; case 0x01: /* dbg mode */ padapter->recvpriv.is_signal_dbg = 1; - extra_arg = extra_arg>100?100:extra_arg; - padapter->recvpriv.signal_strength_dbg =extra_arg; + extra_arg = extra_arg > 100 ? 100 : extra_arg; + padapter->recvpriv.signal_strength_dbg = extra_arg; break; } break; @@ -2806,7 +2806,7 @@ static int rtw_dbg_port(struct net_device *dev, DBG_871X("ampdu_enable = %d\n", psta->htpriv.ampdu_enable); DBG_871X("agg_enable_bitmap =%x, candidate_tid_bitmap =%x\n", psta->htpriv.agg_enable_bitmap, psta->htpriv.candidate_tid_bitmap); - for (i = 0;i<16;i++) { + for (i = 0; i < 16; i++) { preorder_ctrl = &psta->recvreorder_ctrl[i]; if (preorder_ctrl->enable) DBG_871X("tid =%d, indicate_seq =%d\n", i, preorder_ctrl->indicate_seq); @@ -2845,7 +2845,7 @@ static int rtw_dbg_port(struct net_device *dev, spin_lock_bh(&pstapriv->sta_hash_lock); - for (i = 0; i< NUM_STA; i++) { + for (i = 0; i < NUM_STA; i++) { phead = &(pstapriv->sta_hash[i]); plist = get_next(phead); @@ -2872,7 +2872,7 @@ static int rtw_dbg_port(struct net_device *dev, - for (j = 0;j<16;j++) { + for (j = 0; j < 16; j++) { preorder_ctrl = &psta->recvreorder_ctrl[j]; if (preorder_ctrl->enable) DBG_871X("tid =%d, indicate_seq =%d\n", j, preorder_ctrl->indicate_seq); @@ -2900,7 +2900,7 @@ static int rtw_dbg_port(struct net_device *dev, DBG_871X("enable driver ctrl vcs = %d\n", extra_arg); padapter->driver_vcs_en = 1; - if (extra_arg>2) + if (extra_arg > 2) padapter->driver_vcs_type = 1; else padapter->driver_vcs_type = extra_arg; @@ -3048,7 +3048,7 @@ static int rtw_dbg_port(struct net_device *dev, if (max_rx_rate < 0xc) { /* max_rx_rate < MSC0 -> B or G -> disable HT */ pregistrypriv->ht_enable = 0; - for (i = 0; i<NumRates; i++) { + for (i = 0; i < NumRates; i++) { if (pmlmeext->datarate[i] > max_rx_rate) pmlmeext->datarate[i] = 0xff; } @@ -3057,7 +3057,7 @@ static int rtw_dbg_port(struct net_device *dev, else if (max_rx_rate < 0x1c) { /* mcs0~mcs15 */ u32 mcs_bitmap = 0x0; - for (i = 0; i<((max_rx_rate+1)-0xc); i++) + for (i = 0; i < ((max_rx_rate + 1) - 0xc); i++) mcs_bitmap |= BIT(i); set_mcs_rate_by_mask(pmlmeext->default_supported_mcs_set, mcs_bitmap); @@ -3129,9 +3129,9 @@ static int rtw_dbg_port(struct net_device *dev, */ int value; - DBG_871X("Set GPIO Direction! arg = %d , extra_arg =%d\n", arg , extra_arg); + DBG_871X("Set GPIO Direction! arg = %d , extra_arg =%d\n", arg, extra_arg); value = rtw_config_gpio(dev, arg, extra_arg); - DBG_871X("Set GPIO Direction %s\n", (value ==-1)?"Fail!!!":"Success"); + DBG_871X("Set GPIO Direction %s\n", (value == -1) ? "Fail!!!" : "Success"); break; } case 0x27: /* Set GPIO output direction value */ @@ -3142,15 +3142,15 @@ static int rtw_dbg_port(struct net_device *dev, */ int value; - DBG_871X("Set GPIO Value! arg = %d , extra_arg =%d\n", arg , extra_arg); + DBG_871X("Set GPIO Value! arg = %d , extra_arg =%d\n", arg, extra_arg); value = rtw_set_gpio_output_value(dev, arg, extra_arg); - DBG_871X("Set GPIO Value %s\n", (value ==-1)?"Fail!!!":"Success"); + DBG_871X("Set GPIO Value %s\n", (value == -1) ? "Fail!!!" : "Success"); break; } #endif case 0xaa: { - if ((extra_arg & 0x7F)> 0x3F) extra_arg = 0xFF; + if ((extra_arg & 0x7F) > 0x3F) extra_arg = 0xFF; DBG_871X("chang data rate to :0x%02x\n", extra_arg); padapter->fix_rate = extra_arg; } @@ -3161,7 +3161,7 @@ static int rtw_dbg_port(struct net_device *dev, mac_reg_dump(RTW_DBGDUMP, padapter); else if (extra_arg == 1) bb_reg_dump(RTW_DBGDUMP, padapter); - else if (extra_arg ==2) + else if (extra_arg == 2) rf_reg_dump(RTW_DBGDUMP, padapter); } break; @@ -3170,8 +3170,8 @@ static int rtw_dbg_port(struct net_device *dev, { u32 odm_flag; - if (0xf ==extra_arg) { - rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC,&odm_flag); + if (0xf == extra_arg) { + rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &odm_flag); DBG_871X(" === DMFlag(0x%08x) ===\n", odm_flag); DBG_871X("extra_arg = 0 - disable all dynamic func\n"); DBG_871X("extra_arg = 1 - disable DIG- BIT(0)\n"); @@ -3187,7 +3187,7 @@ static int rtw_dbg_port(struct net_device *dev, extra_arg = 3 - turn on all dynamic func */ rtw_hal_set_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &(extra_arg)); - rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC,&odm_flag); + rtw_hal_get_def_var(padapter, HAL_DEF_DBG_DM_FUNC, &odm_flag); DBG_871X(" === DMFlag(0x%08x) ===\n", odm_flag); } } @@ -3257,7 +3257,7 @@ static int wpa_set_param(struct net_device *dev, u8 name, u32 value) /* ret = ieee80211_wpa_enable(ieee, value); */ switch ((value)&0xff) { - case 1 : /* WPA */ + case 1: /* WPA */ padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeWPAPSK; /* WPA_PSK */ padapter->securitypriv.ndisencryptstatus = Ndis802_11Encryption2Enabled; break; @@ -3428,7 +3428,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, struct sta_info *psta = NULL, *pbcmc_sta = NULL; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv* psecuritypriv =&(padapter->securitypriv); + struct security_priv* psecuritypriv = &(padapter->securitypriv); struct sta_priv *pstapriv = &padapter->stapriv; DBG_871X("%s\n", __func__); @@ -3481,7 +3481,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, DBG_871X("r871x_set_encryption, wep_key_idx =%d, len =%d\n", wep_key_idx, wep_key_len); - if ((wep_key_idx >= WEP_KEYS) || (wep_key_len<= 0)) { + if ((wep_key_idx >= WEP_KEYS) || (wep_key_len <= 0)) { ret = -EINVAL; goto exit; } @@ -3523,7 +3523,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, memcpy(&(psecuritypriv->dot11DefKey[wep_key_idx].skey[0]), pwep->KeyMaterial, pwep->KeyLength); - psecuritypriv->dot11DefKeylen[wep_key_idx]=pwep->KeyLength; + psecuritypriv->dot11DefKeylen[wep_key_idx] = pwep->KeyLength; rtw_ap_set_wep_key(padapter, pwep->KeyMaterial, pwep->KeyLength, wep_key_idx, 1); } else { @@ -3549,7 +3549,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, if (strcmp(param->u.crypt.alg, "WEP") == 0) { DBG_871X("%s, set group_key, WEP\n", __func__); - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_; if (param->u.crypt.key_len == 13) @@ -3560,7 +3560,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ @@ -3575,7 +3575,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, psecuritypriv->dot118021XGrpPrivacy = _AES_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); } else { DBG_871X("%s, set group_key, none\n", __func__); @@ -3590,7 +3590,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta) { pbcmc_sta->ieee8021x_blocked = false; pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ @@ -3604,7 +3604,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /* psk/802_1x */ if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { if (param->u.crypt.set_tx == 1) { - memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psta->dot118021x_UncstKey.skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); if (strcmp(param->u.crypt.alg, "WEP") == 0) { DBG_871X("%s, set pairwise key, WEP\n", __func__); @@ -3641,7 +3641,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, } else { /* group key??? */ if (strcmp(param->u.crypt.alg, "WEP") == 0) { - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); psecuritypriv->dot118021XGrpPrivacy = _WEP40_; if (param->u.crypt.key_len == 13) @@ -3649,7 +3649,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { psecuritypriv->dot118021XGrpPrivacy = _TKIP_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); /* DEBUG_ERR("set key length :param->u.crypt.key_len =%d\n", param->u.crypt.key_len); */ /* set mic key */ @@ -3661,7 +3661,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { psecuritypriv->dot118021XGrpPrivacy = _AES_; - memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len>16 ?16:param->u.crypt.key_len)); + memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey, param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len)); } else { psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_; } @@ -3674,7 +3674,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, rtw_ap_set_group_key(padapter, param->u.crypt.key, psecuritypriv->dot118021XGrpPrivacy, param->u.crypt.idx); - pbcmc_sta =rtw_get_bcmc_stainfo(padapter); + pbcmc_sta = rtw_get_bcmc_stainfo(padapter); if (pbcmc_sta) { pbcmc_sta->ieee8021x_blocked = false; pbcmc_sta->dot118021XPrivacy = psecuritypriv->dot118021XGrpPrivacy;/* rx will use bmc_sta's dot118021XPrivacy */ @@ -3706,7 +3706,7 @@ static int rtw_set_beacon(struct net_device *dev, struct ieee_param *param, int memcpy(&pstapriv->max_num_sta, param->u.bcn_ie.reserved, 2); - if ((pstapriv->max_num_sta>NUM_STA) || (pstapriv->max_num_sta<= 0)) + if ((pstapriv->max_num_sta > NUM_STA) || (pstapriv->max_num_sta <= 0)) pstapriv->max_num_sta = NUM_STA; @@ -3831,12 +3831,12 @@ static int rtw_del_sta(struct net_device *dev, struct ieee_param *param) psta = rtw_get_stainfo(pstapriv, param->sta_addr); if (psta) { - u8 updated =false; + u8 updated = false; /* DBG_871X("free psta =%p, aid =%d\n", psta, psta->aid); */ spin_lock_bh(&pstapriv->asoc_list_lock); - if (list_empty(&psta->asoc_list) ==false) { + if (list_empty(&psta->asoc_list) == false) { list_del_init(&psta->asoc_list); pstapriv->asoc_list_cnt--; updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING); @@ -3895,12 +3895,12 @@ static int rtw_ioctl_get_sta_data(struct net_device *dev, struct ieee_param *par ht_20mhz_set : BIT(5) */ - psta_data->sta_set =((psta->nonerp_set) | - (psta->no_short_slot_time_set <<1) | - (psta->no_short_preamble_set <<2) | - (psta->no_ht_gf_set <<3) | - (psta->no_ht_set <<4) | - (psta->ht_20mhz_set <<5)); + psta_data->sta_set = ((psta->nonerp_set) | + (psta->no_short_slot_time_set << 1) | + (psta->no_short_preamble_set << 2) | + (psta->no_ht_gf_set << 3) | + (psta->no_ht_set << 4) | + (psta->ht_20mhz_set << 5)); psta_data->tx_supp_rates_len = psta->bssratelen; memcpy(psta_data->tx_supp_rates, psta->bssrateset, psta->bssratelen); @@ -3969,7 +3969,7 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param) static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, int len) { int ret = 0; - unsigned char wps_oui[4]={0x0, 0x50, 0xf2, 0x04}; + unsigned char wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); @@ -3986,7 +3986,7 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param, kfree(pmlmepriv->wps_beacon_ie); pmlmepriv->wps_beacon_ie = NULL; - if (ie_len>0) { + if (ie_len > 0) { pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len); pmlmepriv->wps_beacon_ie_len = ie_len; if (pmlmepriv->wps_beacon_ie == NULL) { @@ -4024,7 +4024,7 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par kfree(pmlmepriv->wps_probe_resp_ie); pmlmepriv->wps_probe_resp_ie = NULL; - if (ie_len>0) { + if (ie_len > 0) { pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len); pmlmepriv->wps_probe_resp_ie_len = ie_len; if (pmlmepriv->wps_probe_resp_ie == NULL) { @@ -4057,7 +4057,7 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par kfree(pmlmepriv->wps_assoc_resp_ie); pmlmepriv->wps_assoc_resp_ie = NULL; - if (ie_len>0) { + if (ie_len > 0) { pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len); pmlmepriv->wps_assoc_resp_ie_len = ie_len; if (pmlmepriv->wps_assoc_resp_ie == NULL) { @@ -4357,11 +4357,11 @@ static int rtw_wx_set_priv(struct net_device *dev, struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); u8 *probereq_wpsie = ext; int probereq_wpsie_len = len; - u8 wps_oui[4]={0x0, 0x50, 0xf2, 0x04}; + u8 wps_oui[4] = {0x0, 0x50, 0xf2, 0x04}; if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) && (!memcmp(&probereq_wpsie[2], wps_oui, 4))) { - cp_sz = probereq_wpsie_len>MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN:probereq_wpsie_len; + cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len; if (pmlmepriv->wps_probe_req_ie) { pmlmepriv->wps_probe_req_ie_len = 0; @@ -4498,7 +4498,7 @@ static int rtw_test( ret = rtw_hal_fill_h2c_cmd(padapter, param[0], count-1, ¶m[1]); pos = sprintf(extra, "H2C ID = 0x%02x content =", param[0]); - for (i = 1; i<count; i++) + for (i = 1; i < count; i++) pos += sprintf(extra+pos, "%02x,", param[i]); extra[pos] = 0; pos--; @@ -4636,14 +4636,14 @@ static const struct iw_priv_args rtw_private_args[] = { }, { SIOCIWFIRSTPRIV + 0x11, - IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK , "p2p_get" + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "p2p_get" }, { SIOCIWFIRSTPRIV + 0x12, 0, 0, "NULL" }, { SIOCIWFIRSTPRIV + 0x13, - IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64 , "p2p_get2" + IW_PRIV_TYPE_CHAR | 64, IW_PRIV_TYPE_CHAR | 64, "p2p_get2" }, { SIOCIWFIRSTPRIV + 0x14, @@ -4651,14 +4651,14 @@ static const struct iw_priv_args rtw_private_args[] = { }, { SIOCIWFIRSTPRIV + 0x15, - IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024 , "tdls_get" + IW_PRIV_TYPE_CHAR | 1024, IW_PRIV_TYPE_CHAR | 1024, "tdls_get" }, { SIOCIWFIRSTPRIV + 0x16, IW_PRIV_TYPE_CHAR | 64, 0, "pm_set" }, - {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ , 0 , "rereg_nd_name"}, + {SIOCIWFIRSTPRIV + 0x18, IW_PRIV_TYPE_CHAR | IFNAMSIZ, 0, "rereg_nd_name"}, {SIOCIWFIRSTPRIV + 0x1A, IW_PRIV_TYPE_CHAR | 1024, 0, "efuse_set"}, {SIOCIWFIRSTPRIV + 0x1B, IW_PRIV_TYPE_CHAR | 128, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_MASK, "efuse_get"}, { @@ -4667,10 +4667,10 @@ static const struct iw_priv_args rtw_private_args[] = { }, #ifdef CONFIG_WOWLAN - { MP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "wow_mode" }, /* set */ + { MP_WOW_ENABLE, IW_PRIV_TYPE_CHAR | 1024, 0, "wow_mode" }, /* set */ #endif #ifdef CONFIG_AP_WOWLAN - { MP_AP_WOW_ENABLE , IW_PRIV_TYPE_CHAR | 1024, 0, "ap_wow_mode" }, /* set */ + { MP_AP_WOW_ENABLE, IW_PRIV_TYPE_CHAR | 1024, 0, "ap_wow_mode" }, /* set */ #endif }; @@ -4721,7 +4721,7 @@ static iw_handler rtw_private_handler[] = { static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev) { struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); - struct iw_statistics *piwstats =&padapter->iwstats; + struct iw_statistics *piwstats = &padapter->iwstats; int tmp_level = 0; int tmp_qual = 0; int tmp_noise = 0; @@ -4760,10 +4760,10 @@ static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev) rtw_ps_deny(padapter, PS_DENY_IOCTL); LeaveAllPowerSaveModeDirect(padapter); - rtw_hal_set_odm_var(padapter, HAL_ODM_NOISE_MONITOR,&info, false); + rtw_hal_set_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &info, false); /* ODM_InbandNoise_Monitor(podmpriv, true, 0x20, 100); */ rtw_ps_deny_cancel(padapter, PS_DENY_IOCTL); - rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR,&(info.chan), &(padapter->recvpriv.noise)); + rtw_hal_get_odm_var(padapter, HAL_ODM_NOISE_MONITOR, &(info.chan), &(padapter->recvpriv.noise)); DBG_871X("chan:%d, noise_level:%d\n", info.chan, padapter->recvpriv.noise); } #endif diff --git a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c index 52a5b3156b28..f121dbfaa029 100644 --- a/drivers/staging/rtl8723bs/os_dep/mlme_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/mlme_linux.c @@ -64,7 +64,7 @@ void rtw_os_indicate_scan_done(struct adapter *padapter, bool aborted) indicate_wx_scan_complete_event(padapter); } -static RT_PMKID_LIST backupPMKIDList[ NUM_PMKID_CACHE ]; +static RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE]; void rtw_reset_securitypriv(struct adapter *adapter) { u8 backupPMKIDIndex = 0; @@ -83,7 +83,7 @@ void rtw_reset_securitypriv(struct adapter *adapter) /* Backup the btkip_countermeasure information. */ /* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */ - memcpy(&backupPMKIDList[ 0 ], &adapter->securitypriv.PMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); + memcpy(&backupPMKIDList[0], &adapter->securitypriv.PMKIDList[0], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); backupPMKIDIndex = adapter->securitypriv.PMKIDIndex; backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure; backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time; @@ -95,7 +95,7 @@ void rtw_reset_securitypriv(struct adapter *adapter) /* Added by Albert 2009/02/18 */ /* Restore the PMK information to securitypriv structure for the following connection. */ - memcpy(&adapter->securitypriv.PMKIDList[ 0 ], &backupPMKIDList[ 0 ], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); + memcpy(&adapter->securitypriv.PMKIDList[0], &backupPMKIDList[0], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE); adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure; adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time; diff --git a/drivers/staging/rtl8723bs/os_dep/os_intfs.c b/drivers/staging/rtl8723bs/os_dep/os_intfs.c index 47e984d5b7cb..d29f59bbb613 100644 --- a/drivers/staging/rtl8723bs/os_dep/os_intfs.c +++ b/drivers/staging/rtl8723bs/os_dep/os_intfs.c @@ -202,8 +202,8 @@ module_param(rtw_tx_pwr_by_rate, int, 0644); MODULE_PARM_DESC(rtw_tx_pwr_by_rate, "0:Disable, 1:Enable, 2: Depend on efuse"); int _netdev_open(struct net_device *pnetdev); -int netdev_open (struct net_device *pnetdev); -static int netdev_close (struct net_device *pnetdev); +int netdev_open(struct net_device *pnetdev); +static int netdev_close(struct net_device *pnetdev); static void loadparam(struct adapter *padapter, _nic_hdl pnetdev) { @@ -221,7 +221,7 @@ static void loadparam(struct adapter *padapter, _nic_hdl pnetdev) registry_par->channel = (u8)rtw_channel; registry_par->wireless_mode = (u8)rtw_wireless_mode; - registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ; + registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense; registry_par->vcs_type = (u8)rtw_vcs_type; registry_par->rts_thresh = (u16)rtw_rts_thresh; registry_par->frag_thresh = (u16)rtw_frag_thresh; @@ -554,7 +554,7 @@ u32 rtw_start_drv_threads(struct adapter *padapter) return _status; } -void rtw_stop_drv_threads (struct adapter *padapter) +void rtw_stop_drv_threads(struct adapter *padapter) { RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n")); @@ -1154,7 +1154,7 @@ void rtw_dev_unload(struct adapter *padapter) DBG_871X("stop cmdthd timeout\n"); break; } else { - cnt ++; + cnt++; DBG_871X("cmdthd is running(%d)\n", cnt); msleep(10); } @@ -1274,7 +1274,7 @@ void rtw_suspend_wow(struct adapter *padapter) padapter->intf_stop(padapter); } - /* 2.1 clean interupt */ + /* 2.1 clean interrupt */ if (padapter->HalFunc.clear_interrupt) padapter->HalFunc.clear_interrupt(padapter); @@ -1348,7 +1348,7 @@ void rtw_suspend_ap_wow(struct adapter *padapter) /* 2. disable interrupt */ rtw_hal_disable_interrupt(padapter); /* It need wait for leaving 32K. */ - /* 2.1 clean interupt */ + /* 2.1 clean interrupt */ if (padapter->HalFunc.clear_interrupt) padapter->HalFunc.clear_interrupt(padapter); @@ -1799,7 +1799,7 @@ int rtw_resume_common(struct adapter *padapter) pwrpriv->pno_in_resume = false; #endif } - DBG_871X_LEVEL(_drv_always_, "%s:%d in %d ms\n", __func__ , ret, + DBG_871X_LEVEL(_drv_always_, "%s:%d in %d ms\n", __func__, ret, jiffies_to_msecs(jiffies - start_time)); return ret; diff --git a/drivers/staging/rtl8723bs/os_dep/osdep_service.c b/drivers/staging/rtl8723bs/os_dep/osdep_service.c index f5614e56371e..4238209ec175 100644 --- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c +++ b/drivers/staging/rtl8723bs/os_dep/osdep_service.c @@ -289,7 +289,7 @@ void *rtw_cbuf_pop(struct rtw_cbuf *cbuf) } /** - * rtw_cbuf_alloc - allocte a rtw_cbuf with given size and do initialization + * rtw_cbuf_alloc - allocate a rtw_cbuf with given size and do initialization * @size: size of pointer * * Returns: pointer of srtuct rtw_cbuf, NULL for allocation failure diff --git a/drivers/staging/rtl8723bs/os_dep/recv_linux.c b/drivers/staging/rtl8723bs/os_dep/recv_linux.c index 643caccc3069..60c35d92ba29 100644 --- a/drivers/staging/rtl8723bs/os_dep/recv_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/recv_linux.c @@ -35,7 +35,8 @@ void rtw_os_recv_resource_free(struct recv_priv *precvpriv) for (i = 0; i < NR_RECVFRAME; i++) { if (precvframe->u.hdr.pkt) { - dev_kfree_skb_any(precvframe->u.hdr.pkt);/* free skb by driver */ + /* free skb by driver */ + dev_kfree_skb_any(precvframe->u.hdr.pkt); precvframe->u.hdr.pkt = NULL; } precvframe++; @@ -80,7 +81,10 @@ _pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, u16 nSubframe_Length, u8 ((!memcmp(sub_skb->data, rtw_rfc1042_header, SNAP_SIZE) && eth_type != ETH_P_AARP && eth_type != ETH_P_IPX) || !memcmp(sub_skb->data, rtw_bridge_tunnel_header, SNAP_SIZE))) { - /* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */ + /* + * remove RFC1042 or Bridge-Tunnel encapsulation and replace + * EtherType + */ skb_pull(sub_skb, SNAP_SIZE); memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->src, ETH_ALEN); memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, ETH_ALEN); @@ -101,7 +105,7 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt struct mlme_priv*pmlmepriv = &padapter->mlmepriv; int ret; - /* Indicat the packets to upper layer */ + /* Indicate the packets to upper layer */ if (pkt) { if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) { _pkt *pskb2 = NULL; @@ -109,11 +113,7 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt struct sta_priv *pstapriv = &padapter->stapriv; int bmcast = IS_MCAST(pattrib->dst); - /* DBG_871X("bmcast =%d\n", bmcast); */ - if (memcmp(pattrib->dst, myid(&padapter->eeprompriv), ETH_ALEN)) { - /* DBG_871X("not ap psta =%p, addr =%pM\n", psta, pattrib->dst); */ - if (bmcast) { psta = rtw_get_bcmc_stainfo(padapter); pskb2 = rtw_skb_clone(pkt); @@ -123,9 +123,6 @@ void rtw_os_recv_indicate_pkt(struct adapter *padapter, _pkt *pkt, struct rx_pkt if (psta) { struct net_device *pnetdev = (struct net_device*)padapter->pnetdev; - - /* DBG_871X("directly forwarding to the rtw_xmit_entry\n"); */ - /* skb->ip_summed = CHECKSUM_NONE; */ pkt->dev = pnetdev; skb_set_queue_mapping(pkt, rtw_recv_select_queue(pkt)); @@ -197,7 +194,7 @@ void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup) key_type |= NL80211_KEYTYPE_PAIRWISE; } - cfg80211_michael_mic_failure(padapter->pnetdev, (u8 *)&pmlmepriv->assoc_bssid[ 0 ], key_type, -1, + cfg80211_michael_mic_failure(padapter->pnetdev, (u8 *)&pmlmepriv->assoc_bssid[0], key_type, -1, NULL, GFP_ATOMIC); memset(&ev, 0x00, sizeof(ev)); @@ -208,7 +205,7 @@ void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup) } ev.src_addr.sa_family = ARPHRD_ETHER; - memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[ 0 ], ETH_ALEN); + memcpy(ev.src_addr.sa_data, &pmlmepriv->assoc_bssid[0], ETH_ALEN); memset(&wrqu, 0x00, sizeof(wrqu)); wrqu.data.length = sizeof(ev); @@ -223,7 +220,7 @@ static void rtw_os_ksocket_send(struct adapter *padapter, union recv_frame *prec DBG_871X("eth rx: got eth_type = 0x%x\n", pattrib->eth_type); - if (psta && psta->isrc && psta->pid>0) { + if (psta && psta->isrc && psta->pid > 0) { u16 rx_pid; rx_pid = *(u16*)(skb->data+ETH_HLEN); @@ -234,14 +231,10 @@ static void rtw_os_ksocket_send(struct adapter *padapter, union recv_frame *prec if (rx_pid == psta->pid) { int i; u16 len = *(u16*)(skb->data+ETH_HLEN+2); - /* u16 ctrl_type = *(u16*)(skb->data+ETH_HLEN+4); */ - - /* DBG_871X("eth, RC: len = 0x%x, ctrl_type = 0x%x\n", len, ctrl_type); */ DBG_871X("eth, RC: len = 0x%x\n", len); - for (i = 0;i<len;i++) + for (i = 0; i < len; i++) DBG_871X("0x%x\n", *(skb->data+ETH_HLEN+4+i)); - /* DBG_871X("0x%x\n", *(skb->data+ETH_HLEN+6+i)); */ DBG_871X("eth, RC-end\n"); } @@ -291,7 +284,8 @@ int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame rtw_os_recv_indicate_pkt(padapter, skb, pattrib); - precv_frame->u.hdr.pkt = NULL; /* pointers to NULL before rtw_free_recvframe() */ + /* pointers to NULL before rtw_free_recvframe() */ + precv_frame->u.hdr.pkt = NULL; rtw_free_recvframe(precv_frame, pfree_recv_queue); @@ -301,11 +295,11 @@ int rtw_recv_indicatepkt(struct adapter *padapter, union recv_frame *precv_frame _recv_indicatepkt_drop: - /* enqueue back to free_recv_queue */ - rtw_free_recvframe(precv_frame, pfree_recv_queue); + /* enqueue back to free_recv_queue */ + rtw_free_recvframe(precv_frame, pfree_recv_queue); - DBG_COUNTER(padapter->rx_logs.os_indicate_err); - return _FAIL; + DBG_COUNTER(padapter->rx_logs.os_indicate_err); + return _FAIL; } void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl) diff --git a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c index 859f4a0afb95..b093b5629171 100644 --- a/drivers/staging/rtl8723bs/os_dep/sdio_intf.c +++ b/drivers/staging/rtl8723bs/os_dep/sdio_intf.c @@ -108,7 +108,7 @@ static void sdio_free_irq(struct dvobj_priv *dvobj) err = sdio_release_irq(func); if (err) { dvobj->drv_dbg.dbg_sdio_free_irq_error_cnt++; - DBG_871X_LEVEL(_drv_err_,"%s: sdio_release_irq FAIL(%d)!\n", __func__, err); + DBG_871X_LEVEL(_drv_err_, "%s: sdio_release_irq FAIL(%d)!\n", __func__, err); } else dvobj->drv_dbg.dbg_sdio_free_irq_cnt++; sdio_release_host(func); @@ -324,7 +324,7 @@ static struct adapter *rtw_sdio_if1_init(struct dvobj_priv *dvobj, const struct padapter->dvobj = dvobj; dvobj->if1 = padapter; - padapter->bDriverStopped =true; + padapter->bDriverStopped = true; dvobj->padapters = padapter; padapter->iface_id = 0; @@ -430,7 +430,7 @@ static void rtw_sdio_if1_deinit(struct adapter *if1) rtw_cancel_all_timer(if1); #ifdef CONFIG_WOWLAN - adapter_to_pwrctl(if1)->wowlan_mode =false; + adapter_to_pwrctl(if1)->wowlan_mode = false; DBG_871X_LEVEL(_drv_always_, "%s wowlan_mode:%d\n", __func__, adapter_to_pwrctl(if1)->wowlan_mode); #endif /* CONFIG_WOWLAN */ @@ -500,7 +500,7 @@ free_dvobj: if (status != _SUCCESS) sdio_dvobj_deinit(func); exit: - return status == _SUCCESS?0:-ENODEV; + return status == _SUCCESS ? 0 : -ENODEV; } static void rtw_dev_remove(struct sdio_func *func) @@ -548,7 +548,7 @@ extern int pm_netdev_close(struct net_device *pnetdev, u8 bnormal); static int rtw_sdio_suspend(struct device *dev) { - struct sdio_func *func =dev_to_sdio_func(dev); + struct sdio_func *func = dev_to_sdio_func(dev); struct dvobj_priv *psdpriv = sdio_get_drvdata(func); struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv); struct adapter *padapter = psdpriv->if1; @@ -585,7 +585,7 @@ static int rtw_resume_process(struct adapter *padapter) static int rtw_sdio_resume(struct device *dev) { - struct sdio_func *func =dev_to_sdio_func(dev); + struct sdio_func *func = dev_to_sdio_func(dev); struct dvobj_priv *psdpriv = sdio_get_drvdata(func); struct adapter *padapter = psdpriv->if1; struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; diff --git a/drivers/staging/rtl8723bs/os_dep/xmit_linux.c b/drivers/staging/rtl8723bs/os_dep/xmit_linux.c index 4e81bc13e57d..fec8a8caaa46 100644 --- a/drivers/staging/rtl8723bs/os_dep/xmit_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/xmit_linux.c @@ -15,16 +15,16 @@ uint rtw_remainder_len(struct pkt_file *pfile) return (pfile->buf_len - ((SIZE_PTR)(pfile->cur_addr) - (SIZE_PTR)(pfile->buf_start))); } -void _rtw_open_pktfile (_pkt *pktptr, struct pkt_file *pfile) +void _rtw_open_pktfile(_pkt *pktptr, struct pkt_file *pfile) { pfile->pkt = pktptr; pfile->cur_addr = pfile->buf_start = pktptr->data; pfile->pkt_len = pfile->buf_len = pktptr->len; - pfile->cur_buffer = pfile->buf_start ; + pfile->cur_buffer = pfile->buf_start; } -uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen) +uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen) { uint len = 0; diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c index 17c4131f5f62..c6f9375468eb 100644 --- a/drivers/staging/rts5208/rtsx_chip.c +++ b/drivers/staging/rts5208/rtsx_chip.c @@ -940,7 +940,8 @@ static void rtsx_monitor_aspm_config(struct rtsx_chip *chip) if (maybe_support_aspm) chip->aspm_l0s_l1_en = 0x03; - dev_dbg(rtsx_dev(chip), "aspm_level[0] = 0x%02x, aspm_level[1] = 0x%02x\n", + dev_dbg(rtsx_dev(chip), + "aspm_level[0] = 0x%02x, aspm_level[1] = 0x%02x\n", chip->aspm_level[0], chip->aspm_level[1]); if (chip->aspm_l0s_l1_en) { diff --git a/drivers/staging/sm750fb/Makefile b/drivers/staging/sm750fb/Makefile index 1cf3849cef23..b89aa4c12e9d 100644 --- a/drivers/staging/sm750fb/Makefile +++ b/drivers/staging/sm750fb/Makefile @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_FB_SM750) += sm750fb.o -sm750fb-objs := sm750.o sm750_hw.o sm750_accel.o sm750_cursor.o ddk750_chip.o ddk750_power.o ddk750_mode.o -sm750fb-objs += ddk750_display.o ddk750_swi2c.o ddk750_sii164.o ddk750_dvi.o ddk750_hwi2c.o +sm750fb-objs := sm750.o sm750_hw.o sm750_accel.o sm750_cursor.o \ + ddk750_chip.o ddk750_power.o ddk750_mode.o \ + ddk750_display.o ddk750_swi2c.o ddk750_sii164.o \ + ddk750_dvi.o ddk750_hwi2c.o diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c index 5f1bda37f86d..822ceac83068 100644 --- a/drivers/staging/speakup/keyhelp.c +++ b/drivers/staging/speakup/keyhelp.c @@ -49,7 +49,7 @@ static int cur_item, nstates; static void build_key_data(void) { u_char *kp, counters[MAXFUNCS], ch, ch1; - u_short *p_key = key_data, key; + u_short *p_key, key; int i, offset = 1; nstates = (int)(state_tbl[-1]); diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c index 81ecfd1a200d..02471d932d71 100644 --- a/drivers/staging/speakup/main.c +++ b/drivers/staging/speakup/main.c @@ -2117,7 +2117,8 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym, spk_keydown = 0; goto out; } - value = spk_lastkey = pad_chars[value]; + value = pad_chars[value]; + spk_lastkey = value; spk_keydown++; spk_parked &= 0xfe; goto no_map; diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c index 9d85a3a1af4c..28cedaec6d8a 100644 --- a/drivers/staging/speakup/speakup_soft.c +++ b/drivers/staging/speakup/speakup_soft.c @@ -388,7 +388,7 @@ static int softsynth_probe(struct spk_synth *synth) synthu_device.name = "softsynthu"; synthu_device.fops = &softsynthu_fops; if (misc_register(&synthu_device)) { - pr_warn("Couldn't initialize miscdevice /dev/softsynth.\n"); + pr_warn("Couldn't initialize miscdevice /dev/softsynthu.\n"); return -ENODEV; } diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h index ac6a74883af4..c75b40838794 100644 --- a/drivers/staging/speakup/spk_priv.h +++ b/drivers/staging/speakup/spk_priv.h @@ -11,13 +11,11 @@ #ifndef _SPEAKUP_PRIVATE_H #define _SPEAKUP_PRIVATE_H +#include <linux/printk.h> + #include "spk_types.h" #include "spk_priv_keyinfo.h" -#ifndef pr_warn -#define pr_warn(fmt, arg...) printk(KERN_WARNING fmt, ##arg) -#endif - #define V_LAST_VAR { MAXVARS } #define SPACE 0x20 #define SYNTH_CHECK 20030716 /* today's date ought to do for check value */ diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c index 5a9eff08cb96..9b95f77f9265 100644 --- a/drivers/staging/speakup/spk_ttyio.c +++ b/drivers/staging/speakup/spk_ttyio.c @@ -51,7 +51,7 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty) return -EOPNOTSUPP; speakup_tty = tty; - ldisc_data = kmalloc(sizeof(struct spk_ldisc_data), GFP_KERNEL); + ldisc_data = kmalloc(sizeof(*ldisc_data), GFP_KERNEL); if (!ldisc_data) return -ENOMEM; diff --git a/drivers/staging/speakup/spk_types.h b/drivers/staging/speakup/spk_types.h index a2fc72c29894..fc6a9416829c 100644 --- a/drivers/staging/speakup/spk_types.h +++ b/drivers/staging/speakup/spk_types.h @@ -189,7 +189,7 @@ struct spk_synth { void (*flush)(struct spk_synth *synth); int (*is_alive)(struct spk_synth *synth); int (*synth_adjust)(struct st_var_header *var); - void (*read_buff_add)(u_char); + void (*read_buff_add)(u_char c); unsigned char (*get_index)(struct spk_synth *synth); struct synth_indexing indexing; int alive; diff --git a/drivers/staging/unisys/Documentation/overview.txt b/drivers/staging/unisys/Documentation/overview.txt index f8a4144b239c..cf29f884cbe0 100644 --- a/drivers/staging/unisys/Documentation/overview.txt +++ b/drivers/staging/unisys/Documentation/overview.txt @@ -15,12 +15,12 @@ normally be unsharable, specifically: * visorinput - keyboard and mouse These drivers conform to the standard Linux bus/device model described -within Documentation/driver-api/driver-model/, and utilize a driver named visorbus to -present the virtual busses involved. Drivers in the 'visor*' driver set are -commonly referred to as "guest drivers" or "client drivers". All drivers -except visorbus expose a device of a specific usable class to the Linux guest -environment (e.g., block, network, or input), and are collectively referred -to as "function drivers". +within Documentation/driver-api/driver-model/, and utilize a driver named +visorbus to present the virtual busses involved. Drivers in the 'visor*' +driver set are commonly referred to as "guest drivers" or "client drivers". +All drivers except visorbus expose a device of a specific usable class to the +Linux guest environment (e.g., block, network, or input), and are collectively +referred to as "function drivers". The back-end for each device is owned and managed by a small, single-purpose service partition in the s-Par firmware, which communicates diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c index 9693fb559052..6d202cba8575 100644 --- a/drivers/staging/unisys/visorinput/visorinput.c +++ b/drivers/staging/unisys/visorinput/visorinput.c @@ -111,7 +111,7 @@ struct visorinput_devdata { /* size of following array */ unsigned int keycode_table_bytes; /* for keyboard devices: visorkbd_keycode[] + visorkbd_ext_keycode[] */ - unsigned char keycode_table[0]; + unsigned char keycode_table[]; }; static const guid_t visor_keyboard_channel_guid = VISOR_KEYBOARD_CHANNEL_GUID; diff --git a/drivers/staging/uwb/Kconfig b/drivers/staging/uwb/Kconfig deleted file mode 100644 index 259e053e1e09..000000000000 --- a/drivers/staging/uwb/Kconfig +++ /dev/null @@ -1,72 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -# -# UWB device configuration -# - -menuconfig UWB - tristate "Ultra Wideband devices" - default n - select GENERIC_NET_UTILS - help - UWB is a high-bandwidth, low-power, point-to-point radio - technology using a wide spectrum (3.1-10.6GHz). It is - optimized for in-room use (480Mbps at 2 meters, 110Mbps at - 10m). It serves as the transport layer for other protocols, - such as Wireless USB (WUSB). - - The topology is peer to peer; however, higher level - protocols (such as WUSB) might impose a master/slave - relationship. - - Say Y here if your computer has UWB radio controllers (USB or PCI) - based. You will need to enable the radio controllers - below. It is ok to select all of them, no harm done. - - For more help check the UWB and WUSB related files in - <file:Documentation/usb/>. - - To compile the UWB stack as a module, choose M here. - -if UWB - -config UWB_HWA - tristate "UWB Radio Control driver for WUSB-compliant USB dongles (HWA)" - depends on USB - help - This driver enables the radio controller for HWA USB - devices. HWA stands for Host Wire Adapter, and it is a UWB - Radio Controller connected to your system via USB. Most of - them come with a Wireless USB host controller also. - - To compile this driver select Y (built in) or M (module). It - is safe to select any even if you do not have the hardware. - -config UWB_WHCI - tristate "UWB Radio Control driver for WHCI-compliant cards" - depends on PCI - help - This driver enables the radio controller for WHCI cards. - - WHCI is a specification developed by Intel - (http://www.intel.com/technology/comms/wusb/whci.htm) much - in the spirit of USB's EHCI, but for UWB and Wireless USB - radio/host controllers connected via memory mapping (eg: - PCI). Most of these cards come also with a Wireless USB host - controller. - - To compile this driver select Y (built in) or M (module). It - is safe to select any even if you do not have the hardware. - -config UWB_I1480U - tristate "Support for Intel Wireless UWB Link 1480 HWA" - depends on UWB_HWA - select FW_LOADER - help - This driver enables support for the i1480 when connected via - USB. It consists of a firmware uploader that will enable it - to behave as an HWA device. - - To compile this driver select Y (built in) or M (module). It - is safe to select any even if you do not have the hardware. - -endif # UWB diff --git a/drivers/staging/uwb/Makefile b/drivers/staging/uwb/Makefile deleted file mode 100644 index 32f4de7afbd6..000000000000 --- a/drivers/staging/uwb/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UWB) += uwb.o -obj-$(CONFIG_UWB_WHCI) += umc.o whci.o whc-rc.o -obj-$(CONFIG_UWB_HWA) += hwa-rc.o -obj-$(CONFIG_UWB_I1480U) += i1480/ - -uwb-objs := \ - address.o \ - allocator.o \ - beacon.o \ - driver.o \ - drp.o \ - drp-avail.o \ - drp-ie.o \ - est.o \ - ie.o \ - ie-rcv.o \ - lc-dev.o \ - lc-rc.o \ - neh.o \ - pal.o \ - radio.o \ - reset.o \ - rsv.o \ - scan.o \ - uwb-debug.o \ - uwbd.o - -umc-objs := \ - umc-bus.o \ - umc-dev.o \ - umc-drv.o diff --git a/drivers/staging/uwb/TODO b/drivers/staging/uwb/TODO deleted file mode 100644 index abae57000534..000000000000 --- a/drivers/staging/uwb/TODO +++ /dev/null @@ -1,8 +0,0 @@ -TODO: Remove in late 2019 unless there are users - -There seems to not be any real wireless USB devices anywhere in the wild -anymore. It turned out to be a failed technology :( - -This will be removed from the tree if no one objects. - -Greg Kroah-Hartman <gregkh@linuxfoundation.org> diff --git a/drivers/staging/uwb/address.c b/drivers/staging/uwb/address.c deleted file mode 100644 index 857d5cd56a95..000000000000 --- a/drivers/staging/uwb/address.c +++ /dev/null @@ -1,352 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Address management - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ - -#include <linux/slab.h> -#include <linux/errno.h> -#include <linux/module.h> -#include <linux/device.h> -#include <linux/random.h> -#include <linux/etherdevice.h> - -#include "uwb-internal.h" - - -/** Device Address Management command */ -struct uwb_rc_cmd_dev_addr_mgmt { - struct uwb_rccb rccb; - u8 bmOperationType; - u8 baAddr[6]; -} __attribute__((packed)); - - -/** - * Low level command for setting/getting UWB radio's addresses - * - * @hwarc: HWA Radio Control interface instance - * @bmOperationType: - * Set/get, MAC/DEV (see WUSB1.0[8.6.2.2]) - * @baAddr: address buffer--assumed to have enough data to hold - * the address type requested. - * @reply: Pointer to reply buffer (can be stack allocated) - * @returns: 0 if ok, < 0 errno code on error. - * - * @cmd has to be allocated because USB cannot grok USB or vmalloc - * buffers depending on your combination of host architecture. - */ -static -int uwb_rc_dev_addr_mgmt(struct uwb_rc *rc, - u8 bmOperationType, const u8 *baAddr, - struct uwb_rc_evt_dev_addr_mgmt *reply) -{ - int result; - struct uwb_rc_cmd_dev_addr_mgmt *cmd; - - result = -ENOMEM; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - goto error_kzalloc; - cmd->rccb.bCommandType = UWB_RC_CET_GENERAL; - cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_DEV_ADDR_MGMT); - cmd->bmOperationType = bmOperationType; - if (baAddr) { - size_t size = 0; - switch (bmOperationType >> 1) { - case 0: size = 2; break; - case 1: size = 6; break; - default: BUG(); - } - memcpy(cmd->baAddr, baAddr, size); - } - reply->rceb.bEventType = UWB_RC_CET_GENERAL; - reply->rceb.wEvent = UWB_RC_CMD_DEV_ADDR_MGMT; - result = uwb_rc_cmd(rc, "DEV-ADDR-MGMT", - &cmd->rccb, sizeof(*cmd), - &reply->rceb, sizeof(*reply)); - if (result < 0) - goto error_cmd; - if (result < sizeof(*reply)) { - dev_err(&rc->uwb_dev.dev, - "DEV-ADDR-MGMT: not enough data replied: " - "%d vs %zu bytes needed\n", result, sizeof(*reply)); - result = -ENOMSG; - } else if (reply->bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(&rc->uwb_dev.dev, - "DEV-ADDR-MGMT: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply->bResultCode), - reply->bResultCode); - result = -EIO; - } else - result = 0; -error_cmd: - kfree(cmd); -error_kzalloc: - return result; -} - - -/** - * Set the UWB RC MAC or device address. - * - * @rc: UWB Radio Controller - * @_addr: Pointer to address to write [assumed to be either a - * 'struct uwb_mac_addr *' or a 'struct uwb_dev_addr *']. - * @type: Type of address to set (UWB_ADDR_DEV or UWB_ADDR_MAC). - * @returns: 0 if ok, < 0 errno code on error. - * - * Some anal retentivity here: even if both 'struct - * uwb_{dev,mac}_addr' have the actual byte array in the same offset - * and I could just pass _addr to hwarc_cmd_dev_addr_mgmt(), I prefer - * to use some syntatic sugar in case someday we decide to change the - * format of the structs. The compiler will optimize it out anyway. - */ -static int uwb_rc_addr_set(struct uwb_rc *rc, - const void *_addr, enum uwb_addr_type type) -{ - int result; - u8 bmOperationType = 0x1; /* Set address */ - const struct uwb_dev_addr *dev_addr = _addr; - const struct uwb_mac_addr *mac_addr = _addr; - struct uwb_rc_evt_dev_addr_mgmt reply; - const u8 *baAddr; - - result = -EINVAL; - switch (type) { - case UWB_ADDR_DEV: - baAddr = dev_addr->data; - break; - case UWB_ADDR_MAC: - baAddr = mac_addr->data; - bmOperationType |= 0x2; - break; - default: - return result; - } - return uwb_rc_dev_addr_mgmt(rc, bmOperationType, baAddr, &reply); -} - - -/** - * Get the UWB radio's MAC or device address. - * - * @rc: UWB Radio Controller - * @_addr: Where to write the address data [assumed to be either a - * 'struct uwb_mac_addr *' or a 'struct uwb_dev_addr *']. - * @type: Type of address to get (UWB_ADDR_DEV or UWB_ADDR_MAC). - * @returns: 0 if ok (and *_addr set), < 0 errno code on error. - * - * See comment in uwb_rc_addr_set() about anal retentivity in the - * type handling of the address variables. - */ -static int uwb_rc_addr_get(struct uwb_rc *rc, - void *_addr, enum uwb_addr_type type) -{ - int result; - u8 bmOperationType = 0x0; /* Get address */ - struct uwb_rc_evt_dev_addr_mgmt evt; - struct uwb_dev_addr *dev_addr = _addr; - struct uwb_mac_addr *mac_addr = _addr; - u8 *baAddr; - - result = -EINVAL; - switch (type) { - case UWB_ADDR_DEV: - baAddr = dev_addr->data; - break; - case UWB_ADDR_MAC: - bmOperationType |= 0x2; - baAddr = mac_addr->data; - break; - default: - return result; - } - result = uwb_rc_dev_addr_mgmt(rc, bmOperationType, baAddr, &evt); - if (result == 0) - switch (type) { - case UWB_ADDR_DEV: - memcpy(&dev_addr->data, evt.baAddr, - sizeof(dev_addr->data)); - break; - case UWB_ADDR_MAC: - memcpy(&mac_addr->data, evt.baAddr, - sizeof(mac_addr->data)); - break; - default: /* shut gcc up */ - BUG(); - } - return result; -} - - -/** Get @rc's MAC address to @addr */ -int uwb_rc_mac_addr_get(struct uwb_rc *rc, - struct uwb_mac_addr *addr) { - return uwb_rc_addr_get(rc, addr, UWB_ADDR_MAC); -} -EXPORT_SYMBOL_GPL(uwb_rc_mac_addr_get); - - -/** Get @rc's device address to @addr */ -int uwb_rc_dev_addr_get(struct uwb_rc *rc, - struct uwb_dev_addr *addr) { - return uwb_rc_addr_get(rc, addr, UWB_ADDR_DEV); -} -EXPORT_SYMBOL_GPL(uwb_rc_dev_addr_get); - - -/** Set @rc's address to @addr */ -int uwb_rc_mac_addr_set(struct uwb_rc *rc, - const struct uwb_mac_addr *addr) -{ - int result = -EINVAL; - mutex_lock(&rc->uwb_dev.mutex); - result = uwb_rc_addr_set(rc, addr, UWB_ADDR_MAC); - mutex_unlock(&rc->uwb_dev.mutex); - return result; -} - - -/** Set @rc's address to @addr */ -int uwb_rc_dev_addr_set(struct uwb_rc *rc, - const struct uwb_dev_addr *addr) -{ - int result = -EINVAL; - mutex_lock(&rc->uwb_dev.mutex); - result = uwb_rc_addr_set(rc, addr, UWB_ADDR_DEV); - rc->uwb_dev.dev_addr = *addr; - mutex_unlock(&rc->uwb_dev.mutex); - return result; -} - -/* Returns !0 if given address is already assigned to device. */ -int __uwb_mac_addr_assigned_check(struct device *dev, void *_addr) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_mac_addr *addr = _addr; - - if (!uwb_mac_addr_cmp(addr, &uwb_dev->mac_addr)) - return !0; - return 0; -} - -/* Returns !0 if given address is already assigned to device. */ -int __uwb_dev_addr_assigned_check(struct device *dev, void *_addr) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_dev_addr *addr = _addr; - if (!uwb_dev_addr_cmp(addr, &uwb_dev->dev_addr)) - return !0; - return 0; -} - -/** - * uwb_dev_addr_assign - assigned a generated DevAddr to a radio controller - * @rc: the (local) radio controller device requiring a new DevAddr - * - * A new DevAddr is required when: - * - first setting up a radio controller - * - if the hardware reports a DevAddr conflict - * - * The DevAddr is randomly generated in the generated DevAddr range - * [0x100, 0xfeff]. The number of devices in a beacon group is limited - * by mMaxBPLength (96) so this address space will never be exhausted. - * - * [ECMA-368] 17.1.1, 17.16. - */ -int uwb_rc_dev_addr_assign(struct uwb_rc *rc) -{ - struct uwb_dev_addr new_addr; - - do { - get_random_bytes(new_addr.data, sizeof(new_addr.data)); - } while (new_addr.data[0] == 0x00 || new_addr.data[0] == 0xff - || __uwb_dev_addr_assigned(rc, &new_addr)); - - return uwb_rc_dev_addr_set(rc, &new_addr); -} - -/** - * uwbd_evt_handle_rc_dev_addr_conflict - handle a DEV_ADDR_CONFLICT event - * @evt: the DEV_ADDR_CONFLICT notification from the radio controller - * - * A new (non-conflicting) DevAddr is assigned to the radio controller. - * - * [ECMA-368] 17.1.1.1. - */ -int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt) -{ - struct uwb_rc *rc = evt->rc; - - return uwb_rc_dev_addr_assign(rc); -} - -/* - * Print the 48-bit EUI MAC address of the radio controller when - * reading /sys/class/uwb_rc/XX/mac_address - */ -static ssize_t uwb_rc_mac_addr_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - struct uwb_mac_addr addr; - ssize_t result; - - mutex_lock(&rc->uwb_dev.mutex); - result = uwb_rc_addr_get(rc, &addr, UWB_ADDR_MAC); - mutex_unlock(&rc->uwb_dev.mutex); - if (result >= 0) { - result = uwb_mac_addr_print(buf, UWB_ADDR_STRSIZE, &addr); - buf[result++] = '\n'; - } - return result; -} - -/* - * Parse a 48 bit address written to /sys/class/uwb_rc/XX/mac_address - * and if correct, set it. - */ -static ssize_t uwb_rc_mac_addr_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - struct uwb_mac_addr addr; - ssize_t result; - - if (!mac_pton(buf, addr.data)) - return -EINVAL; - if (is_multicast_ether_addr(addr.data)) { - dev_err(&rc->uwb_dev.dev, "refusing to set multicast " - "MAC address %s\n", buf); - return -EINVAL; - } - result = uwb_rc_mac_addr_set(rc, &addr); - if (result == 0) - rc->uwb_dev.mac_addr = addr; - - return result < 0 ? result : size; -} -DEVICE_ATTR(mac_address, S_IRUGO | S_IWUSR, uwb_rc_mac_addr_show, uwb_rc_mac_addr_store); - -/** Print @addr to @buf, @return bytes written */ -size_t __uwb_addr_print(char *buf, size_t buf_size, const unsigned char *addr, - int type) -{ - size_t result; - if (type) - result = scnprintf(buf, buf_size, "%pM", addr); - else - result = scnprintf(buf, buf_size, "%02x:%02x", - addr[1], addr[0]); - return result; -} -EXPORT_SYMBOL_GPL(__uwb_addr_print); diff --git a/drivers/staging/uwb/allocator.c b/drivers/staging/uwb/allocator.c deleted file mode 100644 index 1f429fba20b7..000000000000 --- a/drivers/staging/uwb/allocator.c +++ /dev/null @@ -1,374 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB reservation management. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/slab.h> -#include "uwb.h" - -#include "uwb-internal.h" - -static void uwb_rsv_fill_column_alloc(struct uwb_rsv_alloc_info *ai) -{ - int col, mas, safe_mas, unsafe_mas; - unsigned char *bm = ai->bm; - struct uwb_rsv_col_info *ci = ai->ci; - unsigned char c; - - for (col = ci->csi.start_col; col < UWB_NUM_ZONES; col += ci->csi.interval) { - - safe_mas = ci->csi.safe_mas_per_col; - unsafe_mas = ci->csi.unsafe_mas_per_col; - - for (mas = 0; mas < UWB_MAS_PER_ZONE; mas++ ) { - if (bm[col * UWB_MAS_PER_ZONE + mas] == 0) { - - if (safe_mas > 0) { - safe_mas--; - c = UWB_RSV_MAS_SAFE; - } else if (unsafe_mas > 0) { - unsafe_mas--; - c = UWB_RSV_MAS_UNSAFE; - } else { - break; - } - bm[col * UWB_MAS_PER_ZONE + mas] = c; - } - } - } -} - -static void uwb_rsv_fill_row_alloc(struct uwb_rsv_alloc_info *ai) -{ - int mas, col, rows; - unsigned char *bm = ai->bm; - struct uwb_rsv_row_info *ri = &ai->ri; - unsigned char c; - - rows = 1; - c = UWB_RSV_MAS_SAFE; - for (mas = UWB_MAS_PER_ZONE - 1; mas >= 0; mas--) { - if (ri->avail[mas] == 1) { - - if (rows > ri->used_rows) { - break; - } else if (rows > 7) { - c = UWB_RSV_MAS_UNSAFE; - } - - for (col = 0; col < UWB_NUM_ZONES; col++) { - if (bm[col * UWB_NUM_ZONES + mas] != UWB_RSV_MAS_NOT_AVAIL) { - bm[col * UWB_NUM_ZONES + mas] = c; - if(c == UWB_RSV_MAS_SAFE) - ai->safe_allocated_mases++; - else - ai->unsafe_allocated_mases++; - } - } - rows++; - } - } - ai->total_allocated_mases = ai->safe_allocated_mases + ai->unsafe_allocated_mases; -} - -/* - * Find the best column set for a given availability, interval, num safe mas and - * num unsafe mas. - * - * The different sets are tried in order as shown below, depending on the interval. - * - * interval = 16 - * deep = 0 - * set 1 -> { 8 } - * deep = 1 - * set 1 -> { 4 } - * set 2 -> { 12 } - * deep = 2 - * set 1 -> { 2 } - * set 2 -> { 6 } - * set 3 -> { 10 } - * set 4 -> { 14 } - * deep = 3 - * set 1 -> { 1 } - * set 2 -> { 3 } - * set 3 -> { 5 } - * set 4 -> { 7 } - * set 5 -> { 9 } - * set 6 -> { 11 } - * set 7 -> { 13 } - * set 8 -> { 15 } - * - * interval = 8 - * deep = 0 - * set 1 -> { 4 12 } - * deep = 1 - * set 1 -> { 2 10 } - * set 2 -> { 6 14 } - * deep = 2 - * set 1 -> { 1 9 } - * set 2 -> { 3 11 } - * set 3 -> { 5 13 } - * set 4 -> { 7 15 } - * - * interval = 4 - * deep = 0 - * set 1 -> { 2 6 10 14 } - * deep = 1 - * set 1 -> { 1 5 9 13 } - * set 2 -> { 3 7 11 15 } - * - * interval = 2 - * deep = 0 - * set 1 -> { 1 3 5 7 9 11 13 15 } - */ -static int uwb_rsv_find_best_column_set(struct uwb_rsv_alloc_info *ai, int interval, - int num_safe_mas, int num_unsafe_mas) -{ - struct uwb_rsv_col_info *ci = ai->ci; - struct uwb_rsv_col_set_info *csi = &ci->csi; - struct uwb_rsv_col_set_info tmp_csi; - int deep, set, col, start_col_deep, col_start_set; - int start_col, max_mas_in_set, lowest_max_mas_in_deep; - int n_mas; - int found = UWB_RSV_ALLOC_NOT_FOUND; - - tmp_csi.start_col = 0; - start_col_deep = interval; - n_mas = num_unsafe_mas + num_safe_mas; - - for (deep = 0; ((interval >> deep) & 0x1) == 0; deep++) { - start_col_deep /= 2; - col_start_set = 0; - lowest_max_mas_in_deep = UWB_MAS_PER_ZONE; - - for (set = 1; set <= (1 << deep); set++) { - max_mas_in_set = 0; - start_col = start_col_deep + col_start_set; - for (col = start_col; col < UWB_NUM_ZONES; col += interval) { - - if (ci[col].max_avail_safe >= num_safe_mas && - ci[col].max_avail_unsafe >= n_mas) { - if (ci[col].highest_mas[n_mas] > max_mas_in_set) - max_mas_in_set = ci[col].highest_mas[n_mas]; - } else { - max_mas_in_set = 0; - break; - } - } - if ((lowest_max_mas_in_deep > max_mas_in_set) && max_mas_in_set) { - lowest_max_mas_in_deep = max_mas_in_set; - - tmp_csi.start_col = start_col; - } - col_start_set += (interval >> deep); - } - - if (lowest_max_mas_in_deep < 8) { - csi->start_col = tmp_csi.start_col; - found = UWB_RSV_ALLOC_FOUND; - break; - } else if ((lowest_max_mas_in_deep > 8) && - (lowest_max_mas_in_deep != UWB_MAS_PER_ZONE) && - (found == UWB_RSV_ALLOC_NOT_FOUND)) { - csi->start_col = tmp_csi.start_col; - found = UWB_RSV_ALLOC_FOUND; - } - } - - if (found == UWB_RSV_ALLOC_FOUND) { - csi->interval = interval; - csi->safe_mas_per_col = num_safe_mas; - csi->unsafe_mas_per_col = num_unsafe_mas; - - ai->safe_allocated_mases = (UWB_NUM_ZONES / interval) * num_safe_mas; - ai->unsafe_allocated_mases = (UWB_NUM_ZONES / interval) * num_unsafe_mas; - ai->total_allocated_mases = ai->safe_allocated_mases + ai->unsafe_allocated_mases; - ai->interval = interval; - } - return found; -} - -static void get_row_descriptors(struct uwb_rsv_alloc_info *ai) -{ - unsigned char *bm = ai->bm; - struct uwb_rsv_row_info *ri = &ai->ri; - int col, mas; - - ri->free_rows = 16; - for (mas = 0; mas < UWB_MAS_PER_ZONE; mas ++) { - ri->avail[mas] = 1; - for (col = 1; col < UWB_NUM_ZONES; col++) { - if (bm[col * UWB_NUM_ZONES + mas] == UWB_RSV_MAS_NOT_AVAIL) { - ri->free_rows--; - ri->avail[mas]=0; - break; - } - } - } -} - -static void uwb_rsv_fill_column_info(unsigned char *bm, int column, struct uwb_rsv_col_info *rci) -{ - int mas; - int block_count = 0, start_block = 0; - int previous_avail = 0; - int available = 0; - int safe_mas_in_row[UWB_MAS_PER_ZONE] = { - 8, 7, 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, - }; - - rci->max_avail_safe = 0; - - for (mas = 0; mas < UWB_MAS_PER_ZONE; mas ++) { - if (!bm[column * UWB_NUM_ZONES + mas]) { - available++; - rci->max_avail_unsafe = available; - - rci->highest_mas[available] = mas; - - if (previous_avail) { - block_count++; - if ((block_count > safe_mas_in_row[start_block]) && - (!rci->max_avail_safe)) - rci->max_avail_safe = available - 1; - } else { - previous_avail = 1; - start_block = mas; - block_count = 1; - } - } else { - previous_avail = 0; - } - } - if (!rci->max_avail_safe) - rci->max_avail_safe = rci->max_avail_unsafe; -} - -static void get_column_descriptors(struct uwb_rsv_alloc_info *ai) -{ - unsigned char *bm = ai->bm; - struct uwb_rsv_col_info *ci = ai->ci; - int col; - - for (col = 1; col < UWB_NUM_ZONES; col++) { - uwb_rsv_fill_column_info(bm, col, &ci[col]); - } -} - -static int uwb_rsv_find_best_row_alloc(struct uwb_rsv_alloc_info *ai) -{ - int n_rows; - int max_rows = ai->max_mas / UWB_USABLE_MAS_PER_ROW; - int min_rows = ai->min_mas / UWB_USABLE_MAS_PER_ROW; - if (ai->min_mas % UWB_USABLE_MAS_PER_ROW) - min_rows++; - for (n_rows = max_rows; n_rows >= min_rows; n_rows--) { - if (n_rows <= ai->ri.free_rows) { - ai->ri.used_rows = n_rows; - ai->interval = 1; /* row reservation */ - uwb_rsv_fill_row_alloc(ai); - return UWB_RSV_ALLOC_FOUND; - } - } - return UWB_RSV_ALLOC_NOT_FOUND; -} - -static int uwb_rsv_find_best_col_alloc(struct uwb_rsv_alloc_info *ai, int interval) -{ - int n_safe, n_unsafe, n_mas; - int n_column = UWB_NUM_ZONES / interval; - int max_per_zone = ai->max_mas / n_column; - int min_per_zone = ai->min_mas / n_column; - - if (ai->min_mas % n_column) - min_per_zone++; - - if (min_per_zone > UWB_MAS_PER_ZONE) { - return UWB_RSV_ALLOC_NOT_FOUND; - } - - if (max_per_zone > UWB_MAS_PER_ZONE) { - max_per_zone = UWB_MAS_PER_ZONE; - } - - for (n_mas = max_per_zone; n_mas >= min_per_zone; n_mas--) { - if (uwb_rsv_find_best_column_set(ai, interval, 0, n_mas) == UWB_RSV_ALLOC_NOT_FOUND) - continue; - for (n_safe = n_mas; n_safe >= 0; n_safe--) { - n_unsafe = n_mas - n_safe; - if (uwb_rsv_find_best_column_set(ai, interval, n_safe, n_unsafe) == UWB_RSV_ALLOC_FOUND) { - uwb_rsv_fill_column_alloc(ai); - return UWB_RSV_ALLOC_FOUND; - } - } - } - return UWB_RSV_ALLOC_NOT_FOUND; -} - -int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, struct uwb_mas_bm *available, - struct uwb_mas_bm *result) -{ - struct uwb_rsv_alloc_info *ai; - int interval; - int bit_index; - - ai = kzalloc(sizeof(struct uwb_rsv_alloc_info), GFP_KERNEL); - if (!ai) - return UWB_RSV_ALLOC_NOT_FOUND; - ai->min_mas = rsv->min_mas; - ai->max_mas = rsv->max_mas; - ai->max_interval = rsv->max_interval; - - - /* fill the not available vector from the available bm */ - for_each_clear_bit(bit_index, available->bm, UWB_NUM_MAS) - ai->bm[bit_index] = UWB_RSV_MAS_NOT_AVAIL; - - if (ai->max_interval == 1) { - get_row_descriptors(ai); - if (uwb_rsv_find_best_row_alloc(ai) == UWB_RSV_ALLOC_FOUND) - goto alloc_found; - else - goto alloc_not_found; - } - - get_column_descriptors(ai); - - for (interval = 16; interval >= 2; interval>>=1) { - if (interval > ai->max_interval) - continue; - if (uwb_rsv_find_best_col_alloc(ai, interval) == UWB_RSV_ALLOC_FOUND) - goto alloc_found; - } - - /* try row reservation if no column is found */ - get_row_descriptors(ai); - if (uwb_rsv_find_best_row_alloc(ai) == UWB_RSV_ALLOC_FOUND) - goto alloc_found; - else - goto alloc_not_found; - - alloc_found: - bitmap_zero(result->bm, UWB_NUM_MAS); - bitmap_zero(result->unsafe_bm, UWB_NUM_MAS); - /* fill the safe and unsafe bitmaps */ - for (bit_index = 0; bit_index < UWB_NUM_MAS; bit_index++) { - if (ai->bm[bit_index] == UWB_RSV_MAS_SAFE) - set_bit(bit_index, result->bm); - else if (ai->bm[bit_index] == UWB_RSV_MAS_UNSAFE) - set_bit(bit_index, result->unsafe_bm); - } - bitmap_or(result->bm, result->bm, result->unsafe_bm, UWB_NUM_MAS); - - result->safe = ai->safe_allocated_mases; - result->unsafe = ai->unsafe_allocated_mases; - - kfree(ai); - return UWB_RSV_ALLOC_FOUND; - - alloc_not_found: - kfree(ai); - return UWB_RSV_ALLOC_NOT_FOUND; -} diff --git a/drivers/staging/uwb/beacon.c b/drivers/staging/uwb/beacon.c deleted file mode 100644 index c483c19c5ef8..000000000000 --- a/drivers/staging/uwb/beacon.c +++ /dev/null @@ -1,595 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Beacon management - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/device.h> -#include <linux/err.h> -#include <linux/kdev_t.h> -#include <linux/slab.h> - -#include "uwb-internal.h" - -/* Start Beaconing command structure */ -struct uwb_rc_cmd_start_beacon { - struct uwb_rccb rccb; - __le16 wBPSTOffset; - u8 bChannelNumber; -} __attribute__((packed)); - - -static int uwb_rc_start_beacon(struct uwb_rc *rc, u16 bpst_offset, u8 channel) -{ - int result; - struct uwb_rc_cmd_start_beacon *cmd; - struct uwb_rc_evt_confirm reply; - - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - return -ENOMEM; - cmd->rccb.bCommandType = UWB_RC_CET_GENERAL; - cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_START_BEACON); - cmd->wBPSTOffset = cpu_to_le16(bpst_offset); - cmd->bChannelNumber = channel; - reply.rceb.bEventType = UWB_RC_CET_GENERAL; - reply.rceb.wEvent = UWB_RC_CMD_START_BEACON; - result = uwb_rc_cmd(rc, "START-BEACON", &cmd->rccb, sizeof(*cmd), - &reply.rceb, sizeof(reply)); - if (result < 0) - goto error_cmd; - if (reply.bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(&rc->uwb_dev.dev, - "START-BEACON: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply.bResultCode), reply.bResultCode); - result = -EIO; - } -error_cmd: - kfree(cmd); - return result; -} - -static int uwb_rc_stop_beacon(struct uwb_rc *rc) -{ - int result; - struct uwb_rccb *cmd; - struct uwb_rc_evt_confirm reply; - - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - return -ENOMEM; - cmd->bCommandType = UWB_RC_CET_GENERAL; - cmd->wCommand = cpu_to_le16(UWB_RC_CMD_STOP_BEACON); - reply.rceb.bEventType = UWB_RC_CET_GENERAL; - reply.rceb.wEvent = UWB_RC_CMD_STOP_BEACON; - result = uwb_rc_cmd(rc, "STOP-BEACON", cmd, sizeof(*cmd), - &reply.rceb, sizeof(reply)); - if (result < 0) - goto error_cmd; - if (reply.bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(&rc->uwb_dev.dev, - "STOP-BEACON: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply.bResultCode), reply.bResultCode); - result = -EIO; - } -error_cmd: - kfree(cmd); - return result; -} - -/* - * Start/stop beacons - * - * @rc: UWB Radio Controller to operate on - * @channel: UWB channel on which to beacon (WUSB[table - * 5-12]). If -1, stop beaconing. - * @bpst_offset: Beacon Period Start Time offset; FIXME-do zero - * - * According to WHCI 0.95 [4.13.6] the driver will only receive the RCEB - * of a SET IE command after the device sent the first beacon that includes - * the IEs specified in the SET IE command. So, after we start beaconing we - * check if there is anything in the IE cache and call the SET IE command - * if needed. - */ -int uwb_rc_beacon(struct uwb_rc *rc, int channel, unsigned bpst_offset) -{ - int result; - struct device *dev = &rc->uwb_dev.dev; - - dev_dbg(dev, "%s: channel = %d\n", __func__, channel); - if (channel < 0) - channel = -1; - if (channel == -1) - result = uwb_rc_stop_beacon(rc); - else { - /* channel >= 0...dah */ - result = uwb_rc_start_beacon(rc, bpst_offset, channel); - if (result < 0) { - dev_err(dev, "Cannot start beaconing: %d\n", result); - return result; - } - if (le16_to_cpu(rc->ies->wIELength) > 0) { - result = uwb_rc_set_ie(rc, rc->ies); - if (result < 0) { - dev_err(dev, "Cannot set new IE on device: " - "%d\n", result); - result = uwb_rc_stop_beacon(rc); - channel = -1; - bpst_offset = 0; - } - } - } - - if (result >= 0) - rc->beaconing = channel; - return result; -} - -/* - * Beacon cache - * - * The purpose of this is to speed up the lookup of becon information - * when a new beacon arrives. The UWB Daemon uses it also to keep a - * tab of which devices are in radio distance and which not. When a - * device's beacon stays present for more than a certain amount of - * time, it is considered a new, usable device. When a beacon ceases - * to be received for a certain amount of time, it is considered that - * the device is gone. - * - * FIXME: use an allocator for the entries - * FIXME: use something faster for search than a list - */ - -void uwb_bce_kfree(struct kref *_bce) -{ - struct uwb_beca_e *bce = container_of(_bce, struct uwb_beca_e, refcnt); - - kfree(bce->be); - kfree(bce); -} - - -/* Find a beacon by dev addr in the cache */ -static -struct uwb_beca_e *__uwb_beca_find_bydev(struct uwb_rc *rc, - const struct uwb_dev_addr *dev_addr) -{ - struct uwb_beca_e *bce, *next; - list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) { - if (!memcmp(&bce->dev_addr, dev_addr, sizeof(bce->dev_addr))) - goto out; - } - bce = NULL; -out: - return bce; -} - -/* Find a beacon by dev addr in the cache */ -static -struct uwb_beca_e *__uwb_beca_find_bymac(struct uwb_rc *rc, - const struct uwb_mac_addr *mac_addr) -{ - struct uwb_beca_e *bce, *next; - list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) { - if (!memcmp(bce->mac_addr, mac_addr->data, - sizeof(struct uwb_mac_addr))) - goto out; - } - bce = NULL; -out: - return bce; -} - -/** - * uwb_dev_get_by_devaddr - get a UWB device with a specific DevAddr - * @rc: the radio controller that saw the device - * @devaddr: DevAddr of the UWB device to find - * - * There may be more than one matching device (in the case of a - * DevAddr conflict), but only the first one is returned. - */ -struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc, - const struct uwb_dev_addr *devaddr) -{ - struct uwb_dev *found = NULL; - struct uwb_beca_e *bce; - - mutex_lock(&rc->uwb_beca.mutex); - bce = __uwb_beca_find_bydev(rc, devaddr); - if (bce) - found = uwb_dev_try_get(rc, bce->uwb_dev); - mutex_unlock(&rc->uwb_beca.mutex); - - return found; -} - -/** - * uwb_dev_get_by_macaddr - get a UWB device with a specific EUI-48 - * @rc: the radio controller that saw the device - * @devaddr: EUI-48 of the UWB device to find - */ -struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc, - const struct uwb_mac_addr *macaddr) -{ - struct uwb_dev *found = NULL; - struct uwb_beca_e *bce; - - mutex_lock(&rc->uwb_beca.mutex); - bce = __uwb_beca_find_bymac(rc, macaddr); - if (bce) - found = uwb_dev_try_get(rc, bce->uwb_dev); - mutex_unlock(&rc->uwb_beca.mutex); - - return found; -} - -/* Initialize a beacon cache entry */ -static void uwb_beca_e_init(struct uwb_beca_e *bce) -{ - mutex_init(&bce->mutex); - kref_init(&bce->refcnt); - stats_init(&bce->lqe_stats); - stats_init(&bce->rssi_stats); -} - -/* - * Add a beacon to the cache - * - * @be: Beacon event information - * @bf: Beacon frame (part of b, really) - * @ts_jiffies: Timestamp (in jiffies) when the beacon was received - */ -static -struct uwb_beca_e *__uwb_beca_add(struct uwb_rc *rc, - struct uwb_rc_evt_beacon *be, - struct uwb_beacon_frame *bf, - unsigned long ts_jiffies) -{ - struct uwb_beca_e *bce; - - bce = kzalloc(sizeof(*bce), GFP_KERNEL); - if (bce == NULL) - return NULL; - uwb_beca_e_init(bce); - bce->ts_jiffies = ts_jiffies; - bce->uwb_dev = NULL; - list_add(&bce->node, &rc->uwb_beca.list); - return bce; -} - -/* - * Wipe out beacon entries that became stale - * - * Remove associated devicest too. - */ -void uwb_beca_purge(struct uwb_rc *rc) -{ - struct uwb_beca_e *bce, *next; - unsigned long expires; - - mutex_lock(&rc->uwb_beca.mutex); - list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) { - expires = bce->ts_jiffies + msecs_to_jiffies(beacon_timeout_ms); - if (time_after(jiffies, expires)) { - uwbd_dev_offair(bce); - } - } - mutex_unlock(&rc->uwb_beca.mutex); -} - -/* Clean up the whole beacon cache. Called on shutdown */ -void uwb_beca_release(struct uwb_rc *rc) -{ - struct uwb_beca_e *bce, *next; - - mutex_lock(&rc->uwb_beca.mutex); - list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) { - list_del(&bce->node); - uwb_bce_put(bce); - } - mutex_unlock(&rc->uwb_beca.mutex); -} - -static void uwb_beacon_print(struct uwb_rc *rc, struct uwb_rc_evt_beacon *be, - struct uwb_beacon_frame *bf) -{ - char macbuf[UWB_ADDR_STRSIZE]; - char devbuf[UWB_ADDR_STRSIZE]; - char dstbuf[UWB_ADDR_STRSIZE]; - - uwb_mac_addr_print(macbuf, sizeof(macbuf), &bf->Device_Identifier); - uwb_dev_addr_print(devbuf, sizeof(devbuf), &bf->hdr.SrcAddr); - uwb_dev_addr_print(dstbuf, sizeof(dstbuf), &bf->hdr.DestAddr); - dev_info(&rc->uwb_dev.dev, - "BEACON from %s to %s (ch%u offset %u slot %u MAC %s)\n", - devbuf, dstbuf, be->bChannelNumber, be->wBPSTOffset, - bf->Beacon_Slot_Number, macbuf); -} - -/* - * @bce: beacon cache entry, referenced - */ -ssize_t uwb_bce_print_IEs(struct uwb_dev *uwb_dev, struct uwb_beca_e *bce, - char *buf, size_t size) -{ - ssize_t result = 0; - struct uwb_rc_evt_beacon *be; - struct uwb_beacon_frame *bf; - int ies_len; - struct uwb_ie_hdr *ies; - - mutex_lock(&bce->mutex); - - be = bce->be; - if (be) { - bf = (struct uwb_beacon_frame *)bce->be->BeaconInfo; - ies_len = be->wBeaconInfoLength - sizeof(struct uwb_beacon_frame); - ies = (struct uwb_ie_hdr *)bf->IEData; - - result = uwb_ie_dump_hex(ies, ies_len, buf, size); - } - - mutex_unlock(&bce->mutex); - - return result; -} - -/* - * Verify that the beacon event, frame and IEs are ok - */ -static int uwb_verify_beacon(struct uwb_rc *rc, struct uwb_event *evt, - struct uwb_rc_evt_beacon *be) -{ - int result = -EINVAL; - struct uwb_beacon_frame *bf; - struct device *dev = &rc->uwb_dev.dev; - - /* Is there enough data to decode a beacon frame? */ - if (evt->notif.size < sizeof(*be) + sizeof(*bf)) { - dev_err(dev, "BEACON event: Not enough data to decode " - "(%zu vs %zu bytes needed)\n", evt->notif.size, - sizeof(*be) + sizeof(*bf)); - goto error; - } - /* FIXME: make sure beacon frame IEs are fine and that the whole thing - * is consistent */ - result = 0; -error: - return result; -} - -/* - * Handle UWB_RC_EVT_BEACON events - * - * We check the beacon cache to see how the received beacon fares. If - * is there already we refresh the timestamp. If not we create a new - * entry. - * - * According to the WHCI and WUSB specs, only one beacon frame is - * allowed per notification block, so we don't bother about scanning - * for more. - */ -int uwbd_evt_handle_rc_beacon(struct uwb_event *evt) -{ - int result = -EINVAL; - struct uwb_rc *rc; - struct uwb_rc_evt_beacon *be; - struct uwb_beacon_frame *bf; - struct uwb_beca_e *bce; - - rc = evt->rc; - be = container_of(evt->notif.rceb, struct uwb_rc_evt_beacon, rceb); - result = uwb_verify_beacon(rc, evt, be); - if (result < 0) - return result; - - /* FIXME: handle alien beacons. */ - if (be->bBeaconType == UWB_RC_BEACON_TYPE_OL_ALIEN || - be->bBeaconType == UWB_RC_BEACON_TYPE_NOL_ALIEN) { - return -ENOSYS; - } - - bf = (struct uwb_beacon_frame *) be->BeaconInfo; - - /* - * Drop beacons from devices with a NULL EUI-48 -- they cannot - * be uniquely identified. - * - * It's expected that these will all be WUSB devices and they - * have a WUSB specific connection method so ignoring them - * here shouldn't be a problem. - */ - if (uwb_mac_addr_bcast(&bf->Device_Identifier)) - return 0; - - mutex_lock(&rc->uwb_beca.mutex); - bce = __uwb_beca_find_bymac(rc, &bf->Device_Identifier); - if (bce == NULL) { - /* Not in there, a new device is pinging */ - uwb_beacon_print(evt->rc, be, bf); - bce = __uwb_beca_add(rc, be, bf, evt->ts_jiffies); - if (bce == NULL) { - mutex_unlock(&rc->uwb_beca.mutex); - return -ENOMEM; - } - } - mutex_unlock(&rc->uwb_beca.mutex); - - mutex_lock(&bce->mutex); - /* purge old beacon data */ - kfree(bce->be); - - /* Update commonly used fields */ - bce->ts_jiffies = evt->ts_jiffies; - bce->be = be; - bce->dev_addr = bf->hdr.SrcAddr; - bce->mac_addr = &bf->Device_Identifier; - be->wBPSTOffset = le16_to_cpu(be->wBPSTOffset); - be->wBeaconInfoLength = le16_to_cpu(be->wBeaconInfoLength); - stats_add_sample(&bce->lqe_stats, be->bLQI - 7); - stats_add_sample(&bce->rssi_stats, be->bRSSI + 18); - - /* - * This might be a beacon from a new device. - */ - if (bce->uwb_dev == NULL) - uwbd_dev_onair(evt->rc, bce); - - mutex_unlock(&bce->mutex); - - return 1; /* we keep the event data */ -} - -/* - * Handle UWB_RC_EVT_BEACON_SIZE events - * - * XXXXX - */ -int uwbd_evt_handle_rc_beacon_size(struct uwb_event *evt) -{ - int result = -EINVAL; - struct device *dev = &evt->rc->uwb_dev.dev; - struct uwb_rc_evt_beacon_size *bs; - - /* Is there enough data to decode the event? */ - if (evt->notif.size < sizeof(*bs)) { - dev_err(dev, "BEACON SIZE notification: Not enough data to " - "decode (%zu vs %zu bytes needed)\n", - evt->notif.size, sizeof(*bs)); - goto error; - } - bs = container_of(evt->notif.rceb, struct uwb_rc_evt_beacon_size, rceb); - if (0) - dev_info(dev, "Beacon size changed to %u bytes " - "(FIXME: action?)\n", le16_to_cpu(bs->wNewBeaconSize)); - else { - /* temporary hack until we do something with this message... */ - static unsigned count; - if (++count % 1000 == 0) - dev_info(dev, "Beacon size changed %u times " - "(FIXME: action?)\n", count); - } - result = 0; -error: - return result; -} - -/** - * uwbd_evt_handle_rc_bp_slot_change - handle a BP_SLOT_CHANGE event - * @evt: the BP_SLOT_CHANGE notification from the radio controller - * - * If the event indicates that no beacon period slots were available - * then radio controller has transitioned to a non-beaconing state. - * Otherwise, simply save the current beacon slot. - */ -int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *evt) -{ - struct uwb_rc *rc = evt->rc; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_evt_bp_slot_change *bpsc; - - if (evt->notif.size < sizeof(*bpsc)) { - dev_err(dev, "BP SLOT CHANGE event: Not enough data\n"); - return -EINVAL; - } - bpsc = container_of(evt->notif.rceb, struct uwb_rc_evt_bp_slot_change, rceb); - - if (uwb_rc_evt_bp_slot_change_no_slot(bpsc)) { - dev_err(dev, "stopped beaconing: No free slots in BP\n"); - mutex_lock(&rc->uwb_dev.mutex); - rc->beaconing = -1; - mutex_unlock(&rc->uwb_dev.mutex); - } else - rc->uwb_dev.beacon_slot = uwb_rc_evt_bp_slot_change_slot_num(bpsc); - - return 0; -} - -/** - * Handle UWB_RC_EVT_BPOIE_CHANGE events - * - * XXXXX - */ -struct uwb_ie_bpo { - struct uwb_ie_hdr hdr; - u8 bp_length; - u8 data[]; -} __attribute__((packed)); - -int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *evt) -{ - int result = -EINVAL; - struct device *dev = &evt->rc->uwb_dev.dev; - struct uwb_rc_evt_bpoie_change *bpoiec; - struct uwb_ie_bpo *bpoie; - static unsigned count; /* FIXME: this is a temp hack */ - size_t iesize; - - /* Is there enough data to decode it? */ - if (evt->notif.size < sizeof(*bpoiec)) { - dev_err(dev, "BPOIEC notification: Not enough data to " - "decode (%zu vs %zu bytes needed)\n", - evt->notif.size, sizeof(*bpoiec)); - goto error; - } - bpoiec = container_of(evt->notif.rceb, struct uwb_rc_evt_bpoie_change, rceb); - iesize = le16_to_cpu(bpoiec->wBPOIELength); - if (iesize < sizeof(*bpoie)) { - dev_err(dev, "BPOIEC notification: Not enough IE data to " - "decode (%zu vs %zu bytes needed)\n", - iesize, sizeof(*bpoie)); - goto error; - } - if (++count % 1000 == 0) /* Lame placeholder */ - dev_info(dev, "BPOIE: %u changes received\n", count); - /* - * FIXME: At this point we should go over all the IEs in the - * bpoiec->BPOIE array and act on each. - */ - result = 0; -error: - return result; -} - -/* - * Print beaconing state. - */ -static ssize_t uwb_rc_beacon_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - ssize_t result; - - mutex_lock(&rc->uwb_dev.mutex); - result = sprintf(buf, "%d\n", rc->beaconing); - mutex_unlock(&rc->uwb_dev.mutex); - return result; -} - -/* - * Start beaconing on the specified channel, or stop beaconing. - */ -static ssize_t uwb_rc_beacon_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - int channel; - ssize_t result = -EINVAL; - - result = sscanf(buf, "%d", &channel); - if (result >= 1) - result = uwb_radio_force_channel(rc, channel); - - return result < 0 ? result : size; -} -DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, uwb_rc_beacon_show, uwb_rc_beacon_store); diff --git a/drivers/staging/uwb/driver.c b/drivers/staging/uwb/driver.c deleted file mode 100644 index 5755c2e49ffc..000000000000 --- a/drivers/staging/uwb/driver.c +++ /dev/null @@ -1,143 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Driver initialization, etc - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * - * Life cycle: FIXME: explain - * - * UWB radio controller: - * - * 1. alloc a uwb_rc, zero it - * 2. call uwb_rc_init() on it to set it up + ops (won't do any - * kind of allocation) - * 3. register (now it is owned by the UWB stack--deregister before - * freeing/destroying). - * 4. It lives on it's own now (UWB stack handles)--when it - * disconnects, call unregister() - * 5. free it. - * - * Make sure you have a reference to the uwb_rc before calling - * any of the UWB API functions. - * - * TODO: - * - * 1. Locking and life cycle management is crappy still. All entry - * points to the UWB HCD API assume you have a reference on the - * uwb_rc structure and that it won't go away. They mutex lock it - * before doing anything. - */ - -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/device.h> -#include <linux/err.h> -#include <linux/kdev_t.h> -#include <linux/random.h> - -#include "uwb-internal.h" - - -/* UWB stack attributes (or 'global' constants) */ - - -/** - * If a beacon disappears for longer than this, then we consider the - * device who was represented by that beacon to be gone. - * - * ECMA-368[17.2.3, last para] establishes that a device must not - * consider a device to be its neighbour if he doesn't receive a beacon - * for more than mMaxLostBeacons. mMaxLostBeacons is defined in - * ECMA-368[17.16] as 3; because we can get only one beacon per - * superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time - * for jitter and stuff and make it 500 ms. - */ -unsigned long beacon_timeout_ms = 500; - -static -ssize_t beacon_timeout_ms_show(struct class *class, - struct class_attribute *attr, - char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms); -} - -static -ssize_t beacon_timeout_ms_store(struct class *class, - struct class_attribute *attr, - const char *buf, size_t size) -{ - unsigned long bt; - ssize_t result; - result = sscanf(buf, "%lu", &bt); - if (result != 1) - return -EINVAL; - beacon_timeout_ms = bt; - return size; -} -static CLASS_ATTR_RW(beacon_timeout_ms); - -static struct attribute *uwb_class_attrs[] = { - &class_attr_beacon_timeout_ms.attr, - NULL, -}; -ATTRIBUTE_GROUPS(uwb_class); - -/** Device model classes */ -struct class uwb_rc_class = { - .name = "uwb_rc", - .class_groups = uwb_class_groups, -}; - - -static int __init uwb_subsys_init(void) -{ - int result = 0; - - result = uwb_est_create(); - if (result < 0) { - printk(KERN_ERR "uwb: Can't initialize EST subsystem\n"); - goto error_est_init; - } - - result = class_register(&uwb_rc_class); - if (result < 0) - goto error_uwb_rc_class_register; - - /* Register the UWB bus */ - result = bus_register(&uwb_bus_type); - if (result) { - pr_err("%s - registering bus driver failed\n", __func__); - goto exit_bus; - } - - uwb_dbg_init(); - return 0; - -exit_bus: - class_unregister(&uwb_rc_class); -error_uwb_rc_class_register: - uwb_est_destroy(); -error_est_init: - return result; -} -module_init(uwb_subsys_init); - -static void __exit uwb_subsys_exit(void) -{ - uwb_dbg_exit(); - bus_unregister(&uwb_bus_type); - class_unregister(&uwb_rc_class); - uwb_est_destroy(); - return; -} -module_exit(uwb_subsys_exit); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Ultra Wide Band core"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/uwb/drp-avail.c b/drivers/staging/uwb/drp-avail.c deleted file mode 100644 index 02392ab82a7d..000000000000 --- a/drivers/staging/uwb/drp-avail.c +++ /dev/null @@ -1,278 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * DRP availability management - * - * Copyright (C) 2005-2006 Intel Corporation - * Reinette Chatre <reinette.chatre@intel.com> - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - * - * Manage DRP Availability (the MAS available for DRP - * reservations). Thus: - * - * - Handle DRP Availability Change notifications - * - * - Allow the reservation manager to indicate MAS reserved/released - * by local (owned by/targeted at the radio controller) - * reservations. - * - * - Based on the two sources above, generate a DRP Availability IE to - * be included in the beacon. - * - * See also the documentation for struct uwb_drp_avail. - */ - -#include <linux/errno.h> -#include <linux/module.h> -#include <linux/device.h> -#include <linux/bitmap.h> -#include "uwb-internal.h" - -/** - * uwb_drp_avail_init - initialize an RC's MAS availability - * - * All MAS are available initially. The RC will inform use which - * slots are used for the BP (it may change in size). - */ -void uwb_drp_avail_init(struct uwb_rc *rc) -{ - bitmap_fill(rc->drp_avail.global, UWB_NUM_MAS); - bitmap_fill(rc->drp_avail.local, UWB_NUM_MAS); - bitmap_fill(rc->drp_avail.pending, UWB_NUM_MAS); -} - -/* - * Determine MAS available for new local reservations. - * - * avail = global & local & pending - */ -void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail) -{ - bitmap_and(avail->bm, rc->drp_avail.global, rc->drp_avail.local, UWB_NUM_MAS); - bitmap_and(avail->bm, avail->bm, rc->drp_avail.pending, UWB_NUM_MAS); -} - -/** - * uwb_drp_avail_reserve_pending - reserve MAS for a new reservation - * @rc: the radio controller - * @mas: the MAS to reserve - * - * Returns 0 on success, or -EBUSY if the MAS requested aren't available. - */ -int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas) -{ - struct uwb_mas_bm avail; - - uwb_drp_available(rc, &avail); - if (!bitmap_subset(mas->bm, avail.bm, UWB_NUM_MAS)) - return -EBUSY; - - bitmap_andnot(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS); - return 0; -} - -/** - * uwb_drp_avail_reserve - reserve MAS for an established reservation - * @rc: the radio controller - * @mas: the MAS to reserve - */ -void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas) -{ - bitmap_or(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS); - bitmap_andnot(rc->drp_avail.local, rc->drp_avail.local, mas->bm, UWB_NUM_MAS); - rc->drp_avail.ie_valid = false; -} - -/** - * uwb_drp_avail_release - release MAS from a pending or established reservation - * @rc: the radio controller - * @mas: the MAS to release - */ -void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas) -{ - bitmap_or(rc->drp_avail.local, rc->drp_avail.local, mas->bm, UWB_NUM_MAS); - bitmap_or(rc->drp_avail.pending, rc->drp_avail.pending, mas->bm, UWB_NUM_MAS); - rc->drp_avail.ie_valid = false; - uwb_rsv_handle_drp_avail_change(rc); -} - -/** - * uwb_drp_avail_ie_update - update the DRP Availability IE - * @rc: the radio controller - * - * avail = global & local - */ -void uwb_drp_avail_ie_update(struct uwb_rc *rc) -{ - struct uwb_mas_bm avail; - - bitmap_and(avail.bm, rc->drp_avail.global, rc->drp_avail.local, UWB_NUM_MAS); - - rc->drp_avail.ie.hdr.element_id = UWB_IE_DRP_AVAILABILITY; - rc->drp_avail.ie.hdr.length = UWB_NUM_MAS / 8; - uwb_mas_bm_copy_le(rc->drp_avail.ie.bmp, &avail); - rc->drp_avail.ie_valid = true; -} - -/** - * Create an unsigned long from a buffer containing a byte stream. - * - * @array: pointer to buffer - * @itr: index of buffer from where we start - * @len: the buffer's remaining size may not be exact multiple of - * sizeof(unsigned long), @len is the length of buffer that needs - * to be converted. This will be sizeof(unsigned long) or smaller - * (BUG if not). If it is smaller then we will pad the remaining - * space of the result with zeroes. - */ -static -unsigned long get_val(u8 *array, size_t itr, size_t len) -{ - unsigned long val = 0; - size_t top = itr + len; - - BUG_ON(len > sizeof(val)); - - while (itr < top) { - val <<= 8; - val |= array[top - 1]; - top--; - } - val <<= 8 * (sizeof(val) - len); /* padding */ - return val; -} - -/** - * Initialize bitmap from data buffer. - * - * The bitmap to be converted could come from a IE, for example a - * DRP Availability IE. - * From ECMA-368 1.0 [16.8.7]: " - * octets: 1 1 N * (0 to 32) - * Element ID Length (=N) DRP Availability Bitmap - * - * The DRP Availability Bitmap field is up to 256 bits long, one - * bit for each MAS in the superframe, where the least-significant - * bit of the field corresponds to the first MAS in the superframe - * and successive bits correspond to successive MASs." - * - * The DRP Availability bitmap is in octets from 0 to 32, so octet - * 32 contains bits for MAS 1-8, etc. If the bitmap is smaller than 32 - * octets, the bits in octets not included at the end of the bitmap are - * treated as zero. In this case (when the bitmap is smaller than 32 - * octets) the MAS represented range from MAS 1 to MAS (size of bitmap) - * with the last octet still containing bits for MAS 1-8, etc. - * - * For example: - * F00F0102 03040506 0708090A 0B0C0D0E 0F010203 - * ^^^^ - * |||| - * |||| - * |||\LSB of byte is MAS 9 - * ||\MSB of byte is MAS 16 - * |\LSB of first byte is MAS 1 - * \ MSB of byte is MAS 8 - * - * An example of this encoding can be found in ECMA-368 Annex-D [Table D.11] - * - * The resulting bitmap will have the following mapping: - * bit position 0 == MAS 1 - * bit position 1 == MAS 2 - * ... - * bit position (UWB_NUM_MAS - 1) == MAS UWB_NUM_MAS - * - * @bmp_itr: pointer to bitmap (can be declared with DECLARE_BITMAP) - * @buffer: pointer to buffer containing bitmap data in big endian - * format (MSB first) - * @buffer_size:number of bytes with which bitmap should be initialized - */ -static -void buffer_to_bmp(unsigned long *bmp_itr, void *_buffer, - size_t buffer_size) -{ - u8 *buffer = _buffer; - size_t itr, len; - unsigned long val; - - itr = 0; - while (itr < buffer_size) { - len = buffer_size - itr >= sizeof(val) ? - sizeof(val) : buffer_size - itr; - val = get_val(buffer, itr, len); - bmp_itr[itr / sizeof(val)] = val; - itr += sizeof(val); - } -} - - -/** - * Extract DRP Availability bitmap from the notification. - * - * The notification that comes in contains a bitmap of (UWB_NUM_MAS / 8) bytes - * We convert that to our internal representation. - */ -static -int uwbd_evt_get_drp_avail(struct uwb_event *evt, unsigned long *bmp) -{ - struct device *dev = &evt->rc->uwb_dev.dev; - struct uwb_rc_evt_drp_avail *drp_evt; - int result = -EINVAL; - - /* Is there enough data to decode the event? */ - if (evt->notif.size < sizeof(*drp_evt)) { - dev_err(dev, "DRP Availability Change: Not enough " - "data to decode event [%zu bytes, %zu " - "needed]\n", evt->notif.size, sizeof(*drp_evt)); - goto error; - } - drp_evt = container_of(evt->notif.rceb, struct uwb_rc_evt_drp_avail, rceb); - buffer_to_bmp(bmp, drp_evt->bmp, UWB_NUM_MAS/8); - result = 0; -error: - return result; -} - - -/** - * Process an incoming DRP Availability notification. - * - * @evt: Event information (packs the actual event data, which - * radio controller it came to, etc). - * - * @returns: 0 on success (so uwbd() frees the event buffer), < 0 - * on error. - * - * According to ECMA-368 1.0 [16.8.7], bits set to ONE indicate that - * the MAS slot is available, bits set to ZERO indicate that the slot - * is busy. - * - * So we clear available slots, we set used slots :) - * - * The notification only marks non-availability based on the BP and - * received DRP IEs that are not for this radio controller. A copy of - * this bitmap is needed to generate the real availability (which - * includes local and pending reservations). - * - * The DRP Availability IE that this radio controller emits will need - * to be updated. - */ -int uwbd_evt_handle_rc_drp_avail(struct uwb_event *evt) -{ - int result; - struct uwb_rc *rc = evt->rc; - DECLARE_BITMAP(bmp, UWB_NUM_MAS); - - result = uwbd_evt_get_drp_avail(evt, bmp); - if (result < 0) - return result; - - mutex_lock(&rc->rsvs_mutex); - bitmap_copy(rc->drp_avail.global, bmp, UWB_NUM_MAS); - rc->drp_avail.ie_valid = false; - uwb_rsv_handle_drp_avail_change(rc); - mutex_unlock(&rc->rsvs_mutex); - - uwb_rsv_sched_update(rc); - - return 0; -} diff --git a/drivers/staging/uwb/drp-ie.c b/drivers/staging/uwb/drp-ie.c deleted file mode 100644 index b2a862cf76de..000000000000 --- a/drivers/staging/uwb/drp-ie.c +++ /dev/null @@ -1,305 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB DRP IE management. - * - * Copyright (C) 2005-2006 Intel Corporation - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/random.h> -#include <linux/slab.h> - -#include "uwb.h" -#include "uwb-internal.h" - - -/* - * Return the reason code for a reservations's DRP IE. - */ -static int uwb_rsv_reason_code(struct uwb_rsv *rsv) -{ - static const int reason_codes[] = { - [UWB_RSV_STATE_O_INITIATED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_O_PENDING] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_O_MODIFIED] = UWB_DRP_REASON_MODIFIED, - [UWB_RSV_STATE_O_ESTABLISHED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_O_TO_BE_MOVED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_O_MOVE_COMBINING] = UWB_DRP_REASON_MODIFIED, - [UWB_RSV_STATE_O_MOVE_REDUCING] = UWB_DRP_REASON_MODIFIED, - [UWB_RSV_STATE_O_MOVE_EXPANDING] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_ACCEPTED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_CONFLICT] = UWB_DRP_REASON_CONFLICT, - [UWB_RSV_STATE_T_PENDING] = UWB_DRP_REASON_PENDING, - [UWB_RSV_STATE_T_DENIED] = UWB_DRP_REASON_DENIED, - [UWB_RSV_STATE_T_RESIZED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = UWB_DRP_REASON_CONFLICT, - [UWB_RSV_STATE_T_EXPANDING_PENDING] = UWB_DRP_REASON_PENDING, - [UWB_RSV_STATE_T_EXPANDING_DENIED] = UWB_DRP_REASON_DENIED, - }; - - return reason_codes[rsv->state]; -} - -/* - * Return the reason code for a reservations's companion DRP IE . - */ -static int uwb_rsv_companion_reason_code(struct uwb_rsv *rsv) -{ - static const int companion_reason_codes[] = { - [UWB_RSV_STATE_O_MOVE_EXPANDING] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = UWB_DRP_REASON_ACCEPTED, - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = UWB_DRP_REASON_CONFLICT, - [UWB_RSV_STATE_T_EXPANDING_PENDING] = UWB_DRP_REASON_PENDING, - [UWB_RSV_STATE_T_EXPANDING_DENIED] = UWB_DRP_REASON_DENIED, - }; - - return companion_reason_codes[rsv->state]; -} - -/* - * Return the status bit for a reservations's DRP IE. - */ -int uwb_rsv_status(struct uwb_rsv *rsv) -{ - static const int statuses[] = { - [UWB_RSV_STATE_O_INITIATED] = 0, - [UWB_RSV_STATE_O_PENDING] = 0, - [UWB_RSV_STATE_O_MODIFIED] = 1, - [UWB_RSV_STATE_O_ESTABLISHED] = 1, - [UWB_RSV_STATE_O_TO_BE_MOVED] = 0, - [UWB_RSV_STATE_O_MOVE_COMBINING] = 1, - [UWB_RSV_STATE_O_MOVE_REDUCING] = 1, - [UWB_RSV_STATE_O_MOVE_EXPANDING] = 1, - [UWB_RSV_STATE_T_ACCEPTED] = 1, - [UWB_RSV_STATE_T_CONFLICT] = 0, - [UWB_RSV_STATE_T_PENDING] = 0, - [UWB_RSV_STATE_T_DENIED] = 0, - [UWB_RSV_STATE_T_RESIZED] = 1, - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = 1, - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = 1, - [UWB_RSV_STATE_T_EXPANDING_PENDING] = 1, - [UWB_RSV_STATE_T_EXPANDING_DENIED] = 1, - - }; - - return statuses[rsv->state]; -} - -/* - * Return the status bit for a reservations's companion DRP IE . - */ -int uwb_rsv_companion_status(struct uwb_rsv *rsv) -{ - static const int companion_statuses[] = { - [UWB_RSV_STATE_O_MOVE_EXPANDING] = 0, - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = 1, - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = 0, - [UWB_RSV_STATE_T_EXPANDING_PENDING] = 0, - [UWB_RSV_STATE_T_EXPANDING_DENIED] = 0, - }; - - return companion_statuses[rsv->state]; -} - -/* - * Allocate a DRP IE. - * - * To save having to free/allocate a DRP IE when its MAS changes, - * enough memory is allocated for the maxiumum number of DRP - * allocation fields. This gives an overhead per reservation of up to - * (UWB_NUM_ZONES - 1) * 4 = 60 octets. - */ -static struct uwb_ie_drp *uwb_drp_ie_alloc(void) -{ - struct uwb_ie_drp *drp_ie; - - drp_ie = kzalloc(struct_size(drp_ie, allocs, UWB_NUM_ZONES), - GFP_KERNEL); - if (drp_ie) - drp_ie->hdr.element_id = UWB_IE_DRP; - return drp_ie; -} - - -/* - * Fill a DRP IE's allocation fields from a MAS bitmap. - */ -static void uwb_drp_ie_from_bm(struct uwb_ie_drp *drp_ie, - struct uwb_mas_bm *mas) -{ - int z, i, num_fields = 0, next = 0; - struct uwb_drp_alloc *zones; - __le16 current_bmp; - DECLARE_BITMAP(tmp_bmp, UWB_NUM_MAS); - DECLARE_BITMAP(tmp_mas_bm, UWB_MAS_PER_ZONE); - - zones = drp_ie->allocs; - - bitmap_copy(tmp_bmp, mas->bm, UWB_NUM_MAS); - - /* Determine unique MAS bitmaps in zones from bitmap. */ - for (z = 0; z < UWB_NUM_ZONES; z++) { - bitmap_copy(tmp_mas_bm, tmp_bmp, UWB_MAS_PER_ZONE); - if (bitmap_weight(tmp_mas_bm, UWB_MAS_PER_ZONE) > 0) { - bool found = false; - current_bmp = (__le16) *tmp_mas_bm; - for (i = 0; i < next; i++) { - if (current_bmp == zones[i].mas_bm) { - zones[i].zone_bm |= 1 << z; - found = true; - break; - } - } - if (!found) { - num_fields++; - zones[next].zone_bm = 1 << z; - zones[next].mas_bm = current_bmp; - next++; - } - } - bitmap_shift_right(tmp_bmp, tmp_bmp, UWB_MAS_PER_ZONE, UWB_NUM_MAS); - } - - /* Store in format ready for transmission (le16). */ - for (i = 0; i < num_fields; i++) { - drp_ie->allocs[i].zone_bm = cpu_to_le16(zones[i].zone_bm); - drp_ie->allocs[i].mas_bm = cpu_to_le16(zones[i].mas_bm); - } - - drp_ie->hdr.length = sizeof(struct uwb_ie_drp) - sizeof(struct uwb_ie_hdr) - + num_fields * sizeof(struct uwb_drp_alloc); -} - -/** - * uwb_drp_ie_update - update a reservation's DRP IE - * @rsv: the reservation - */ -int uwb_drp_ie_update(struct uwb_rsv *rsv) -{ - struct uwb_ie_drp *drp_ie; - struct uwb_rsv_move *mv; - int unsafe; - - if (rsv->state == UWB_RSV_STATE_NONE) { - kfree(rsv->drp_ie); - rsv->drp_ie = NULL; - return 0; - } - - unsafe = rsv->mas.unsafe ? 1 : 0; - - if (rsv->drp_ie == NULL) { - rsv->drp_ie = uwb_drp_ie_alloc(); - if (rsv->drp_ie == NULL) - return -ENOMEM; - } - drp_ie = rsv->drp_ie; - - uwb_ie_drp_set_unsafe(drp_ie, unsafe); - uwb_ie_drp_set_tiebreaker(drp_ie, rsv->tiebreaker); - uwb_ie_drp_set_owner(drp_ie, uwb_rsv_is_owner(rsv)); - uwb_ie_drp_set_status(drp_ie, uwb_rsv_status(rsv)); - uwb_ie_drp_set_reason_code(drp_ie, uwb_rsv_reason_code(rsv)); - uwb_ie_drp_set_stream_index(drp_ie, rsv->stream); - uwb_ie_drp_set_type(drp_ie, rsv->type); - - if (uwb_rsv_is_owner(rsv)) { - switch (rsv->target.type) { - case UWB_RSV_TARGET_DEV: - drp_ie->dev_addr = rsv->target.dev->dev_addr; - break; - case UWB_RSV_TARGET_DEVADDR: - drp_ie->dev_addr = rsv->target.devaddr; - break; - } - } else - drp_ie->dev_addr = rsv->owner->dev_addr; - - uwb_drp_ie_from_bm(drp_ie, &rsv->mas); - - if (uwb_rsv_has_two_drp_ies(rsv)) { - mv = &rsv->mv; - if (mv->companion_drp_ie == NULL) { - mv->companion_drp_ie = uwb_drp_ie_alloc(); - if (mv->companion_drp_ie == NULL) - return -ENOMEM; - } - drp_ie = mv->companion_drp_ie; - - /* keep all the same configuration of the main drp_ie */ - memcpy(drp_ie, rsv->drp_ie, sizeof(struct uwb_ie_drp)); - - - /* FIXME: handle properly the unsafe bit */ - uwb_ie_drp_set_unsafe(drp_ie, 1); - uwb_ie_drp_set_status(drp_ie, uwb_rsv_companion_status(rsv)); - uwb_ie_drp_set_reason_code(drp_ie, uwb_rsv_companion_reason_code(rsv)); - - uwb_drp_ie_from_bm(drp_ie, &mv->companion_mas); - } - - rsv->ie_valid = true; - return 0; -} - -/* - * Set MAS bits from given MAS bitmap in a single zone of large bitmap. - * - * We are given a zone id and the MAS bitmap of bits that need to be set in - * this zone. Note that this zone may already have bits set and this only - * adds settings - we cannot simply assign the MAS bitmap contents to the - * zone contents. We iterate over the the bits (MAS) in the zone and set the - * bits that are set in the given MAS bitmap. - */ -static -void uwb_drp_ie_single_zone_to_bm(struct uwb_mas_bm *bm, u8 zone, u16 mas_bm) -{ - int mas; - u16 mas_mask; - - for (mas = 0; mas < UWB_MAS_PER_ZONE; mas++) { - mas_mask = 1 << mas; - if (mas_bm & mas_mask) - set_bit(zone * UWB_NUM_ZONES + mas, bm->bm); - } -} - -/** - * uwb_drp_ie_zones_to_bm - convert DRP allocation fields to a bitmap - * @mas: MAS bitmap that will be populated to correspond to the - * allocation fields in the DRP IE - * @drp_ie: the DRP IE that contains the allocation fields. - * - * The input format is an array of MAS allocation fields (16 bit Zone - * bitmap, 16 bit MAS bitmap) as described in [ECMA-368] section - * 16.8.6. The output is a full 256 bit MAS bitmap. - * - * We go over all the allocation fields, for each allocation field we - * know which zones are impacted. We iterate over all the zones - * impacted and call a function that will set the correct MAS bits in - * each zone. - */ -void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie) -{ - int numallocs = (drp_ie->hdr.length - 4) / 4; - const struct uwb_drp_alloc *alloc; - int cnt; - u16 zone_bm, mas_bm; - u8 zone; - u16 zone_mask; - - bitmap_zero(bm->bm, UWB_NUM_MAS); - - for (cnt = 0; cnt < numallocs; cnt++) { - alloc = &drp_ie->allocs[cnt]; - zone_bm = le16_to_cpu(alloc->zone_bm); - mas_bm = le16_to_cpu(alloc->mas_bm); - for (zone = 0; zone < UWB_NUM_ZONES; zone++) { - zone_mask = 1 << zone; - if (zone_bm & zone_mask) - uwb_drp_ie_single_zone_to_bm(bm, zone, mas_bm); - } - } -} - diff --git a/drivers/staging/uwb/drp.c b/drivers/staging/uwb/drp.c deleted file mode 100644 index 869987bede7b..000000000000 --- a/drivers/staging/uwb/drp.c +++ /dev/null @@ -1,842 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Dynamic Reservation Protocol handling - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kthread.h> -#include <linux/freezer.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include "uwb-internal.h" - - -/* DRP Conflict Actions ([ECMA-368 2nd Edition] 17.4.6) */ -enum uwb_drp_conflict_action { - /* Reservation is maintained, no action needed */ - UWB_DRP_CONFLICT_MANTAIN = 0, - - /* the device shall not transmit frames in conflicting MASs in - * the following superframe. If the device is the reservation - * target, it shall also set the Reason Code in its DRP IE to - * Conflict in its beacon in the following superframe. - */ - UWB_DRP_CONFLICT_ACT1, - - /* the device shall not set the Reservation Status bit to ONE - * and shall not transmit frames in conflicting MASs. If the - * device is the reservation target, it shall also set the - * Reason Code in its DRP IE to Conflict. - */ - UWB_DRP_CONFLICT_ACT2, - - /* the device shall not transmit frames in conflicting MASs in - * the following superframe. It shall remove the conflicting - * MASs from the reservation or set the Reservation Status to - * ZERO in its beacon in the following superframe. If the - * device is the reservation target, it shall also set the - * Reason Code in its DRP IE to Conflict. - */ - UWB_DRP_CONFLICT_ACT3, -}; - - -static void uwb_rc_set_drp_cmd_done(struct uwb_rc *rc, void *arg, - struct uwb_rceb *reply, ssize_t reply_size) -{ - struct uwb_rc_evt_set_drp_ie *r = (struct uwb_rc_evt_set_drp_ie *)reply; - unsigned long flags; - - if (r != NULL) { - if (r->bResultCode != UWB_RC_RES_SUCCESS) - dev_err(&rc->uwb_dev.dev, "SET-DRP-IE failed: %s (%d)\n", - uwb_rc_strerror(r->bResultCode), r->bResultCode); - } else - dev_err(&rc->uwb_dev.dev, "SET-DRP-IE: timeout\n"); - - spin_lock_irqsave(&rc->rsvs_lock, flags); - if (rc->set_drp_ie_pending > 1) { - rc->set_drp_ie_pending = 0; - uwb_rsv_queue_update(rc); - } else { - rc->set_drp_ie_pending = 0; - } - spin_unlock_irqrestore(&rc->rsvs_lock, flags); -} - -/** - * Construct and send the SET DRP IE - * - * @rc: UWB Host controller - * @returns: >= 0 number of bytes still available in the beacon - * < 0 errno code on error. - * - * See WUSB[8.6.2.7]: The host must set all the DRP IEs that it wants the - * device to include in its beacon at the same time. We thus have to - * traverse all reservations and include the DRP IEs of all PENDING - * and NEGOTIATED reservations in a SET DRP command for transmission. - * - * A DRP Availability IE is appended. - * - * rc->rsvs_mutex is held - * - * FIXME We currently ignore the returned value indicating the remaining space - * in beacon. This could be used to deny reservation requests earlier if - * determined that they would cause the beacon space to be exceeded. - */ -int uwb_rc_send_all_drp_ie(struct uwb_rc *rc) -{ - int result; - struct uwb_rc_cmd_set_drp_ie *cmd; - struct uwb_rsv *rsv; - struct uwb_rsv_move *mv; - int num_bytes = 0; - u8 *IEDataptr; - - result = -ENOMEM; - /* First traverse all reservations to determine memory needed. */ - list_for_each_entry(rsv, &rc->reservations, rc_node) { - if (rsv->drp_ie != NULL) { - num_bytes += rsv->drp_ie->hdr.length + 2; - if (uwb_rsv_has_two_drp_ies(rsv) && - (rsv->mv.companion_drp_ie != NULL)) { - mv = &rsv->mv; - num_bytes += - mv->companion_drp_ie->hdr.length + 2; - } - } - } - num_bytes += sizeof(rc->drp_avail.ie); - cmd = kzalloc(sizeof(*cmd) + num_bytes, GFP_KERNEL); - if (cmd == NULL) - goto error; - cmd->rccb.bCommandType = UWB_RC_CET_GENERAL; - cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SET_DRP_IE); - cmd->wIELength = num_bytes; - IEDataptr = (u8 *)&cmd->IEData[0]; - - /* FIXME: DRV avail IE is not always needed */ - /* put DRP avail IE first */ - memcpy(IEDataptr, &rc->drp_avail.ie, sizeof(rc->drp_avail.ie)); - IEDataptr += sizeof(struct uwb_ie_drp_avail); - - /* Next traverse all reservations to place IEs in allocated memory. */ - list_for_each_entry(rsv, &rc->reservations, rc_node) { - if (rsv->drp_ie != NULL) { - memcpy(IEDataptr, rsv->drp_ie, - rsv->drp_ie->hdr.length + 2); - IEDataptr += rsv->drp_ie->hdr.length + 2; - - if (uwb_rsv_has_two_drp_ies(rsv) && - (rsv->mv.companion_drp_ie != NULL)) { - mv = &rsv->mv; - memcpy(IEDataptr, mv->companion_drp_ie, - mv->companion_drp_ie->hdr.length + 2); - IEDataptr += - mv->companion_drp_ie->hdr.length + 2; - } - } - } - - result = uwb_rc_cmd_async(rc, "SET-DRP-IE", - &cmd->rccb, sizeof(*cmd) + num_bytes, - UWB_RC_CET_GENERAL, UWB_RC_CMD_SET_DRP_IE, - uwb_rc_set_drp_cmd_done, NULL); - - rc->set_drp_ie_pending = 1; - - kfree(cmd); -error: - return result; -} - -/* - * Evaluate the action to perform using conflict resolution rules - * - * Return a uwb_drp_conflict_action. - */ -static int evaluate_conflict_action(struct uwb_ie_drp *ext_drp_ie, int ext_beacon_slot, - struct uwb_rsv *rsv, int our_status) -{ - int our_tie_breaker = rsv->tiebreaker; - int our_type = rsv->type; - int our_beacon_slot = rsv->rc->uwb_dev.beacon_slot; - - int ext_tie_breaker = uwb_ie_drp_tiebreaker(ext_drp_ie); - int ext_status = uwb_ie_drp_status(ext_drp_ie); - int ext_type = uwb_ie_drp_type(ext_drp_ie); - - - /* [ECMA-368 2nd Edition] 17.4.6 */ - if (ext_type == UWB_DRP_TYPE_PCA && our_type == UWB_DRP_TYPE_PCA) { - return UWB_DRP_CONFLICT_MANTAIN; - } - - /* [ECMA-368 2nd Edition] 17.4.6-1 */ - if (our_type == UWB_DRP_TYPE_ALIEN_BP) { - return UWB_DRP_CONFLICT_MANTAIN; - } - - /* [ECMA-368 2nd Edition] 17.4.6-2 */ - if (ext_type == UWB_DRP_TYPE_ALIEN_BP) { - /* here we know our_type != UWB_DRP_TYPE_ALIEN_BP */ - return UWB_DRP_CONFLICT_ACT1; - } - - /* [ECMA-368 2nd Edition] 17.4.6-3 */ - if (our_status == 0 && ext_status == 1) { - return UWB_DRP_CONFLICT_ACT2; - } - - /* [ECMA-368 2nd Edition] 17.4.6-4 */ - if (our_status == 1 && ext_status == 0) { - return UWB_DRP_CONFLICT_MANTAIN; - } - - /* [ECMA-368 2nd Edition] 17.4.6-5a */ - if (our_tie_breaker == ext_tie_breaker && - our_beacon_slot < ext_beacon_slot) { - return UWB_DRP_CONFLICT_MANTAIN; - } - - /* [ECMA-368 2nd Edition] 17.4.6-5b */ - if (our_tie_breaker != ext_tie_breaker && - our_beacon_slot > ext_beacon_slot) { - return UWB_DRP_CONFLICT_MANTAIN; - } - - if (our_status == 0) { - if (our_tie_breaker == ext_tie_breaker) { - /* [ECMA-368 2nd Edition] 17.4.6-6a */ - if (our_beacon_slot > ext_beacon_slot) { - return UWB_DRP_CONFLICT_ACT2; - } - } else { - /* [ECMA-368 2nd Edition] 17.4.6-6b */ - if (our_beacon_slot < ext_beacon_slot) { - return UWB_DRP_CONFLICT_ACT2; - } - } - } else { - if (our_tie_breaker == ext_tie_breaker) { - /* [ECMA-368 2nd Edition] 17.4.6-7a */ - if (our_beacon_slot > ext_beacon_slot) { - return UWB_DRP_CONFLICT_ACT3; - } - } else { - /* [ECMA-368 2nd Edition] 17.4.6-7b */ - if (our_beacon_slot < ext_beacon_slot) { - return UWB_DRP_CONFLICT_ACT3; - } - } - } - return UWB_DRP_CONFLICT_MANTAIN; -} - -static void handle_conflict_normal(struct uwb_ie_drp *drp_ie, - int ext_beacon_slot, - struct uwb_rsv *rsv, - struct uwb_mas_bm *conflicting_mas) -{ - struct uwb_rc *rc = rsv->rc; - struct uwb_rsv_move *mv = &rsv->mv; - struct uwb_drp_backoff_win *bow = &rc->bow; - int action; - - action = evaluate_conflict_action(drp_ie, ext_beacon_slot, rsv, uwb_rsv_status(rsv)); - - if (uwb_rsv_is_owner(rsv)) { - switch(action) { - case UWB_DRP_CONFLICT_ACT2: - /* try move */ - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_TO_BE_MOVED); - if (bow->can_reserve_extra_mases == false) - uwb_rsv_backoff_win_increment(rc); - - break; - case UWB_DRP_CONFLICT_ACT3: - uwb_rsv_backoff_win_increment(rc); - /* drop some mases with reason modified */ - /* put in the companion the mases to be dropped */ - bitmap_and(mv->companion_mas.bm, rsv->mas.bm, conflicting_mas->bm, UWB_NUM_MAS); - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MODIFIED); - default: - break; - } - } else { - switch(action) { - case UWB_DRP_CONFLICT_ACT2: - case UWB_DRP_CONFLICT_ACT3: - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_CONFLICT); - default: - break; - } - - } - -} - -static void handle_conflict_expanding(struct uwb_ie_drp *drp_ie, int ext_beacon_slot, - struct uwb_rsv *rsv, bool companion_only, - struct uwb_mas_bm *conflicting_mas) -{ - struct uwb_rc *rc = rsv->rc; - struct uwb_drp_backoff_win *bow = &rc->bow; - struct uwb_rsv_move *mv = &rsv->mv; - int action; - - if (companion_only) { - /* status of companion is 0 at this point */ - action = evaluate_conflict_action(drp_ie, ext_beacon_slot, rsv, 0); - if (uwb_rsv_is_owner(rsv)) { - switch(action) { - case UWB_DRP_CONFLICT_ACT2: - case UWB_DRP_CONFLICT_ACT3: - uwb_rsv_set_state(rsv, - UWB_RSV_STATE_O_ESTABLISHED); - rsv->needs_release_companion_mas = false; - if (bow->can_reserve_extra_mases == false) - uwb_rsv_backoff_win_increment(rc); - uwb_drp_avail_release(rsv->rc, - &rsv->mv.companion_mas); - } - } else { /* rsv is target */ - switch(action) { - case UWB_DRP_CONFLICT_ACT2: - case UWB_DRP_CONFLICT_ACT3: - uwb_rsv_set_state(rsv, - UWB_RSV_STATE_T_EXPANDING_CONFLICT); - /* send_drp_avail_ie = true; */ - } - } - } else { /* also base part of the reservation is conflicting */ - if (uwb_rsv_is_owner(rsv)) { - uwb_rsv_backoff_win_increment(rc); - /* remove companion part */ - uwb_drp_avail_release(rsv->rc, &rsv->mv.companion_mas); - - /* drop some mases with reason modified */ - - /* put in the companion the mases to be dropped */ - bitmap_andnot(mv->companion_mas.bm, rsv->mas.bm, - conflicting_mas->bm, UWB_NUM_MAS); - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MODIFIED); - } else { /* it is a target rsv */ - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_CONFLICT); - /* send_drp_avail_ie = true; */ - } - } -} - -static void uwb_drp_handle_conflict_rsv(struct uwb_rc *rc, struct uwb_rsv *rsv, - struct uwb_rc_evt_drp *drp_evt, - struct uwb_ie_drp *drp_ie, - struct uwb_mas_bm *conflicting_mas) -{ - struct uwb_rsv_move *mv; - - /* check if the conflicting reservation has two drp_ies */ - if (uwb_rsv_has_two_drp_ies(rsv)) { - mv = &rsv->mv; - if (bitmap_intersects(rsv->mas.bm, conflicting_mas->bm, - UWB_NUM_MAS)) { - handle_conflict_expanding(drp_ie, - drp_evt->beacon_slot_number, - rsv, false, conflicting_mas); - } else { - if (bitmap_intersects(mv->companion_mas.bm, - conflicting_mas->bm, UWB_NUM_MAS)) { - handle_conflict_expanding( - drp_ie, drp_evt->beacon_slot_number, - rsv, true, conflicting_mas); - } - } - } else if (bitmap_intersects(rsv->mas.bm, conflicting_mas->bm, - UWB_NUM_MAS)) { - handle_conflict_normal(drp_ie, drp_evt->beacon_slot_number, - rsv, conflicting_mas); - } -} - -static void uwb_drp_handle_all_conflict_rsv(struct uwb_rc *rc, - struct uwb_rc_evt_drp *drp_evt, - struct uwb_ie_drp *drp_ie, - struct uwb_mas_bm *conflicting_mas) -{ - struct uwb_rsv *rsv; - - list_for_each_entry(rsv, &rc->reservations, rc_node) { - uwb_drp_handle_conflict_rsv(rc, rsv, drp_evt, drp_ie, - conflicting_mas); - } -} - -static void uwb_drp_process_target_accepted(struct uwb_rc *rc, - struct uwb_rsv *rsv, struct uwb_rc_evt_drp *drp_evt, - struct uwb_ie_drp *drp_ie, struct uwb_mas_bm *mas) -{ - struct uwb_rsv_move *mv = &rsv->mv; - int status; - - status = uwb_ie_drp_status(drp_ie); - - if (rsv->state == UWB_RSV_STATE_T_CONFLICT) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_CONFLICT); - return; - } - - if (rsv->state == UWB_RSV_STATE_T_EXPANDING_ACCEPTED) { - /* drp_ie is companion */ - if (!bitmap_equal(rsv->mas.bm, mas->bm, UWB_NUM_MAS)) { - /* stroke companion */ - uwb_rsv_set_state(rsv, - UWB_RSV_STATE_T_EXPANDING_ACCEPTED); - } - } else { - if (!bitmap_equal(rsv->mas.bm, mas->bm, UWB_NUM_MAS)) { - if (uwb_drp_avail_reserve_pending(rc, mas) == -EBUSY) { - /* FIXME: there is a conflict, find - * the conflicting reservations and - * take a sensible action. Consider - * that in drp_ie there is the - * "neighbour" */ - uwb_drp_handle_all_conflict_rsv(rc, drp_evt, - drp_ie, mas); - } else { - /* accept the extra reservation */ - bitmap_copy(mv->companion_mas.bm, mas->bm, - UWB_NUM_MAS); - uwb_rsv_set_state(rsv, - UWB_RSV_STATE_T_EXPANDING_ACCEPTED); - } - } else { - if (status) { - uwb_rsv_set_state(rsv, - UWB_RSV_STATE_T_ACCEPTED); - } - } - - } -} - -/* - * Based on the DRP IE, transition a target reservation to a new - * state. - */ -static void uwb_drp_process_target(struct uwb_rc *rc, struct uwb_rsv *rsv, - struct uwb_ie_drp *drp_ie, struct uwb_rc_evt_drp *drp_evt) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rsv_move *mv = &rsv->mv; - int status; - enum uwb_drp_reason reason_code; - struct uwb_mas_bm mas; - - status = uwb_ie_drp_status(drp_ie); - reason_code = uwb_ie_drp_reason_code(drp_ie); - uwb_drp_ie_to_bm(&mas, drp_ie); - - switch (reason_code) { - case UWB_DRP_REASON_ACCEPTED: - uwb_drp_process_target_accepted(rc, rsv, drp_evt, drp_ie, &mas); - break; - - case UWB_DRP_REASON_MODIFIED: - /* check to see if we have already modified the reservation */ - if (bitmap_equal(rsv->mas.bm, mas.bm, UWB_NUM_MAS)) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_ACCEPTED); - break; - } - - /* find if the owner wants to expand or reduce */ - if (bitmap_subset(mas.bm, rsv->mas.bm, UWB_NUM_MAS)) { - /* owner is reducing */ - bitmap_andnot(mv->companion_mas.bm, rsv->mas.bm, mas.bm, - UWB_NUM_MAS); - uwb_drp_avail_release(rsv->rc, &mv->companion_mas); - } - - bitmap_copy(rsv->mas.bm, mas.bm, UWB_NUM_MAS); - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_RESIZED); - break; - default: - dev_warn(dev, "ignoring invalid DRP IE state (%d/%d)\n", - reason_code, status); - } -} - -static void uwb_drp_process_owner_accepted(struct uwb_rsv *rsv, - struct uwb_mas_bm *mas) -{ - struct uwb_rsv_move *mv = &rsv->mv; - - switch (rsv->state) { - case UWB_RSV_STATE_O_PENDING: - case UWB_RSV_STATE_O_INITIATED: - case UWB_RSV_STATE_O_ESTABLISHED: - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_ESTABLISHED); - break; - case UWB_RSV_STATE_O_MODIFIED: - if (bitmap_equal(mas->bm, rsv->mas.bm, UWB_NUM_MAS)) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_ESTABLISHED); - else - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MODIFIED); - break; - - case UWB_RSV_STATE_O_MOVE_REDUCING: /* shouldn' t be a problem */ - if (bitmap_equal(mas->bm, rsv->mas.bm, UWB_NUM_MAS)) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_ESTABLISHED); - else - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_REDUCING); - break; - case UWB_RSV_STATE_O_MOVE_EXPANDING: - if (bitmap_equal(mas->bm, mv->companion_mas.bm, UWB_NUM_MAS)) { - /* Companion reservation accepted */ - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_COMBINING); - } else { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_EXPANDING); - } - break; - case UWB_RSV_STATE_O_MOVE_COMBINING: - if (bitmap_equal(mas->bm, rsv->mas.bm, UWB_NUM_MAS)) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_REDUCING); - else - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_COMBINING); - break; - default: - break; - } -} -/* - * Based on the DRP IE, transition an owner reservation to a new - * state. - */ -static void uwb_drp_process_owner(struct uwb_rc *rc, struct uwb_rsv *rsv, - struct uwb_dev *src, struct uwb_ie_drp *drp_ie, - struct uwb_rc_evt_drp *drp_evt) -{ - struct device *dev = &rc->uwb_dev.dev; - int status; - enum uwb_drp_reason reason_code; - struct uwb_mas_bm mas; - - status = uwb_ie_drp_status(drp_ie); - reason_code = uwb_ie_drp_reason_code(drp_ie); - uwb_drp_ie_to_bm(&mas, drp_ie); - - if (status) { - switch (reason_code) { - case UWB_DRP_REASON_ACCEPTED: - uwb_drp_process_owner_accepted(rsv, &mas); - break; - default: - dev_warn(dev, "ignoring invalid DRP IE state (%d/%d)\n", - reason_code, status); - } - } else { - switch (reason_code) { - case UWB_DRP_REASON_PENDING: - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_PENDING); - break; - case UWB_DRP_REASON_DENIED: - uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); - break; - case UWB_DRP_REASON_CONFLICT: - /* resolve the conflict */ - bitmap_complement(mas.bm, src->last_availability_bm, - UWB_NUM_MAS); - uwb_drp_handle_conflict_rsv(rc, rsv, drp_evt, drp_ie, &mas); - break; - default: - dev_warn(dev, "ignoring invalid DRP IE state (%d/%d)\n", - reason_code, status); - } - } -} - -static void uwb_cnflt_alien_stroke_timer(struct uwb_cnflt_alien *cnflt) -{ - unsigned timeout_us = UWB_MAX_LOST_BEACONS * UWB_SUPERFRAME_LENGTH_US; - mod_timer(&cnflt->timer, jiffies + usecs_to_jiffies(timeout_us)); -} - -static void uwb_cnflt_update_work(struct work_struct *work) -{ - struct uwb_cnflt_alien *cnflt = container_of(work, - struct uwb_cnflt_alien, - cnflt_update_work); - struct uwb_cnflt_alien *c; - struct uwb_rc *rc = cnflt->rc; - - unsigned long delay_us = UWB_MAS_LENGTH_US * UWB_MAS_PER_ZONE; - - mutex_lock(&rc->rsvs_mutex); - - list_del(&cnflt->rc_node); - - /* update rc global conflicting alien bitmap */ - bitmap_zero(rc->cnflt_alien_bitmap.bm, UWB_NUM_MAS); - - list_for_each_entry(c, &rc->cnflt_alien_list, rc_node) { - bitmap_or(rc->cnflt_alien_bitmap.bm, rc->cnflt_alien_bitmap.bm, - c->mas.bm, UWB_NUM_MAS); - } - - queue_delayed_work(rc->rsv_workq, &rc->rsv_alien_bp_work, - usecs_to_jiffies(delay_us)); - - kfree(cnflt); - mutex_unlock(&rc->rsvs_mutex); -} - -static void uwb_cnflt_timer(struct timer_list *t) -{ - struct uwb_cnflt_alien *cnflt = from_timer(cnflt, t, timer); - - queue_work(cnflt->rc->rsv_workq, &cnflt->cnflt_update_work); -} - -/* - * We have received an DRP_IE of type Alien BP and we need to make - * sure we do not transmit in conflicting MASs. - */ -static void uwb_drp_handle_alien_drp(struct uwb_rc *rc, struct uwb_ie_drp *drp_ie) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_mas_bm mas; - struct uwb_cnflt_alien *cnflt; - unsigned long delay_us = UWB_MAS_LENGTH_US * UWB_MAS_PER_ZONE; - - uwb_drp_ie_to_bm(&mas, drp_ie); - - list_for_each_entry(cnflt, &rc->cnflt_alien_list, rc_node) { - if (bitmap_equal(cnflt->mas.bm, mas.bm, UWB_NUM_MAS)) { - /* Existing alien BP reservation conflicting - * bitmap, just reset the timer */ - uwb_cnflt_alien_stroke_timer(cnflt); - return; - } - } - - /* New alien BP reservation conflicting bitmap */ - - /* alloc and initialize new uwb_cnflt_alien */ - cnflt = kzalloc(sizeof(struct uwb_cnflt_alien), GFP_KERNEL); - if (!cnflt) { - dev_err(dev, "failed to alloc uwb_cnflt_alien struct\n"); - return; - } - - INIT_LIST_HEAD(&cnflt->rc_node); - timer_setup(&cnflt->timer, uwb_cnflt_timer, 0); - - cnflt->rc = rc; - INIT_WORK(&cnflt->cnflt_update_work, uwb_cnflt_update_work); - - bitmap_copy(cnflt->mas.bm, mas.bm, UWB_NUM_MAS); - - list_add_tail(&cnflt->rc_node, &rc->cnflt_alien_list); - - /* update rc global conflicting alien bitmap */ - bitmap_or(rc->cnflt_alien_bitmap.bm, rc->cnflt_alien_bitmap.bm, mas.bm, UWB_NUM_MAS); - - queue_delayed_work(rc->rsv_workq, &rc->rsv_alien_bp_work, usecs_to_jiffies(delay_us)); - - /* start the timer */ - uwb_cnflt_alien_stroke_timer(cnflt); -} - -static void uwb_drp_process_not_involved(struct uwb_rc *rc, - struct uwb_rc_evt_drp *drp_evt, - struct uwb_ie_drp *drp_ie) -{ - struct uwb_mas_bm mas; - - uwb_drp_ie_to_bm(&mas, drp_ie); - uwb_drp_handle_all_conflict_rsv(rc, drp_evt, drp_ie, &mas); -} - -static void uwb_drp_process_involved(struct uwb_rc *rc, struct uwb_dev *src, - struct uwb_rc_evt_drp *drp_evt, - struct uwb_ie_drp *drp_ie) -{ - struct uwb_rsv *rsv; - - rsv = uwb_rsv_find(rc, src, drp_ie); - if (!rsv) { - /* - * No reservation? It's either for a recently - * terminated reservation; or the DRP IE couldn't be - * processed (e.g., an invalid IE or out of memory). - */ - return; - } - - /* - * Do nothing with DRP IEs for reservations that have been - * terminated. - */ - if (rsv->state == UWB_RSV_STATE_NONE) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); - return; - } - - if (uwb_ie_drp_owner(drp_ie)) - uwb_drp_process_target(rc, rsv, drp_ie, drp_evt); - else - uwb_drp_process_owner(rc, rsv, src, drp_ie, drp_evt); - -} - - -static bool uwb_drp_involves_us(struct uwb_rc *rc, struct uwb_ie_drp *drp_ie) -{ - return uwb_dev_addr_cmp(&rc->uwb_dev.dev_addr, &drp_ie->dev_addr) == 0; -} - -/* - * Process a received DRP IE. - */ -static void uwb_drp_process(struct uwb_rc *rc, struct uwb_rc_evt_drp *drp_evt, - struct uwb_dev *src, struct uwb_ie_drp *drp_ie) -{ - if (uwb_ie_drp_type(drp_ie) == UWB_DRP_TYPE_ALIEN_BP) - uwb_drp_handle_alien_drp(rc, drp_ie); - else if (uwb_drp_involves_us(rc, drp_ie)) - uwb_drp_process_involved(rc, src, drp_evt, drp_ie); - else - uwb_drp_process_not_involved(rc, drp_evt, drp_ie); -} - -/* - * Process a received DRP Availability IE - */ -static void uwb_drp_availability_process(struct uwb_rc *rc, struct uwb_dev *src, - struct uwb_ie_drp_avail *drp_availability_ie) -{ - bitmap_copy(src->last_availability_bm, - drp_availability_ie->bmp, UWB_NUM_MAS); -} - -/* - * Process all the DRP IEs (both DRP IEs and the DRP Availability IE) - * from a device. - */ -static -void uwb_drp_process_all(struct uwb_rc *rc, struct uwb_rc_evt_drp *drp_evt, - size_t ielen, struct uwb_dev *src_dev) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_ie_hdr *ie_hdr; - void *ptr; - - ptr = drp_evt->ie_data; - for (;;) { - ie_hdr = uwb_ie_next(&ptr, &ielen); - if (!ie_hdr) - break; - - switch (ie_hdr->element_id) { - case UWB_IE_DRP_AVAILABILITY: - uwb_drp_availability_process(rc, src_dev, (struct uwb_ie_drp_avail *)ie_hdr); - break; - case UWB_IE_DRP: - uwb_drp_process(rc, drp_evt, src_dev, (struct uwb_ie_drp *)ie_hdr); - break; - default: - dev_warn(dev, "unexpected IE in DRP notification\n"); - break; - } - } - - if (ielen > 0) - dev_warn(dev, "%d octets remaining in DRP notification\n", - (int)ielen); -} - -/** - * uwbd_evt_handle_rc_drp - handle a DRP_IE event - * @evt: the DRP_IE event from the radio controller - * - * This processes DRP notifications from the radio controller, either - * initiating a new reservation or transitioning an existing - * reservation into a different state. - * - * DRP notifications can occur for three different reasons: - * - * - UWB_DRP_NOTIF_DRP_IE_RECVD: one or more DRP IEs with the RC as - * the target or source have been received. - * - * These DRP IEs could be new or for an existing reservation. - * - * If the DRP IE for an existing reservation ceases to be to - * received for at least mMaxLostBeacons, the reservation should be - * considered to be terminated. Note that the TERMINATE reason (see - * below) may not always be signalled (e.g., the remote device has - * two or more reservations established with the RC). - * - * - UWB_DRP_NOTIF_CONFLICT: DRP IEs from any device in the beacon - * group conflict with the RC's reservations. - * - * - UWB_DRP_NOTIF_TERMINATE: DRP IEs are no longer being received - * from a device (i.e., it's terminated all reservations). - * - * Only the software state of the reservations is changed; the setting - * of the radio controller's DRP IEs is done after all the events in - * an event buffer are processed. This saves waiting multiple times - * for the SET_DRP_IE command to complete. - */ -int uwbd_evt_handle_rc_drp(struct uwb_event *evt) -{ - struct device *dev = &evt->rc->uwb_dev.dev; - struct uwb_rc *rc = evt->rc; - struct uwb_rc_evt_drp *drp_evt; - size_t ielength, bytes_left; - struct uwb_dev_addr src_addr; - struct uwb_dev *src_dev; - - /* Is there enough data to decode the event (and any IEs in - its payload)? */ - if (evt->notif.size < sizeof(*drp_evt)) { - dev_err(dev, "DRP event: Not enough data to decode event " - "[%zu bytes left, %zu needed]\n", - evt->notif.size, sizeof(*drp_evt)); - return 0; - } - bytes_left = evt->notif.size - sizeof(*drp_evt); - drp_evt = container_of(evt->notif.rceb, struct uwb_rc_evt_drp, rceb); - ielength = le16_to_cpu(drp_evt->ie_length); - if (bytes_left != ielength) { - dev_err(dev, "DRP event: Not enough data in payload [%zu" - "bytes left, %zu declared in the event]\n", - bytes_left, ielength); - return 0; - } - - memcpy(src_addr.data, &drp_evt->src_addr, sizeof(src_addr)); - src_dev = uwb_dev_get_by_devaddr(rc, &src_addr); - if (!src_dev) { - /* - * A DRP notification from an unrecognized device. - * - * This is probably from a WUSB device that doesn't - * have an EUI-48 and therefore doesn't show up in the - * UWB device database. It's safe to simply ignore - * these. - */ - return 0; - } - - mutex_lock(&rc->rsvs_mutex); - - /* We do not distinguish from the reason */ - uwb_drp_process_all(rc, drp_evt, ielength, src_dev); - - mutex_unlock(&rc->rsvs_mutex); - - uwb_dev_put(src_dev); - return 0; -} diff --git a/drivers/staging/uwb/est.c b/drivers/staging/uwb/est.c deleted file mode 100644 index d4141ffdd775..000000000000 --- a/drivers/staging/uwb/est.c +++ /dev/null @@ -1,450 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band Radio Control - * Event Size Tables management - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * - * Infrastructure, code and data tables for guessing the size of - * events received on the notification endpoints of UWB radio - * controllers. - * - * You define a table of events and for each, its size and how to get - * the extra size. - * - * ENTRY POINTS: - * - * uwb_est_{init/destroy}(): To initialize/release the EST subsystem. - * - * uwb_est_[u]register(): To un/register event size tables - * uwb_est_grow() - * - * uwb_est_find_size(): Get the size of an event - * uwb_est_get_size() - */ -#include <linux/spinlock.h> -#include <linux/slab.h> -#include <linux/export.h> - -#include "uwb-internal.h" - -struct uwb_est { - u16 type_event_high; - u16 vendor, product; - u8 entries; - const struct uwb_est_entry *entry; -}; - -static struct uwb_est *uwb_est; -static u8 uwb_est_size; -static u8 uwb_est_used; -static DEFINE_RWLOCK(uwb_est_lock); - -/** - * WUSB Standard Event Size Table, HWA-RC interface - * - * Sizes for events and notifications type 0 (general), high nibble 0. - */ -static -struct uwb_est_entry uwb_est_00_00xx[] = { - [UWB_RC_EVT_IE_RCV] = { - .size = sizeof(struct uwb_rc_evt_ie_rcv), - .offset = 1 + offsetof(struct uwb_rc_evt_ie_rcv, wIELength), - }, - [UWB_RC_EVT_BEACON] = { - .size = sizeof(struct uwb_rc_evt_beacon), - .offset = 1 + offsetof(struct uwb_rc_evt_beacon, wBeaconInfoLength), - }, - [UWB_RC_EVT_BEACON_SIZE] = { - .size = sizeof(struct uwb_rc_evt_beacon_size), - }, - [UWB_RC_EVT_BPOIE_CHANGE] = { - .size = sizeof(struct uwb_rc_evt_bpoie_change), - .offset = 1 + offsetof(struct uwb_rc_evt_bpoie_change, - wBPOIELength), - }, - [UWB_RC_EVT_BP_SLOT_CHANGE] = { - .size = sizeof(struct uwb_rc_evt_bp_slot_change), - }, - [UWB_RC_EVT_BP_SWITCH_IE_RCV] = { - .size = sizeof(struct uwb_rc_evt_bp_switch_ie_rcv), - .offset = 1 + offsetof(struct uwb_rc_evt_bp_switch_ie_rcv, wIELength), - }, - [UWB_RC_EVT_DEV_ADDR_CONFLICT] = { - .size = sizeof(struct uwb_rc_evt_dev_addr_conflict), - }, - [UWB_RC_EVT_DRP_AVAIL] = { - .size = sizeof(struct uwb_rc_evt_drp_avail) - }, - [UWB_RC_EVT_DRP] = { - .size = sizeof(struct uwb_rc_evt_drp), - .offset = 1 + offsetof(struct uwb_rc_evt_drp, ie_length), - }, - [UWB_RC_EVT_BP_SWITCH_STATUS] = { - .size = sizeof(struct uwb_rc_evt_bp_switch_status), - }, - [UWB_RC_EVT_CMD_FRAME_RCV] = { - .size = sizeof(struct uwb_rc_evt_cmd_frame_rcv), - .offset = 1 + offsetof(struct uwb_rc_evt_cmd_frame_rcv, dataLength), - }, - [UWB_RC_EVT_CHANNEL_CHANGE_IE_RCV] = { - .size = sizeof(struct uwb_rc_evt_channel_change_ie_rcv), - .offset = 1 + offsetof(struct uwb_rc_evt_channel_change_ie_rcv, wIELength), - }, - [UWB_RC_CMD_CHANNEL_CHANGE] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_DEV_ADDR_MGMT] = { - .size = sizeof(struct uwb_rc_evt_dev_addr_mgmt) }, - [UWB_RC_CMD_GET_IE] = { - .size = sizeof(struct uwb_rc_evt_get_ie), - .offset = 1 + offsetof(struct uwb_rc_evt_get_ie, wIELength), - }, - [UWB_RC_CMD_RESET] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SCAN] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SET_BEACON_FILTER] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SET_DRP_IE] = { - .size = sizeof(struct uwb_rc_evt_set_drp_ie), - }, - [UWB_RC_CMD_SET_IE] = { - .size = sizeof(struct uwb_rc_evt_set_ie), - }, - [UWB_RC_CMD_SET_NOTIFICATION_FILTER] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SET_TX_POWER] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SLEEP] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_START_BEACON] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_STOP_BEACON] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_BP_MERGE] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SEND_COMMAND_FRAME] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, - [UWB_RC_CMD_SET_ASIE_NOTIF] = { - .size = sizeof(struct uwb_rc_evt_confirm), - }, -}; - -static -struct uwb_est_entry uwb_est_01_00xx[] = { - [UWB_RC_DAA_ENERGY_DETECTED] = { - .size = sizeof(struct uwb_rc_evt_daa_energy_detected), - }, - [UWB_RC_SET_DAA_ENERGY_MASK] = { - .size = sizeof(struct uwb_rc_evt_set_daa_energy_mask), - }, - [UWB_RC_SET_NOTIFICATION_FILTER_EX] = { - .size = sizeof(struct uwb_rc_evt_set_notification_filter_ex), - }, -}; - -/** - * Initialize the EST subsystem - * - * Register the standard tables also. - * - * FIXME: tag init - */ -int uwb_est_create(void) -{ - int result; - - uwb_est_size = 2; - uwb_est_used = 0; - uwb_est = kcalloc(uwb_est_size, sizeof(uwb_est[0]), GFP_KERNEL); - if (uwb_est == NULL) - return -ENOMEM; - - result = uwb_est_register(UWB_RC_CET_GENERAL, 0, 0xffff, 0xffff, - uwb_est_00_00xx, ARRAY_SIZE(uwb_est_00_00xx)); - if (result < 0) - goto out; - result = uwb_est_register(UWB_RC_CET_EX_TYPE_1, 0, 0xffff, 0xffff, - uwb_est_01_00xx, ARRAY_SIZE(uwb_est_01_00xx)); -out: - return result; -} - - -/** Clean it up */ -void uwb_est_destroy(void) -{ - kfree(uwb_est); - uwb_est = NULL; - uwb_est_size = uwb_est_used = 0; -} - - -/** - * Double the capacity of the EST table - * - * @returns 0 if ok, < 0 errno no error. - */ -static -int uwb_est_grow(void) -{ - size_t actual_size = uwb_est_size * sizeof(uwb_est[0]); - void *new = kmalloc_array(2, actual_size, GFP_ATOMIC); - if (new == NULL) - return -ENOMEM; - memcpy(new, uwb_est, actual_size); - memset(new + actual_size, 0, actual_size); - kfree(uwb_est); - uwb_est = new; - uwb_est_size *= 2; - return 0; -} - - -/** - * Register an event size table - * - * Makes room for it if the table is full, and then inserts it in the - * right position (entries are sorted by type, event_high, vendor and - * then product). - * - * @vendor: vendor code for matching against the device (0x0000 and - * 0xffff mean any); use 0x0000 to force all to match without - * checking possible vendor specific ones, 0xfffff to match - * after checking vendor specific ones. - * - * @product: product code from that vendor; same matching rules, use - * 0x0000 for not allowing vendor specific matches, 0xffff - * for allowing. - * - * This arragement just makes the tables sort differenty. Because the - * table is sorted by growing type-event_high-vendor-product, a zero - * vendor will match before than a 0x456a vendor, that will match - * before a 0xfffff vendor. - * - * @returns 0 if ok, < 0 errno on error (-ENOENT if not found). - */ -/* FIXME: add bus type to vendor/product code */ -int uwb_est_register(u8 type, u8 event_high, u16 vendor, u16 product, - const struct uwb_est_entry *entry, size_t entries) -{ - unsigned long flags; - unsigned itr; - int result = 0; - - write_lock_irqsave(&uwb_est_lock, flags); - if (uwb_est_used == uwb_est_size) { - result = uwb_est_grow(); - if (result < 0) - goto out; - } - /* Find the right spot to insert it in */ - for (itr = 0; itr < uwb_est_used; itr++) - if (uwb_est[itr].type_event_high < type - && uwb_est[itr].vendor < vendor - && uwb_est[itr].product < product) - break; - - /* Shift others to make room for the new one? */ - if (itr < uwb_est_used) - memmove(&uwb_est[itr+1], &uwb_est[itr], uwb_est_used - itr); - uwb_est[itr].type_event_high = type << 8 | event_high; - uwb_est[itr].vendor = vendor; - uwb_est[itr].product = product; - uwb_est[itr].entry = entry; - uwb_est[itr].entries = entries; - uwb_est_used++; -out: - write_unlock_irqrestore(&uwb_est_lock, flags); - return result; -} -EXPORT_SYMBOL_GPL(uwb_est_register); - - -/** - * Unregister an event size table - * - * This just removes the specified entry and moves the ones after it - * to fill in the gap. This is needed to keep the list sorted; no - * reallocation is done to reduce the size of the table. - * - * We unregister by all the data we used to register instead of by - * pointer to the @entry array because we might have used the same - * table for a bunch of IDs (for example). - * - * @returns 0 if ok, < 0 errno on error (-ENOENT if not found). - */ -int uwb_est_unregister(u8 type, u8 event_high, u16 vendor, u16 product, - const struct uwb_est_entry *entry, size_t entries) -{ - unsigned long flags; - unsigned itr; - struct uwb_est est_cmp = { - .type_event_high = type << 8 | event_high, - .vendor = vendor, - .product = product, - .entry = entry, - .entries = entries - }; - write_lock_irqsave(&uwb_est_lock, flags); - for (itr = 0; itr < uwb_est_used; itr++) - if (!memcmp(&uwb_est[itr], &est_cmp, sizeof(est_cmp))) - goto found; - write_unlock_irqrestore(&uwb_est_lock, flags); - return -ENOENT; - -found: - if (itr < uwb_est_used - 1) /* Not last one? move ones above */ - memmove(&uwb_est[itr], &uwb_est[itr+1], uwb_est_used - itr - 1); - uwb_est_used--; - write_unlock_irqrestore(&uwb_est_lock, flags); - return 0; -} -EXPORT_SYMBOL_GPL(uwb_est_unregister); - - -/** - * Get the size of an event from a table - * - * @rceb: pointer to the buffer with the event - * @rceb_size: size of the area pointed to by @rceb in bytes. - * @returns: > 0 Size of the event - * -ENOSPC An area big enough was not provided to look - * ahead into the event's guts and guess the size. - * -EINVAL Unknown event code (wEvent). - * - * This will look at the received RCEB and guess what is the total - * size. For variable sized events, it will look further ahead into - * their length field to see how much data should be read. - * - * Note this size is *not* final--the neh (Notification/Event Handle) - * might specificy an extra size to add. - */ -static -ssize_t uwb_est_get_size(struct uwb_rc *uwb_rc, struct uwb_est *est, - u8 event_low, const struct uwb_rceb *rceb, - size_t rceb_size) -{ - unsigned offset; - ssize_t size; - struct device *dev = &uwb_rc->uwb_dev.dev; - const struct uwb_est_entry *entry; - - size = -ENOENT; - if (event_low >= est->entries) { /* in range? */ - dev_err(dev, "EST %p 0x%04x/%04x/%04x[%u]: event %u out of range\n", - est, est->type_event_high, est->vendor, est->product, - est->entries, event_low); - goto out; - } - size = -ENOENT; - entry = &est->entry[event_low]; - if (entry->size == 0 && entry->offset == 0) { /* unknown? */ - dev_err(dev, "EST %p 0x%04x/%04x/%04x[%u]: event %u unknown\n", - est, est->type_event_high, est->vendor, est->product, - est->entries, event_low); - goto out; - } - offset = entry->offset; /* extra fries with that? */ - if (offset == 0) - size = entry->size; - else { - /* Ops, got an extra size field at 'offset'--read it */ - const void *ptr = rceb; - size_t type_size = 0; - offset--; - size = -ENOSPC; /* enough data for more? */ - switch (entry->type) { - case UWB_EST_16: type_size = sizeof(__le16); break; - case UWB_EST_8: type_size = sizeof(u8); break; - default: BUG(); - } - if (offset + type_size > rceb_size) { - dev_err(dev, "EST %p 0x%04x/%04x/%04x[%u]: " - "not enough data to read extra size\n", - est, est->type_event_high, est->vendor, - est->product, est->entries); - goto out; - } - size = entry->size; - ptr += offset; - switch (entry->type) { - case UWB_EST_16: size += le16_to_cpu(*(__le16 *)ptr); break; - case UWB_EST_8: size += *(u8 *)ptr; break; - default: BUG(); - } - } -out: - return size; -} - - -/** - * Guesses the size of a WA event - * - * @rceb: pointer to the buffer with the event - * @rceb_size: size of the area pointed to by @rceb in bytes. - * @returns: > 0 Size of the event - * -ENOSPC An area big enough was not provided to look - * ahead into the event's guts and guess the size. - * -EINVAL Unknown event code (wEvent). - * - * This will look at the received RCEB and guess what is the total - * size by checking all the tables registered with - * uwb_est_register(). For variable sized events, it will look further - * ahead into their length field to see how much data should be read. - * - * Note this size is *not* final--the neh (Notification/Event Handle) - * might specificy an extra size to add or replace. - */ -ssize_t uwb_est_find_size(struct uwb_rc *rc, const struct uwb_rceb *rceb, - size_t rceb_size) -{ - /* FIXME: add vendor/product data */ - ssize_t size; - struct device *dev = &rc->uwb_dev.dev; - unsigned long flags; - unsigned itr; - u16 type_event_high, event; - - read_lock_irqsave(&uwb_est_lock, flags); - size = -ENOSPC; - if (rceb_size < sizeof(*rceb)) - goto out; - event = le16_to_cpu(rceb->wEvent); - type_event_high = rceb->bEventType << 8 | (event & 0xff00) >> 8; - for (itr = 0; itr < uwb_est_used; itr++) { - if (uwb_est[itr].type_event_high != type_event_high) - continue; - size = uwb_est_get_size(rc, &uwb_est[itr], - event & 0x00ff, rceb, rceb_size); - /* try more tables that might handle the same type */ - if (size != -ENOENT) - goto out; - } - dev_dbg(dev, - "event 0x%02x/%04x/%02x: no handlers available; RCEB %4ph\n", - (unsigned) rceb->bEventType, - (unsigned) le16_to_cpu(rceb->wEvent), - (unsigned) rceb->bEventContext, - rceb); - size = -ENOENT; -out: - read_unlock_irqrestore(&uwb_est_lock, flags); - return size; -} -EXPORT_SYMBOL_GPL(uwb_est_find_size); diff --git a/drivers/staging/uwb/hwa-rc.c b/drivers/staging/uwb/hwa-rc.c deleted file mode 100644 index b6effad749d7..000000000000 --- a/drivers/staging/uwb/hwa-rc.c +++ /dev/null @@ -1,929 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * WUSB Host Wire Adapter: Radio Control Interface (WUSB[8.6]) - * Radio Control command/event transport - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Initialize the Radio Control interface Driver. - * - * For each device probed, creates an 'struct hwarc' which contains - * just the representation of the UWB Radio Controller, and the logic - * for reading notifications and passing them to the UWB Core. - * - * So we initialize all of those, register the UWB Radio Controller - * and setup the notification/event handle to pipe the notifications - * to the UWB management Daemon. - * - * Command and event filtering. - * - * This is the driver for the Radio Control Interface described in WUSB - * 1.0. The core UWB module assumes that all drivers are compliant to the - * WHCI 0.95 specification. We thus create a filter that parses all - * incoming messages from the (WUSB 1.0) device and manipulate them to - * conform to the WHCI 0.95 specification. Similarly, outgoing messages - * are parsed and manipulated to conform to the WUSB 1.0 compliant messages - * that the device expects. Only a few messages are affected: - * Affected events: - * UWB_RC_EVT_BEACON - * UWB_RC_EVT_BP_SLOT_CHANGE - * UWB_RC_EVT_DRP_AVAIL - * UWB_RC_EVT_DRP - * Affected commands: - * UWB_RC_CMD_SCAN - * UWB_RC_CMD_SET_DRP_IE - */ -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/usb.h> -#include "../wusbcore/include/wusb.h" -#include "../wusbcore/include/wusb-wa.h" -#include "uwb.h" - -#include "uwb-internal.h" - -/* The device uses commands and events from the WHCI specification, although - * reporting itself as WUSB compliant. */ -#define WUSB_QUIRK_WHCI_CMD_EVT 0x01 - -/** - * Descriptor for an instance of the UWB Radio Control Driver that - * attaches to the RCI interface of the Host Wired Adapter. - * - * Unless there is a lock specific to the 'data members', all access - * is protected by uwb_rc->mutex. - * - * The NEEP (Notification/Event EndPoint) URB (@neep_urb) writes to - * @rd_buffer. Note there is no locking because it is perfectly (heh!) - * serialized--probe() submits an URB, callback is called, processes - * the data (synchronously), submits another URB, and so on. There is - * no concurrent access to the buffer. - */ -struct hwarc { - struct usb_device *usb_dev; - struct usb_interface *usb_iface; - struct uwb_rc *uwb_rc; /* UWB host controller */ - struct urb *neep_urb; /* Notification endpoint handling */ - struct edc neep_edc; - void *rd_buffer; /* NEEP read buffer */ -}; - - -/* Beacon received notification (WUSB 1.0 [8.6.3.2]) */ -struct uwb_rc_evt_beacon_WUSB_0100 { - struct uwb_rceb rceb; - u8 bChannelNumber; - __le16 wBPSTOffset; - u8 bLQI; - u8 bRSSI; - __le16 wBeaconInfoLength; - u8 BeaconInfo[]; -} __attribute__((packed)); - -/** - * Filter WUSB 1.0 BEACON RCV notification to be WHCI 0.95 - * - * @header: the incoming event - * @buf_size: size of buffer containing incoming event - * @new_size: size of event after filtering completed - * - * The WHCI 0.95 spec has a "Beacon Type" field. This value is unknown at - * the time we receive the beacon from WUSB so we just set it to - * UWB_RC_BEACON_TYPE_NEIGHBOR as a default. - * The solution below allocates memory upon receipt of every beacon from a - * WUSB device. This will deteriorate performance. What is the right way to - * do this? - */ -static -int hwarc_filter_evt_beacon_WUSB_0100(struct uwb_rc *rc, - struct uwb_rceb **header, - const size_t buf_size, - size_t *new_size) -{ - struct uwb_rc_evt_beacon_WUSB_0100 *be; - struct uwb_rc_evt_beacon *newbe; - size_t bytes_left, ielength; - struct device *dev = &rc->uwb_dev.dev; - - be = container_of(*header, struct uwb_rc_evt_beacon_WUSB_0100, rceb); - bytes_left = buf_size; - if (bytes_left < sizeof(*be)) { - dev_err(dev, "Beacon Received Notification: Not enough data " - "to decode for filtering (%zu vs %zu bytes needed)\n", - bytes_left, sizeof(*be)); - return -EINVAL; - } - bytes_left -= sizeof(*be); - ielength = le16_to_cpu(be->wBeaconInfoLength); - if (bytes_left < ielength) { - dev_err(dev, "Beacon Received Notification: Not enough data " - "to decode IEs (%zu vs %zu bytes needed)\n", - bytes_left, ielength); - return -EINVAL; - } - newbe = kzalloc(sizeof(*newbe) + ielength, GFP_ATOMIC); - if (newbe == NULL) - return -ENOMEM; - newbe->rceb = be->rceb; - newbe->bChannelNumber = be->bChannelNumber; - newbe->bBeaconType = UWB_RC_BEACON_TYPE_NEIGHBOR; - newbe->wBPSTOffset = be->wBPSTOffset; - newbe->bLQI = be->bLQI; - newbe->bRSSI = be->bRSSI; - newbe->wBeaconInfoLength = be->wBeaconInfoLength; - memcpy(newbe->BeaconInfo, be->BeaconInfo, ielength); - *header = &newbe->rceb; - *new_size = sizeof(*newbe) + ielength; - return 1; /* calling function will free memory */ -} - - -/* DRP Availability change notification (WUSB 1.0 [8.6.3.8]) */ -struct uwb_rc_evt_drp_avail_WUSB_0100 { - struct uwb_rceb rceb; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/** - * Filter WUSB 1.0 DRP AVAILABILITY CHANGE notification to be WHCI 0.95 - * - * @header: the incoming event - * @buf_size: size of buffer containing incoming event - * @new_size: size of event after filtering completed - */ -static -int hwarc_filter_evt_drp_avail_WUSB_0100(struct uwb_rc *rc, - struct uwb_rceb **header, - const size_t buf_size, - size_t *new_size) -{ - struct uwb_rc_evt_drp_avail_WUSB_0100 *da; - struct uwb_rc_evt_drp_avail *newda; - struct uwb_ie_hdr *ie_hdr; - size_t bytes_left, ielength; - struct device *dev = &rc->uwb_dev.dev; - - - da = container_of(*header, struct uwb_rc_evt_drp_avail_WUSB_0100, rceb); - bytes_left = buf_size; - if (bytes_left < sizeof(*da)) { - dev_err(dev, "Not enough data to decode DRP Avail " - "Notification for filtering. Expected %zu, " - "received %zu.\n", (size_t)sizeof(*da), bytes_left); - return -EINVAL; - } - bytes_left -= sizeof(*da); - ielength = le16_to_cpu(da->wIELength); - if (bytes_left < ielength) { - dev_err(dev, "DRP Avail Notification filter: IE length " - "[%zu bytes] does not match actual length " - "[%zu bytes].\n", ielength, bytes_left); - return -EINVAL; - } - if (ielength < sizeof(*ie_hdr)) { - dev_err(dev, "DRP Avail Notification filter: Not enough " - "data to decode IE [%zu bytes, %zu needed]\n", - ielength, sizeof(*ie_hdr)); - return -EINVAL; - } - ie_hdr = (void *) da->IEData; - if (ie_hdr->length > 32) { - dev_err(dev, "DRP Availability Change event has unexpected " - "length for filtering. Expected < 32 bytes, " - "got %zu bytes.\n", (size_t)ie_hdr->length); - return -EINVAL; - } - newda = kzalloc(sizeof(*newda), GFP_ATOMIC); - if (newda == NULL) - return -ENOMEM; - newda->rceb = da->rceb; - memcpy(newda->bmp, (u8 *) ie_hdr + sizeof(*ie_hdr), ie_hdr->length); - *header = &newda->rceb; - *new_size = sizeof(*newda); - return 1; /* calling function will free memory */ -} - - -/* DRP notification (WUSB 1.0 [8.6.3.9]) */ -struct uwb_rc_evt_drp_WUSB_0100 { - struct uwb_rceb rceb; - struct uwb_dev_addr wSrcAddr; - u8 bExplicit; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/** - * Filter WUSB 1.0 DRP Notification to be WHCI 0.95 - * - * @header: the incoming event - * @buf_size: size of buffer containing incoming event - * @new_size: size of event after filtering completed - * - * It is hard to manage DRP reservations without having a Reason code. - * Unfortunately there is none in the WUSB spec. We just set the default to - * DRP IE RECEIVED. - * We do not currently use the bBeaconSlotNumber value, so we set this to - * zero for now. - */ -static -int hwarc_filter_evt_drp_WUSB_0100(struct uwb_rc *rc, - struct uwb_rceb **header, - const size_t buf_size, - size_t *new_size) -{ - struct uwb_rc_evt_drp_WUSB_0100 *drpev; - struct uwb_rc_evt_drp *newdrpev; - size_t bytes_left, ielength; - struct device *dev = &rc->uwb_dev.dev; - - drpev = container_of(*header, struct uwb_rc_evt_drp_WUSB_0100, rceb); - bytes_left = buf_size; - if (bytes_left < sizeof(*drpev)) { - dev_err(dev, "Not enough data to decode DRP Notification " - "for filtering. Expected %zu, received %zu.\n", - (size_t)sizeof(*drpev), bytes_left); - return -EINVAL; - } - ielength = le16_to_cpu(drpev->wIELength); - bytes_left -= sizeof(*drpev); - if (bytes_left < ielength) { - dev_err(dev, "DRP Notification filter: header length [%zu " - "bytes] does not match actual length [%zu " - "bytes].\n", ielength, bytes_left); - return -EINVAL; - } - newdrpev = kzalloc(sizeof(*newdrpev) + ielength, GFP_ATOMIC); - if (newdrpev == NULL) - return -ENOMEM; - newdrpev->rceb = drpev->rceb; - newdrpev->src_addr = drpev->wSrcAddr; - newdrpev->reason = UWB_DRP_NOTIF_DRP_IE_RCVD; - newdrpev->beacon_slot_number = 0; - newdrpev->ie_length = drpev->wIELength; - memcpy(newdrpev->ie_data, drpev->IEData, ielength); - *header = &newdrpev->rceb; - *new_size = sizeof(*newdrpev) + ielength; - return 1; /* calling function will free memory */ -} - - -/* Scan Command (WUSB 1.0 [8.6.2.5]) */ -struct uwb_rc_cmd_scan_WUSB_0100 { - struct uwb_rccb rccb; - u8 bChannelNumber; - u8 bScanState; -} __attribute__((packed)); - -/** - * Filter WHCI 0.95 SCAN command to be WUSB 1.0 SCAN command - * - * @header: command sent to device (compliant to WHCI 0.95) - * @size: size of command sent to device - * - * We only reduce the size by two bytes because the WUSB 1.0 scan command - * does not have the last field (wStarttime). Also, make sure we don't send - * the device an unexpected scan type. - */ -static -int hwarc_filter_cmd_scan_WUSB_0100(struct uwb_rc *rc, - struct uwb_rccb **header, - size_t *size) -{ - struct uwb_rc_cmd_scan *sc; - - sc = container_of(*header, struct uwb_rc_cmd_scan, rccb); - - if (sc->bScanState == UWB_SCAN_ONLY_STARTTIME) - sc->bScanState = UWB_SCAN_ONLY; - /* Don't send the last two bytes. */ - *size -= 2; - return 0; -} - - -/* SET DRP IE command (WUSB 1.0 [8.6.2.7]) */ -struct uwb_rc_cmd_set_drp_ie_WUSB_0100 { - struct uwb_rccb rccb; - u8 bExplicit; - __le16 wIELength; - struct uwb_ie_drp IEData[]; -} __attribute__((packed)); - -/** - * Filter WHCI 0.95 SET DRP IE command to be WUSB 1.0 SET DRP IE command - * - * @header: command sent to device (compliant to WHCI 0.95) - * @size: size of command sent to device - * - * WUSB has an extra bExplicit field - we assume always explicit - * negotiation so this field is set. The command expected by the device is - * thus larger than the one prepared by the driver so we need to - * reallocate memory to accommodate this. - * We trust the driver to send us the correct data so no checking is done - * on incoming data - evn though it is variable length. - */ -static -int hwarc_filter_cmd_set_drp_ie_WUSB_0100(struct uwb_rc *rc, - struct uwb_rccb **header, - size_t *size) -{ - struct uwb_rc_cmd_set_drp_ie *orgcmd; - struct uwb_rc_cmd_set_drp_ie_WUSB_0100 *cmd; - size_t ielength; - - orgcmd = container_of(*header, struct uwb_rc_cmd_set_drp_ie, rccb); - ielength = le16_to_cpu(orgcmd->wIELength); - cmd = kzalloc(sizeof(*cmd) + ielength, GFP_KERNEL); - if (cmd == NULL) - return -ENOMEM; - cmd->rccb = orgcmd->rccb; - cmd->bExplicit = 0; - cmd->wIELength = orgcmd->wIELength; - memcpy(cmd->IEData, orgcmd->IEData, ielength); - *header = &cmd->rccb; - *size = sizeof(*cmd) + ielength; - return 1; /* calling function will free memory */ -} - - -/** - * Filter data from WHCI driver to WUSB device - * - * @header: WHCI 0.95 compliant command from driver - * @size: length of command - * - * The routine managing commands to the device (uwb_rc_cmd()) will call the - * filtering function pointer (if it exists) before it passes any data to - * the device. At this time the command has been formatted according to - * WHCI 0.95 and is ready to be sent to the device. - * - * The filter function will be provided with the current command and its - * length. The function will manipulate the command if necessary and - * potentially reallocate memory for a command that needed more memory that - * the given command. If new memory was created the function will return 1 - * to indicate to the calling function that the memory need to be freed - * when not needed any more. The size will contain the new length of the - * command. - * If memory has not been allocated we rely on the original mechanisms to - * free the memory of the command - even when we reduce the value of size. - */ -static -int hwarc_filter_cmd_WUSB_0100(struct uwb_rc *rc, struct uwb_rccb **header, - size_t *size) -{ - int result; - struct uwb_rccb *rccb = *header; - int cmd = le16_to_cpu(rccb->wCommand); - switch (cmd) { - case UWB_RC_CMD_SCAN: - result = hwarc_filter_cmd_scan_WUSB_0100(rc, header, size); - break; - case UWB_RC_CMD_SET_DRP_IE: - result = hwarc_filter_cmd_set_drp_ie_WUSB_0100(rc, header, size); - break; - default: - result = -ENOANO; - break; - } - return result; -} - - -/** - * Filter data from WHCI driver to WUSB device - * - * @header: WHCI 0.95 compliant command from driver - * @size: length of command - * - * Filter commands based on which protocol the device supports. The WUSB - * errata should be the same as WHCI 0.95 so we do not filter that here - - * only WUSB 1.0. - */ -static -int hwarc_filter_cmd(struct uwb_rc *rc, struct uwb_rccb **header, - size_t *size) -{ - int result = -ENOANO; - if (rc->version == 0x0100) - result = hwarc_filter_cmd_WUSB_0100(rc, header, size); - return result; -} - - -/** - * Compute return value as sum of incoming value and value at given offset - * - * @rceb: event for which we compute the size, it contains a variable - * length field. - * @core_size: size of the "non variable" part of the event - * @offset: place in event where the length of the variable part is stored - * @buf_size: total length of buffer in which event arrived - we need to make - * sure we read the offset in memory that is still part of the event - */ -static -ssize_t hwarc_get_event_size(struct uwb_rc *rc, const struct uwb_rceb *rceb, - size_t core_size, size_t offset, - const size_t buf_size) -{ - ssize_t size = -ENOSPC; - const void *ptr = rceb; - size_t type_size = sizeof(__le16); - struct device *dev = &rc->uwb_dev.dev; - - if (offset + type_size >= buf_size) { - dev_err(dev, "Not enough data to read extra size of event " - "0x%02x/%04x/%02x, only got %zu bytes.\n", - rceb->bEventType, le16_to_cpu(rceb->wEvent), - rceb->bEventContext, buf_size); - goto out; - } - ptr += offset; - size = core_size + le16_to_cpu(*(__le16 *)ptr); -out: - return size; -} - - -/* Beacon slot change notification (WUSB 1.0 [8.6.3.5]) */ -struct uwb_rc_evt_bp_slot_change_WUSB_0100 { - struct uwb_rceb rceb; - u8 bSlotNumber; -} __attribute__((packed)); - - -/** - * Filter data from WUSB device to WHCI driver - * - * @header: incoming event - * @buf_size: size of buffer in which event arrived - * @_event_size: actual size of event in the buffer - * @new_size: size of event after filtered - * - * We don't know how the buffer is constructed - there may be more than one - * event in it so buffer length does not determine event length. We first - * determine the expected size of the incoming event. This value is passed - * back only if the actual filtering succeeded (so we know the computed - * expected size is correct). This value will be zero if - * the event did not need any filtering. - * - * WHCI interprets the BP Slot Change event's data differently than - * WUSB. The event sizes are exactly the same. The data field - * indicates the new beacon slot in which a RC is transmitting its - * beacon. The maximum value of this is 96 (wMacBPLength ECMA-368 - * 17.16 (Table 117)). We thus know that the WUSB value will not set - * the bit bNoSlot, so we don't really do anything (placeholder). - */ -static -int hwarc_filter_event_WUSB_0100(struct uwb_rc *rc, struct uwb_rceb **header, - const size_t buf_size, size_t *_real_size, - size_t *_new_size) -{ - int result = -ENOANO; - struct uwb_rceb *rceb = *header; - int event = le16_to_cpu(rceb->wEvent); - ssize_t event_size; - size_t core_size, offset; - - if (rceb->bEventType != UWB_RC_CET_GENERAL) - goto out; - switch (event) { - case UWB_RC_EVT_BEACON: - core_size = sizeof(struct uwb_rc_evt_beacon_WUSB_0100); - offset = offsetof(struct uwb_rc_evt_beacon_WUSB_0100, - wBeaconInfoLength); - event_size = hwarc_get_event_size(rc, rceb, core_size, - offset, buf_size); - if (event_size < 0) - goto out; - *_real_size = event_size; - result = hwarc_filter_evt_beacon_WUSB_0100(rc, header, - buf_size, _new_size); - break; - case UWB_RC_EVT_BP_SLOT_CHANGE: - *_new_size = *_real_size = - sizeof(struct uwb_rc_evt_bp_slot_change_WUSB_0100); - result = 0; - break; - - case UWB_RC_EVT_DRP_AVAIL: - core_size = sizeof(struct uwb_rc_evt_drp_avail_WUSB_0100); - offset = offsetof(struct uwb_rc_evt_drp_avail_WUSB_0100, - wIELength); - event_size = hwarc_get_event_size(rc, rceb, core_size, - offset, buf_size); - if (event_size < 0) - goto out; - *_real_size = event_size; - result = hwarc_filter_evt_drp_avail_WUSB_0100( - rc, header, buf_size, _new_size); - break; - - case UWB_RC_EVT_DRP: - core_size = sizeof(struct uwb_rc_evt_drp_WUSB_0100); - offset = offsetof(struct uwb_rc_evt_drp_WUSB_0100, wIELength); - event_size = hwarc_get_event_size(rc, rceb, core_size, - offset, buf_size); - if (event_size < 0) - goto out; - *_real_size = event_size; - result = hwarc_filter_evt_drp_WUSB_0100(rc, header, - buf_size, _new_size); - break; - - default: - break; - } -out: - return result; -} - -/** - * Filter data from WUSB device to WHCI driver - * - * @header: incoming event - * @buf_size: size of buffer in which event arrived - * @_event_size: actual size of event in the buffer - * @_new_size: size of event after filtered - * - * Filter events based on which protocol the device supports. The WUSB - * errata should be the same as WHCI 0.95 so we do not filter that here - - * only WUSB 1.0. - * - * If we don't handle it, we return -ENOANO (why the weird error code? - * well, so if I get it, I can pinpoint in the code that raised - * it...after all, not too many places use the higher error codes). - */ -static -int hwarc_filter_event(struct uwb_rc *rc, struct uwb_rceb **header, - const size_t buf_size, size_t *_real_size, - size_t *_new_size) -{ - int result = -ENOANO; - if (rc->version == 0x0100) - result = hwarc_filter_event_WUSB_0100( - rc, header, buf_size, _real_size, _new_size); - return result; -} - - -/** - * Execute an UWB RC command on HWA - * - * @rc: Instance of a Radio Controller that is a HWA - * @cmd: Buffer containing the RCCB and payload to execute - * @cmd_size: Size of the command buffer. - * - * NOTE: rc's mutex has to be locked - */ -static -int hwarc_cmd(struct uwb_rc *uwb_rc, const struct uwb_rccb *cmd, size_t cmd_size) -{ - struct hwarc *hwarc = uwb_rc->priv; - return usb_control_msg( - hwarc->usb_dev, usb_sndctrlpipe(hwarc->usb_dev, 0), - WA_EXEC_RC_CMD, USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, hwarc->usb_iface->cur_altsetting->desc.bInterfaceNumber, - (void *) cmd, cmd_size, 100 /* FIXME: this is totally arbitrary */); -} - -static -int hwarc_reset(struct uwb_rc *uwb_rc) -{ - struct hwarc *hwarc = uwb_rc->priv; - int result; - - /* device lock must be held when calling usb_reset_device. */ - result = usb_lock_device_for_reset(hwarc->usb_dev, NULL); - if (result >= 0) { - result = usb_reset_device(hwarc->usb_dev); - usb_unlock_device(hwarc->usb_dev); - } - - return result; -} - -/** - * Callback for the notification and event endpoint - * - * Check's that everything is fine and then passes the read data to - * the notification/event handling mechanism (neh). - */ -static -void hwarc_neep_cb(struct urb *urb) -{ - struct hwarc *hwarc = urb->context; - struct usb_interface *usb_iface = hwarc->usb_iface; - struct device *dev = &usb_iface->dev; - int result; - - switch (result = urb->status) { - case 0: - uwb_rc_neh_grok(hwarc->uwb_rc, urb->transfer_buffer, - urb->actual_length); - break; - case -ECONNRESET: /* Not an error, but a controlled situation; */ - case -ENOENT: /* (we killed the URB)...so, no broadcast */ - goto out; - case -ESHUTDOWN: /* going away! */ - goto out; - default: /* On general errors, retry unless it gets ugly */ - if (edc_inc(&hwarc->neep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)) - goto error_exceeded; - dev_err(dev, "NEEP: URB error %d\n", urb->status); - } - result = usb_submit_urb(urb, GFP_ATOMIC); - if (result < 0 && result != -ENODEV && result != -EPERM) { - /* ignoring unrecoverable errors */ - dev_err(dev, "NEEP: Can't resubmit URB (%d) resetting device\n", - result); - goto error; - } -out: - return; - -error_exceeded: - dev_err(dev, "NEEP: URB max acceptable errors " - "exceeded, resetting device\n"); -error: - uwb_rc_neh_error(hwarc->uwb_rc, result); - uwb_rc_reset_all(hwarc->uwb_rc); - return; -} - -static void hwarc_init(struct hwarc *hwarc) -{ - edc_init(&hwarc->neep_edc); -} - -/** - * Initialize the notification/event endpoint stuff - * - * Note this is effectively a parallel thread; it knows that - * hwarc->uwb_rc always exists because the existence of a 'hwarc' - * means that there is a reverence on the hwarc->uwb_rc (see - * _probe()), and thus _neep_cb() can execute safely. - */ -static int hwarc_neep_init(struct uwb_rc *rc) -{ - struct hwarc *hwarc = rc->priv; - struct usb_interface *iface = hwarc->usb_iface; - struct usb_device *usb_dev = interface_to_usbdev(iface); - struct device *dev = &iface->dev; - int result; - struct usb_endpoint_descriptor *epd; - - epd = &iface->cur_altsetting->endpoint[0].desc; - hwarc->rd_buffer = (void *) __get_free_page(GFP_KERNEL); - if (hwarc->rd_buffer == NULL) { - dev_err(dev, "Unable to allocate notification's read buffer\n"); - goto error_rd_buffer; - } - hwarc->neep_urb = usb_alloc_urb(0, GFP_KERNEL); - if (hwarc->neep_urb == NULL) - goto error_urb_alloc; - usb_fill_int_urb(hwarc->neep_urb, usb_dev, - usb_rcvintpipe(usb_dev, epd->bEndpointAddress), - hwarc->rd_buffer, PAGE_SIZE, - hwarc_neep_cb, hwarc, epd->bInterval); - result = usb_submit_urb(hwarc->neep_urb, GFP_ATOMIC); - if (result < 0) { - dev_err(dev, "Cannot submit notification URB: %d\n", result); - goto error_neep_submit; - } - return 0; - -error_neep_submit: - usb_free_urb(hwarc->neep_urb); - hwarc->neep_urb = NULL; -error_urb_alloc: - free_page((unsigned long)hwarc->rd_buffer); - hwarc->rd_buffer = NULL; -error_rd_buffer: - return -ENOMEM; -} - - -/** Clean up all the notification endpoint resources */ -static void hwarc_neep_release(struct uwb_rc *rc) -{ - struct hwarc *hwarc = rc->priv; - - usb_kill_urb(hwarc->neep_urb); - usb_free_urb(hwarc->neep_urb); - hwarc->neep_urb = NULL; - - free_page((unsigned long)hwarc->rd_buffer); - hwarc->rd_buffer = NULL; -} - -/** - * Get the version from class-specific descriptor - * - * NOTE: this descriptor comes with the big bundled configuration - * descriptor that includes the interfaces' and endpoints', so - * we just look for it in the cached copy kept by the USB stack. - * - * NOTE2: We convert LE fields to CPU order. - */ -static int hwarc_get_version(struct uwb_rc *rc) -{ - int result; - - struct hwarc *hwarc = rc->priv; - struct uwb_rc_control_intf_class_desc *descr; - struct device *dev = &rc->uwb_dev.dev; - struct usb_device *usb_dev = hwarc->usb_dev; - char *itr; - struct usb_descriptor_header *hdr; - size_t itr_size, actconfig_idx; - u16 version; - - actconfig_idx = (usb_dev->actconfig - usb_dev->config) / - sizeof(usb_dev->config[0]); - itr = usb_dev->rawdescriptors[actconfig_idx]; - itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength); - while (itr_size >= sizeof(*hdr)) { - hdr = (struct usb_descriptor_header *) itr; - dev_dbg(dev, "Extra device descriptor: " - "type %02x/%u bytes @ %zu (%zu left)\n", - hdr->bDescriptorType, hdr->bLength, - (itr - usb_dev->rawdescriptors[actconfig_idx]), - itr_size); - if (hdr->bDescriptorType == USB_DT_CS_RADIO_CONTROL) - goto found; - itr += hdr->bLength; - itr_size -= hdr->bLength; - } - dev_err(dev, "cannot find Radio Control Interface Class descriptor\n"); - return -ENODEV; - -found: - result = -EINVAL; - if (hdr->bLength > itr_size) { /* is it available? */ - dev_err(dev, "incomplete Radio Control Interface Class " - "descriptor (%zu bytes left, %u needed)\n", - itr_size, hdr->bLength); - goto error; - } - if (hdr->bLength < sizeof(*descr)) { - dev_err(dev, "short Radio Control Interface Class " - "descriptor\n"); - goto error; - } - descr = (struct uwb_rc_control_intf_class_desc *) hdr; - /* Make LE fields CPU order */ - version = __le16_to_cpu(descr->bcdRCIVersion); - if (version != 0x0100) { - dev_err(dev, "Device reports protocol version 0x%04x. We " - "do not support that. \n", version); - result = -EINVAL; - goto error; - } - rc->version = version; - dev_dbg(dev, "Device supports WUSB protocol version 0x%04x \n", rc->version); - result = 0; -error: - return result; -} - -/* - * By creating a 'uwb_rc', we have a reference on it -- that reference - * is the one we drop when we disconnect. - * - * No need to switch altsettings; according to WUSB1.0[8.6.1.1], there - * is only one altsetting allowed. - */ -static int hwarc_probe(struct usb_interface *iface, - const struct usb_device_id *id) -{ - int result; - struct uwb_rc *uwb_rc; - struct hwarc *hwarc; - struct device *dev = &iface->dev; - - if (iface->cur_altsetting->desc.bNumEndpoints < 1) - return -ENODEV; - if (!usb_endpoint_xfer_int(&iface->cur_altsetting->endpoint[0].desc)) - return -ENODEV; - - result = -ENOMEM; - uwb_rc = uwb_rc_alloc(); - if (uwb_rc == NULL) { - dev_err(dev, "unable to allocate RC instance\n"); - goto error_rc_alloc; - } - hwarc = kzalloc(sizeof(*hwarc), GFP_KERNEL); - if (hwarc == NULL) { - dev_err(dev, "unable to allocate HWA RC instance\n"); - goto error_alloc; - } - hwarc_init(hwarc); - hwarc->usb_dev = usb_get_dev(interface_to_usbdev(iface)); - hwarc->usb_iface = usb_get_intf(iface); - hwarc->uwb_rc = uwb_rc; - - uwb_rc->owner = THIS_MODULE; - uwb_rc->start = hwarc_neep_init; - uwb_rc->stop = hwarc_neep_release; - uwb_rc->cmd = hwarc_cmd; - uwb_rc->reset = hwarc_reset; - if (id->driver_info & WUSB_QUIRK_WHCI_CMD_EVT) { - uwb_rc->filter_cmd = NULL; - uwb_rc->filter_event = NULL; - } else { - uwb_rc->filter_cmd = hwarc_filter_cmd; - uwb_rc->filter_event = hwarc_filter_event; - } - - result = uwb_rc_add(uwb_rc, dev, hwarc); - if (result < 0) - goto error_rc_add; - result = hwarc_get_version(uwb_rc); - if (result < 0) { - dev_err(dev, "cannot retrieve version of RC \n"); - goto error_get_version; - } - usb_set_intfdata(iface, hwarc); - return 0; - -error_get_version: - uwb_rc_rm(uwb_rc); -error_rc_add: - usb_put_intf(iface); - usb_put_dev(hwarc->usb_dev); - kfree(hwarc); -error_alloc: - uwb_rc_put(uwb_rc); -error_rc_alloc: - return result; -} - -static void hwarc_disconnect(struct usb_interface *iface) -{ - struct hwarc *hwarc = usb_get_intfdata(iface); - struct uwb_rc *uwb_rc = hwarc->uwb_rc; - - usb_set_intfdata(hwarc->usb_iface, NULL); - uwb_rc_rm(uwb_rc); - usb_put_intf(hwarc->usb_iface); - usb_put_dev(hwarc->usb_dev); - kfree(hwarc); - uwb_rc_put(uwb_rc); /* when creating the device, refcount = 1 */ -} - -static int hwarc_pre_reset(struct usb_interface *iface) -{ - struct hwarc *hwarc = usb_get_intfdata(iface); - struct uwb_rc *uwb_rc = hwarc->uwb_rc; - - uwb_rc_pre_reset(uwb_rc); - return 0; -} - -static int hwarc_post_reset(struct usb_interface *iface) -{ - struct hwarc *hwarc = usb_get_intfdata(iface); - struct uwb_rc *uwb_rc = hwarc->uwb_rc; - - return uwb_rc_post_reset(uwb_rc); -} - -/** USB device ID's that we handle */ -static const struct usb_device_id hwarc_id_table[] = { - /* D-Link DUB-1210 */ - { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3d02, 0xe0, 0x01, 0x02), - .driver_info = WUSB_QUIRK_WHCI_CMD_EVT }, - /* Intel i1480 (using firmware 1.3PA2-20070828) */ - { USB_DEVICE_AND_INTERFACE_INFO(0x8086, 0x0c3b, 0xe0, 0x01, 0x02), - .driver_info = WUSB_QUIRK_WHCI_CMD_EVT }, - /* Alereon 5310 */ - { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x01, 0x02), - .driver_info = WUSB_QUIRK_WHCI_CMD_EVT }, - /* Alereon 5611 */ - { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x01, 0x02), - .driver_info = WUSB_QUIRK_WHCI_CMD_EVT }, - /* Generic match for the Radio Control interface */ - { USB_INTERFACE_INFO(0xe0, 0x01, 0x02), }, - { }, -}; -MODULE_DEVICE_TABLE(usb, hwarc_id_table); - -static struct usb_driver hwarc_driver = { - .name = "hwa-rc", - .id_table = hwarc_id_table, - .probe = hwarc_probe, - .disconnect = hwarc_disconnect, - .pre_reset = hwarc_pre_reset, - .post_reset = hwarc_post_reset, -}; - -module_usb_driver(hwarc_driver); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Host Wireless Adapter Radio Control Driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/uwb/i1480/Makefile b/drivers/staging/uwb/i1480/Makefile deleted file mode 100644 index d26fb9b845ae..000000000000 --- a/drivers/staging/uwb/i1480/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_UWB_I1480U) += dfu/ i1480-est.o diff --git a/drivers/staging/uwb/i1480/dfu/Makefile b/drivers/staging/uwb/i1480/dfu/Makefile deleted file mode 100644 index 4739fdac5922..000000000000 --- a/drivers/staging/uwb/i1480/dfu/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_UWB_I1480U) += i1480-dfu-usb.o - -i1480-dfu-usb-objs := \ - dfu.o \ - mac.o \ - phy.o \ - usb.o - - diff --git a/drivers/staging/uwb/i1480/dfu/dfu.c b/drivers/staging/uwb/i1480/dfu/dfu.c deleted file mode 100644 index 9d51ce8faad1..000000000000 --- a/drivers/staging/uwb/i1480/dfu/dfu.c +++ /dev/null @@ -1,198 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Intel Wireless UWB Link 1480 - * Main driver - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Common code for firmware upload used by the USB and PCI version; - * i1480_fw_upload() takes a device descriptor and uses the function - * pointers it provides to upload firmware and prepare the PHY. - * - * As well, provides common functions used by the rest of the code. - */ -#include "i1480-dfu.h" -#include <linux/errno.h> -#include <linux/delay.h> -#include <linux/pci.h> -#include <linux/device.h> -#include <linux/random.h> -#include <linux/export.h> -#include "../../uwb.h" - -/* - * i1480_rceb_check - Check RCEB for expected field values - * @i1480: pointer to device for which RCEB is being checked - * @rceb: RCEB being checked - * @cmd: which command the RCEB is related to - * @context: expected context - * @expected_type: expected event type - * @expected_event: expected event - * - * If @cmd is NULL, do not print error messages, but still return an error - * code. - * - * Return 0 if @rceb matches the expected values, -EINVAL otherwise. - */ -int i1480_rceb_check(const struct i1480 *i1480, const struct uwb_rceb *rceb, - const char *cmd, u8 context, u8 expected_type, - unsigned expected_event) -{ - int result = 0; - struct device *dev = i1480->dev; - if (rceb->bEventContext != context) { - if (cmd) - dev_err(dev, "%s: unexpected context id 0x%02x " - "(expected 0x%02x)\n", cmd, - rceb->bEventContext, context); - result = -EINVAL; - } - if (rceb->bEventType != expected_type) { - if (cmd) - dev_err(dev, "%s: unexpected event type 0x%02x " - "(expected 0x%02x)\n", cmd, - rceb->bEventType, expected_type); - result = -EINVAL; - } - if (le16_to_cpu(rceb->wEvent) != expected_event) { - if (cmd) - dev_err(dev, "%s: unexpected event 0x%04x " - "(expected 0x%04x)\n", cmd, - le16_to_cpu(rceb->wEvent), expected_event); - result = -EINVAL; - } - return result; -} -EXPORT_SYMBOL_GPL(i1480_rceb_check); - - -/* - * Execute a Radio Control Command - * - * Command data has to be in i1480->cmd_buf. - * - * @returns size of the reply data filled in i1480->evt_buf or < 0 errno - * code on error. - */ -ssize_t i1480_cmd(struct i1480 *i1480, const char *cmd_name, size_t cmd_size, - size_t reply_size) -{ - ssize_t result; - struct uwb_rceb *reply = i1480->evt_buf; - struct uwb_rccb *cmd = i1480->cmd_buf; - u16 expected_event = reply->wEvent; - u8 expected_type = reply->bEventType; - u8 context; - - init_completion(&i1480->evt_complete); - i1480->evt_result = -EINPROGRESS; - do { - get_random_bytes(&context, 1); - } while (context == 0x00 || context == 0xff); - cmd->bCommandContext = context; - result = i1480->cmd(i1480, cmd_name, cmd_size); - if (result < 0) - goto error; - /* wait for the callback to report a event was received */ - result = wait_for_completion_interruptible_timeout( - &i1480->evt_complete, HZ); - if (result == 0) { - result = -ETIMEDOUT; - goto error; - } - if (result < 0) - goto error; - result = i1480->evt_result; - if (result < 0) { - dev_err(i1480->dev, "%s: command reply reception failed: %zd\n", - cmd_name, result); - goto error; - } - /* - * Firmware versions >= 1.4.12224 for IOGear GUWA100U generate a - * spurious notification after firmware is downloaded. So check whether - * the receibed RCEB is such notification before assuming that the - * command has failed. - */ - if (i1480_rceb_check(i1480, i1480->evt_buf, NULL, - 0, 0xfd, 0x0022) == 0) { - /* Now wait for the actual RCEB for this command. */ - result = i1480->wait_init_done(i1480); - if (result < 0) - goto error; - result = i1480->evt_result; - } - if (result != reply_size) { - dev_err(i1480->dev, "%s returned only %zu bytes, %zu expected\n", - cmd_name, result, reply_size); - result = -EINVAL; - goto error; - } - /* Verify we got the right event in response */ - result = i1480_rceb_check(i1480, i1480->evt_buf, cmd_name, context, - expected_type, expected_event); -error: - return result; -} -EXPORT_SYMBOL_GPL(i1480_cmd); - - -static -int i1480_print_state(struct i1480 *i1480) -{ - int result; - u32 *buf = (u32 *) i1480->cmd_buf; - - result = i1480->read(i1480, 0x80080000, 2 * sizeof(*buf)); - if (result < 0) { - dev_err(i1480->dev, "cannot read U & L states: %d\n", result); - goto error; - } - dev_info(i1480->dev, "state U 0x%08x, L 0x%08x\n", buf[0], buf[1]); -error: - return result; -} - - -/* - * PCI probe, firmware uploader - * - * _mac_fw_upload() will call rc_setup(), which needs an rc_release(). - */ -int i1480_fw_upload(struct i1480 *i1480) -{ - int result; - - result = i1480_pre_fw_upload(i1480); /* PHY pre fw */ - if (result < 0 && result != -ENOENT) { - i1480_print_state(i1480); - goto error; - } - result = i1480_mac_fw_upload(i1480); /* MAC fw */ - if (result < 0) { - if (result == -ENOENT) - dev_err(i1480->dev, "Cannot locate MAC FW file '%s'\n", - i1480->mac_fw_name); - else - i1480_print_state(i1480); - goto error; - } - result = i1480_phy_fw_upload(i1480); /* PHY fw */ - if (result < 0 && result != -ENOENT) { - i1480_print_state(i1480); - goto error_rc_release; - } - /* - * FIXME: find some reliable way to check whether firmware is running - * properly. Maybe use some standard request that has no side effects? - */ - dev_info(i1480->dev, "firmware uploaded successfully\n"); -error_rc_release: - if (i1480->rc_release) - i1480->rc_release(i1480); - result = 0; -error: - return result; -} -EXPORT_SYMBOL_GPL(i1480_fw_upload); diff --git a/drivers/staging/uwb/i1480/dfu/i1480-dfu.h b/drivers/staging/uwb/i1480/dfu/i1480-dfu.h deleted file mode 100644 index b21d058ecc23..000000000000 --- a/drivers/staging/uwb/i1480/dfu/i1480-dfu.h +++ /dev/null @@ -1,246 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * i1480 Device Firmware Upload - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This driver is the firmware uploader for the Intel Wireless UWB - * Link 1480 device (both in the USB and PCI incarnations). - * - * The process is quite simple: we stop the device, write the firmware - * to its memory and then restart it. Wait for the device to let us - * know it is done booting firmware. Ready. - * - * We might have to upload before or after a phy firmware (which might - * be done in two methods, using a normal firmware image or through - * the MPI port). - * - * Because USB and PCI use common methods, we just make ops out of the - * common operations (read, write, wait_init_done and cmd) and - * implement them in usb.c and pci.c. - * - * The flow is (some parts omitted): - * - * i1480_{usb,pci}_probe() On enumerate/discovery - * i1480_fw_upload() - * i1480_pre_fw_upload() - * __mac_fw_upload() - * fw_hdrs_load() - * mac_fw_hdrs_push() - * i1480->write() [i1480_{usb,pci}_write()] - * i1480_fw_cmp() - * i1480->read() [i1480_{usb,pci}_read()] - * i1480_mac_fw_upload() - * __mac_fw_upload() - * i1480->setup(() - * i1480->wait_init_done() - * i1480_cmd_reset() - * i1480->cmd() [i1480_{usb,pci}_cmd()] - * ... - * i1480_phy_fw_upload() - * request_firmware() - * i1480_mpi_write() - * i1480->cmd() [i1480_{usb,pci}_cmd()] - * - * Once the probe function enumerates the device and uploads the - * firmware, we just exit with -ENODEV, as we don't really want to - * attach to the device. - */ -#ifndef __i1480_DFU_H__ -#define __i1480_DFU_H__ - -#include <linux/types.h> -#include <linux/completion.h> -#include "../../include/spec.h" - -#define i1480_FW_UPLOAD_MODE_MASK (cpu_to_le32(0x00000018)) - -#if i1480_FW > 0x00000302 -#define i1480_RCEB_EXTENDED -#endif - -struct uwb_rccb; -struct uwb_rceb; - -/* - * Common firmware upload handlers - * - * Normally you embed this struct in another one specific to your hw. - * - * @write Write to device's memory from buffer. - * @read Read from device's memory to i1480->evt_buf. - * @setup Setup device after basic firmware is uploaded - * @wait_init_done - * Wait for the device to send a notification saying init - * is done. - * @cmd FOP for issuing the command to the hardware. The - * command data is contained in i1480->cmd_buf and the size - * is supplied as an argument. The command replied is put - * in i1480->evt_buf and the size in i1480->evt_result (or if - * an error, a < 0 errno code). - * - * @cmd_buf Memory buffer used to send commands to the device. - * Allocated by the upper layers i1480_fw_upload(). - * Size has to be @buf_size. - * @evt_buf Memory buffer used to place the async notifications - * received by the hw. Allocated by the upper layers - * i1480_fw_upload(). - * Size has to be @buf_size. - * @cmd_complete - * Low level driver uses this to notify code waiting afor - * an event that the event has arrived and data is in - * i1480->evt_buf (and size/result in i1480->evt_result). - * @hw_rev - * Use this value to activate dfu code to support new revisions - * of hardware. i1480_init() sets this to a default value. - * It should be updated by the USB and PCI code. - */ -struct i1480 { - struct device *dev; - - int (*write)(struct i1480 *, u32 addr, const void *, size_t); - int (*read)(struct i1480 *, u32 addr, size_t); - int (*rc_setup)(struct i1480 *); - void (*rc_release)(struct i1480 *); - int (*wait_init_done)(struct i1480 *); - int (*cmd)(struct i1480 *, const char *cmd_name, size_t cmd_size); - const char *pre_fw_name; - const char *mac_fw_name; - const char *mac_fw_name_deprecate; /* FIXME: Will go away */ - const char *phy_fw_name; - u8 hw_rev; - - size_t buf_size; /* size of both evt_buf and cmd_buf */ - void *evt_buf, *cmd_buf; - ssize_t evt_result; - struct completion evt_complete; -}; - -static inline -void i1480_init(struct i1480 *i1480) -{ - i1480->hw_rev = 1; - init_completion(&i1480->evt_complete); -} - -extern int i1480_fw_upload(struct i1480 *); -extern int i1480_pre_fw_upload(struct i1480 *); -extern int i1480_mac_fw_upload(struct i1480 *); -extern int i1480_phy_fw_upload(struct i1480 *); -extern ssize_t i1480_cmd(struct i1480 *, const char *, size_t, size_t); -extern int i1480_rceb_check(const struct i1480 *, - const struct uwb_rceb *, const char *, u8, - u8, unsigned); - -enum { - /* Vendor specific command type */ - i1480_CET_VS1 = 0xfd, - /* i1480 commands */ - i1480_CMD_SET_IP_MAS = 0x000e, - i1480_CMD_GET_MAC_PHY_INFO = 0x0003, - i1480_CMD_MPI_WRITE = 0x000f, - i1480_CMD_MPI_READ = 0x0010, - /* i1480 events */ -#if i1480_FW > 0x00000302 - i1480_EVT_CONFIRM = 0x0002, - i1480_EVT_RM_INIT_DONE = 0x0101, - i1480_EVT_DEV_ADD = 0x0103, - i1480_EVT_DEV_RM = 0x0104, - i1480_EVT_DEV_ID_CHANGE = 0x0105, - i1480_EVT_GET_MAC_PHY_INFO = i1480_CMD_GET_MAC_PHY_INFO, -#else - i1480_EVT_CONFIRM = 0x0002, - i1480_EVT_RM_INIT_DONE = 0x0101, - i1480_EVT_DEV_ADD = 0x0103, - i1480_EVT_DEV_RM = 0x0104, - i1480_EVT_DEV_ID_CHANGE = 0x0105, - i1480_EVT_GET_MAC_PHY_INFO = i1480_EVT_CONFIRM, -#endif -}; - - -struct i1480_evt_confirm { - struct uwb_rceb rceb; -#ifdef i1480_RCEB_EXTENDED - __le16 wParamLength; -#endif - u8 bResultCode; -} __attribute__((packed)); - - -struct i1480_rceb { - struct uwb_rceb rceb; -#ifdef i1480_RCEB_EXTENDED - __le16 wParamLength; -#endif -} __attribute__((packed)); - - -/** - * Get MAC & PHY Information confirm event structure - * - * Confirm event returned by the command. - */ -struct i1480_evt_confirm_GMPI { -#if i1480_FW > 0x00000302 - struct uwb_rceb rceb; - __le16 wParamLength; - __le16 status; - u8 mac_addr[6]; /* EUI-64 bit IEEE address [still 8 bytes?] */ - u8 dev_addr[2]; - __le16 mac_fw_rev; /* major = v >> 8; minor = v & 0xff */ - u8 hw_rev; - u8 phy_vendor; - u8 phy_rev; /* major v = >> 8; minor = v & 0xff */ - __le16 mac_caps; - u8 phy_caps[3]; - u8 key_stores; - __le16 mcast_addr_stores; - u8 sec_mode_supported; -#else - struct uwb_rceb rceb; - u8 status; - u8 mac_addr[8]; /* EUI-64 bit IEEE address [still 8 bytes?] */ - u8 dev_addr[2]; - __le16 mac_fw_rev; /* major = v >> 8; minor = v & 0xff */ - __le16 phy_fw_rev; /* major v = >> 8; minor = v & 0xff */ - __le16 mac_caps; - u8 phy_caps; - u8 key_stores; - __le16 mcast_addr_stores; - u8 sec_mode_supported; -#endif -} __attribute__((packed)); - - -struct i1480_cmd_mpi_write { - struct uwb_rccb rccb; - __le16 size; - u8 data[]; -}; - - -struct i1480_cmd_mpi_read { - struct uwb_rccb rccb; - __le16 size; - struct { - u8 page, offset; - } __attribute__((packed)) data[]; -} __attribute__((packed)); - - -struct i1480_evt_mpi_read { - struct uwb_rceb rceb; -#ifdef i1480_RCEB_EXTENDED - __le16 wParamLength; -#endif - u8 bResultCode; - __le16 size; - struct { - u8 page, offset, value; - } __attribute__((packed)) data[]; -} __attribute__((packed)); - - -#endif /* #ifndef __i1480_DFU_H__ */ diff --git a/drivers/staging/uwb/i1480/dfu/mac.c b/drivers/staging/uwb/i1480/dfu/mac.c deleted file mode 100644 index 6e4d6c9cecf5..000000000000 --- a/drivers/staging/uwb/i1480/dfu/mac.c +++ /dev/null @@ -1,496 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Intel Wireless UWB Link 1480 - * MAC Firmware upload implementation - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Implementation of the code for parsing the firmware file (extract - * the headers and binary code chunks) in the fw_*() functions. The - * code to upload pre and mac firmwares is the same, so it uses a - * common entry point in __mac_fw_upload(), which uses the i1480 - * function pointers to push the firmware to the device. - */ -#include <linux/delay.h> -#include <linux/firmware.h> -#include <linux/slab.h> -#include "../../uwb.h" -#include "i1480-dfu.h" - -/* - * Descriptor for a continuous segment of MAC fw data - */ -struct fw_hdr { - unsigned long address; - size_t length; - const u32 *bin; - struct fw_hdr *next; -}; - - -/* Free a chain of firmware headers */ -static -void fw_hdrs_free(struct fw_hdr *hdr) -{ - struct fw_hdr *next; - - while (hdr) { - next = hdr->next; - kfree(hdr); - hdr = next; - } -} - - -/* Fill a firmware header descriptor from a memory buffer */ -static -int fw_hdr_load(struct i1480 *i1480, struct fw_hdr *hdr, unsigned hdr_cnt, - const char *_data, const u32 *data_itr, const u32 *data_top) -{ - size_t hdr_offset = (const char *) data_itr - _data; - size_t remaining_size = (void *) data_top - (void *) data_itr; - if (data_itr + 2 > data_top) { - dev_err(i1480->dev, "fw hdr #%u/%zu: EOF reached in header at " - "offset %zu, limit %zu\n", - hdr_cnt, hdr_offset, - (const char *) data_itr + 2 - _data, - (const char *) data_top - _data); - return -EINVAL; - } - hdr->next = NULL; - hdr->address = le32_to_cpu(*data_itr++); - hdr->length = le32_to_cpu(*data_itr++); - hdr->bin = data_itr; - if (hdr->length > remaining_size) { - dev_err(i1480->dev, "fw hdr #%u/%zu: EOF reached in data; " - "chunk too long (%zu bytes), only %zu left\n", - hdr_cnt, hdr_offset, hdr->length, remaining_size); - return -EINVAL; - } - return 0; -} - - -/** - * Get a buffer where the firmware is supposed to be and create a - * chain of headers linking them together. - * - * @phdr: where to place the pointer to the first header (headers link - * to the next via the @hdr->next ptr); need to free the whole - * chain when done. - * - * @_data: Pointer to the data buffer. - * - * @_data_size: Size of the data buffer (bytes); data size has to be a - * multiple of 4. Function will fail if not. - * - * Goes over the whole binary blob; reads the first chunk and creates - * a fw hdr from it (which points to where the data is in @_data and - * the length of the chunk); then goes on to the next chunk until - * done. Each header is linked to the next. - */ -static -int fw_hdrs_load(struct i1480 *i1480, struct fw_hdr **phdr, - const char *_data, size_t data_size) -{ - int result; - unsigned hdr_cnt = 0; - u32 *data = (u32 *) _data, *data_itr, *data_top; - struct fw_hdr *hdr, **prev_hdr = phdr; - - result = -EINVAL; - /* Check size is ok and pointer is aligned */ - if (data_size % sizeof(u32) != 0) - goto error; - if ((unsigned long) _data % sizeof(u16) != 0) - goto error; - *phdr = NULL; - data_itr = data; - data_top = (u32 *) (_data + data_size); - while (data_itr < data_top) { - result = -ENOMEM; - hdr = kmalloc(sizeof(*hdr), GFP_KERNEL); - if (hdr == NULL) { - dev_err(i1480->dev, "Cannot allocate fw header " - "for chunk #%u\n", hdr_cnt); - goto error_alloc; - } - result = fw_hdr_load(i1480, hdr, hdr_cnt, - _data, data_itr, data_top); - if (result < 0) - goto error_load; - data_itr += 2 + hdr->length; - *prev_hdr = hdr; - prev_hdr = &hdr->next; - hdr_cnt++; - }; - *prev_hdr = NULL; - return 0; - -error_load: - kfree(hdr); -error_alloc: - fw_hdrs_free(*phdr); -error: - return result; -} - - -/** - * Compares a chunk of fw with one in the devices's memory - * - * @i1480: Device instance - * @hdr: Pointer to the firmware chunk - * @returns: 0 if equal, < 0 errno on error. If > 0, it is the offset - * where the difference was found (plus one). - * - * Kind of dirty and simplistic, but does the trick in both the PCI - * and USB version. We do a quick[er] memcmp(), and if it fails, we do - * a byte-by-byte to find the offset. - */ -static -ssize_t i1480_fw_cmp(struct i1480 *i1480, struct fw_hdr *hdr) -{ - ssize_t result = 0; - u32 src_itr = 0, cnt; - size_t size = hdr->length*sizeof(hdr->bin[0]); - size_t chunk_size; - u8 *bin = (u8 *) hdr->bin; - - while (size > 0) { - chunk_size = size < i1480->buf_size ? size : i1480->buf_size; - result = i1480->read(i1480, hdr->address + src_itr, chunk_size); - if (result < 0) { - dev_err(i1480->dev, "error reading for verification: " - "%zd\n", result); - goto error; - } - if (memcmp(i1480->cmd_buf, bin + src_itr, result)) { - u8 *buf = i1480->cmd_buf; - for (cnt = 0; cnt < result; cnt++) - if (bin[src_itr + cnt] != buf[cnt]) { - dev_err(i1480->dev, "byte failed at " - "src_itr %u cnt %u [0x%02x " - "vs 0x%02x]\n", src_itr, cnt, - bin[src_itr + cnt], buf[cnt]); - result = src_itr + cnt + 1; - goto cmp_failed; - } - } - src_itr += result; - size -= result; - } - result = 0; -error: -cmp_failed: - return result; -} - - -/** - * Writes firmware headers to the device. - * - * @prd: PRD instance - * @hdr: Processed firmware - * @returns: 0 if ok, < 0 errno on error. - */ -static -int mac_fw_hdrs_push(struct i1480 *i1480, struct fw_hdr *hdr, - const char *fw_name, const char *fw_tag) -{ - struct device *dev = i1480->dev; - ssize_t result = 0; - struct fw_hdr *hdr_itr; - int verif_retry_count; - - /* Now, header by header, push them to the hw */ - for (hdr_itr = hdr; hdr_itr != NULL; hdr_itr = hdr_itr->next) { - verif_retry_count = 0; -retry: - dev_dbg(dev, "fw chunk (%zu @ 0x%08lx)\n", - hdr_itr->length * sizeof(hdr_itr->bin[0]), - hdr_itr->address); - result = i1480->write(i1480, hdr_itr->address, hdr_itr->bin, - hdr_itr->length*sizeof(hdr_itr->bin[0])); - if (result < 0) { - dev_err(dev, "%s fw '%s': write failed (%zuB @ 0x%lx):" - " %zd\n", fw_tag, fw_name, - hdr_itr->length * sizeof(hdr_itr->bin[0]), - hdr_itr->address, result); - break; - } - result = i1480_fw_cmp(i1480, hdr_itr); - if (result < 0) { - dev_err(dev, "%s fw '%s': verification read " - "failed (%zuB @ 0x%lx): %zd\n", - fw_tag, fw_name, - hdr_itr->length * sizeof(hdr_itr->bin[0]), - hdr_itr->address, result); - break; - } - if (result > 0) { /* Offset where it failed + 1 */ - result--; - dev_err(dev, "%s fw '%s': WARNING: verification " - "failed at 0x%lx: retrying\n", - fw_tag, fw_name, hdr_itr->address + result); - if (++verif_retry_count < 3) - goto retry; /* write this block again! */ - dev_err(dev, "%s fw '%s': verification failed at 0x%lx: " - "tried %d times\n", fw_tag, fw_name, - hdr_itr->address + result, verif_retry_count); - result = -EINVAL; - break; - } - } - return result; -} - - -/** Puts the device in firmware upload mode.*/ -static -int mac_fw_upload_enable(struct i1480 *i1480) -{ - int result; - u32 reg = 0x800000c0; - u32 *buffer = (u32 *)i1480->cmd_buf; - - if (i1480->hw_rev > 1) - reg = 0x8000d0d4; - result = i1480->read(i1480, reg, sizeof(u32)); - if (result < 0) - goto error_cmd; - *buffer &= ~i1480_FW_UPLOAD_MODE_MASK; - result = i1480->write(i1480, reg, buffer, sizeof(u32)); - if (result < 0) - goto error_cmd; - return 0; -error_cmd: - dev_err(i1480->dev, "can't enable fw upload mode: %d\n", result); - return result; -} - - -/** Gets the device out of firmware upload mode. */ -static -int mac_fw_upload_disable(struct i1480 *i1480) -{ - int result; - u32 reg = 0x800000c0; - u32 *buffer = (u32 *)i1480->cmd_buf; - - if (i1480->hw_rev > 1) - reg = 0x8000d0d4; - result = i1480->read(i1480, reg, sizeof(u32)); - if (result < 0) - goto error_cmd; - *buffer |= i1480_FW_UPLOAD_MODE_MASK; - result = i1480->write(i1480, reg, buffer, sizeof(u32)); - if (result < 0) - goto error_cmd; - return 0; -error_cmd: - dev_err(i1480->dev, "can't disable fw upload mode: %d\n", result); - return result; -} - - - -/** - * Generic function for uploading a MAC firmware. - * - * @i1480: Device instance - * @fw_name: Name of firmware file to upload. - * @fw_tag: Name of the firmware type (for messages) - * [eg: MAC, PRE] - * @do_wait: Wait for device to emit initialization done message (0 - * for PRE fws, 1 for MAC fws). - * @returns: 0 if ok, < 0 errno on error. - */ -static -int __mac_fw_upload(struct i1480 *i1480, const char *fw_name, - const char *fw_tag) -{ - int result; - const struct firmware *fw; - struct fw_hdr *fw_hdrs; - - result = request_firmware(&fw, fw_name, i1480->dev); - if (result < 0) /* Up to caller to complain on -ENOENT */ - goto out; - result = fw_hdrs_load(i1480, &fw_hdrs, fw->data, fw->size); - if (result < 0) { - dev_err(i1480->dev, "%s fw '%s': failed to parse firmware " - "file: %d\n", fw_tag, fw_name, result); - goto out_release; - } - result = mac_fw_upload_enable(i1480); - if (result < 0) - goto out_hdrs_release; - result = mac_fw_hdrs_push(i1480, fw_hdrs, fw_name, fw_tag); - mac_fw_upload_disable(i1480); -out_hdrs_release: - if (result >= 0) - dev_info(i1480->dev, "%s fw '%s': uploaded\n", fw_tag, fw_name); - else - dev_err(i1480->dev, "%s fw '%s': failed to upload (%d), " - "power cycle device\n", fw_tag, fw_name, result); - fw_hdrs_free(fw_hdrs); -out_release: - release_firmware(fw); -out: - return result; -} - - -/** - * Upload a pre-PHY firmware - * - */ -int i1480_pre_fw_upload(struct i1480 *i1480) -{ - int result; - result = __mac_fw_upload(i1480, i1480->pre_fw_name, "PRE"); - if (result == 0) - msleep(400); - return result; -} - - -/** - * Reset a the MAC and PHY - * - * @i1480: Device's instance - * @returns: 0 if ok, < 0 errno code on error - * - * We put the command on kmalloc'ed memory as some arches cannot do - * USB from the stack. The reply event is copied from an stage buffer, - * so it can be in the stack. See WUSB1.0[8.6.2.4] for more details. - * - * We issue the reset to make sure the UWB controller reinits the PHY; - * this way we can now if the PHY init went ok. - */ -static -int i1480_cmd_reset(struct i1480 *i1480) -{ - int result; - struct uwb_rccb *cmd = (void *) i1480->cmd_buf; - struct i1480_evt_reset { - struct uwb_rceb rceb; - u8 bResultCode; - } __attribute__((packed)) *reply = (void *) i1480->evt_buf; - - result = -ENOMEM; - cmd->bCommandType = UWB_RC_CET_GENERAL; - cmd->wCommand = cpu_to_le16(UWB_RC_CMD_RESET); - reply->rceb.bEventType = UWB_RC_CET_GENERAL; - reply->rceb.wEvent = UWB_RC_CMD_RESET; - result = i1480_cmd(i1480, "RESET", sizeof(*cmd), sizeof(*reply)); - if (result < 0) - goto out; - if (reply->bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(i1480->dev, "RESET: command execution failed: %u\n", - reply->bResultCode); - result = -EIO; - } -out: - return result; - -} - - -/* Wait for the MAC FW to start running */ -static -int i1480_fw_is_running_q(struct i1480 *i1480) -{ - int cnt = 0; - int result; - u32 *val = (u32 *) i1480->cmd_buf; - - for (cnt = 0; cnt < 10; cnt++) { - msleep(100); - result = i1480->read(i1480, 0x80080000, 4); - if (result < 0) { - dev_err(i1480->dev, "Can't read 0x8008000: %d\n", result); - goto out; - } - if (*val == 0x55555555UL) /* fw running? cool */ - goto out; - } - dev_err(i1480->dev, "Timed out waiting for fw to start\n"); - result = -ETIMEDOUT; -out: - return result; - -} - - -/** - * Upload MAC firmware, wait for it to start - * - * @i1480: Device instance - * @fw_name: Name of the file that contains the firmware - * - * This has to be called after the pre fw has been uploaded (if - * there is any). - */ -int i1480_mac_fw_upload(struct i1480 *i1480) -{ - int result = 0, deprecated_name = 0; - struct i1480_rceb *rcebe = (void *) i1480->evt_buf; - - result = __mac_fw_upload(i1480, i1480->mac_fw_name, "MAC"); - if (result == -ENOENT) { - result = __mac_fw_upload(i1480, i1480->mac_fw_name_deprecate, - "MAC"); - deprecated_name = 1; - } - if (result < 0) - return result; - if (deprecated_name == 1) - dev_warn(i1480->dev, - "WARNING: firmware file name %s is deprecated, " - "please rename to %s\n", - i1480->mac_fw_name_deprecate, i1480->mac_fw_name); - result = i1480_fw_is_running_q(i1480); - if (result < 0) - goto error_fw_not_running; - result = i1480->rc_setup ? i1480->rc_setup(i1480) : 0; - if (result < 0) { - dev_err(i1480->dev, "Cannot setup after MAC fw upload: %d\n", - result); - goto error_setup; - } - result = i1480->wait_init_done(i1480); /* wait init'on */ - if (result < 0) { - dev_err(i1480->dev, "MAC fw '%s': Initialization timed out " - "(%d)\n", i1480->mac_fw_name, result); - goto error_init_timeout; - } - /* verify we got the right initialization done event */ - if (i1480->evt_result != sizeof(*rcebe)) { - dev_err(i1480->dev, "MAC fw '%s': initialization event returns " - "wrong size (%zu bytes vs %zu needed)\n", - i1480->mac_fw_name, i1480->evt_result, sizeof(*rcebe)); - goto error_size; - } - result = -EIO; - if (i1480_rceb_check(i1480, &rcebe->rceb, NULL, 0, i1480_CET_VS1, - i1480_EVT_RM_INIT_DONE) < 0) { - dev_err(i1480->dev, "wrong initialization event 0x%02x/%04x/%02x " - "received; expected 0x%02x/%04x/00\n", - rcebe->rceb.bEventType, le16_to_cpu(rcebe->rceb.wEvent), - rcebe->rceb.bEventContext, i1480_CET_VS1, - i1480_EVT_RM_INIT_DONE); - goto error_init_timeout; - } - result = i1480_cmd_reset(i1480); - if (result < 0) - dev_err(i1480->dev, "MAC fw '%s': MBOA reset failed (%d)\n", - i1480->mac_fw_name, result); -error_fw_not_running: -error_init_timeout: -error_size: -error_setup: - return result; -} diff --git a/drivers/staging/uwb/i1480/dfu/phy.c b/drivers/staging/uwb/i1480/dfu/phy.c deleted file mode 100644 index 13512c7dda0b..000000000000 --- a/drivers/staging/uwb/i1480/dfu/phy.c +++ /dev/null @@ -1,190 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Intel Wireless UWB Link 1480 - * PHY parameters upload - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Code for uploading the PHY parameters to the PHY through the UWB - * Radio Control interface. - * - * We just send the data through the MPI interface using HWA-like - * commands and then reset the PHY to make sure it is ok. - */ -#include <linux/delay.h> -#include <linux/device.h> -#include <linux/firmware.h> -#include "../../../wusbcore/include/wusb.h" -#include "i1480-dfu.h" - - -/** - * Write a value array to an address of the MPI interface - * - * @i1480: Device descriptor - * @data: Data array to write - * @size: Size of the data array - * @returns: 0 if ok, < 0 errno code on error. - * - * The data array is organized into pairs: - * - * ADDRESS VALUE - * - * ADDRESS is BE 16 bit unsigned, VALUE 8 bit unsigned. Size thus has - * to be a multiple of three. - */ -static -int i1480_mpi_write(struct i1480 *i1480, const void *data, size_t size) -{ - int result; - struct i1480_cmd_mpi_write *cmd = i1480->cmd_buf; - struct i1480_evt_confirm *reply = i1480->evt_buf; - - BUG_ON(size > 480); - result = -ENOMEM; - cmd->rccb.bCommandType = i1480_CET_VS1; - cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_WRITE); - cmd->size = cpu_to_le16(size); - memcpy(cmd->data, data, size); - reply->rceb.bEventType = i1480_CET_VS1; - reply->rceb.wEvent = i1480_CMD_MPI_WRITE; - result = i1480_cmd(i1480, "MPI-WRITE", sizeof(*cmd) + size, sizeof(*reply)); - if (result < 0) - goto out; - if (reply->bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(i1480->dev, "MPI-WRITE: command execution failed: %d\n", - reply->bResultCode); - result = -EIO; - } -out: - return result; -} - - -/** - * Read a value array to from an address of the MPI interface - * - * @i1480: Device descriptor - * @data: where to place the read array - * @srcaddr: Where to read from - * @size: Size of the data read array - * @returns: 0 if ok, < 0 errno code on error. - * - * The command data array is organized into pairs ADDR0 ADDR1..., and - * the returned data in ADDR0 VALUE0 ADDR1 VALUE1... - * - * We generate the command array to be a sequential read and then - * rearrange the result. - * - * We use the i1480->cmd_buf for the command, i1480->evt_buf for the reply. - * - * As the reply has to fit in 512 bytes (i1480->evt_buffer), the max amount - * of values we can read is (512 - sizeof(*reply)) / 3 - */ -static -int i1480_mpi_read(struct i1480 *i1480, u8 *data, u16 srcaddr, size_t size) -{ - int result; - struct i1480_cmd_mpi_read *cmd = i1480->cmd_buf; - struct i1480_evt_mpi_read *reply = i1480->evt_buf; - unsigned cnt; - - memset(i1480->cmd_buf, 0x69, 512); - memset(i1480->evt_buf, 0x69, 512); - - BUG_ON(size > (i1480->buf_size - sizeof(*reply)) / 3); - result = -ENOMEM; - cmd->rccb.bCommandType = i1480_CET_VS1; - cmd->rccb.wCommand = cpu_to_le16(i1480_CMD_MPI_READ); - cmd->size = cpu_to_le16(3*size); - for (cnt = 0; cnt < size; cnt++) { - cmd->data[cnt].page = (srcaddr + cnt) >> 8; - cmd->data[cnt].offset = (srcaddr + cnt) & 0xff; - } - reply->rceb.bEventType = i1480_CET_VS1; - reply->rceb.wEvent = i1480_CMD_MPI_READ; - result = i1480_cmd(i1480, "MPI-READ", sizeof(*cmd) + 2*size, - sizeof(*reply) + 3*size); - if (result < 0) - goto out; - if (reply->bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(i1480->dev, "MPI-READ: command execution failed: %d\n", - reply->bResultCode); - result = -EIO; - goto out; - } - for (cnt = 0; cnt < size; cnt++) { - if (reply->data[cnt].page != (srcaddr + cnt) >> 8) - dev_err(i1480->dev, "MPI-READ: page inconsistency at " - "index %u: expected 0x%02x, got 0x%02x\n", cnt, - (srcaddr + cnt) >> 8, reply->data[cnt].page); - if (reply->data[cnt].offset != ((srcaddr + cnt) & 0x00ff)) - dev_err(i1480->dev, "MPI-READ: offset inconsistency at " - "index %u: expected 0x%02x, got 0x%02x\n", cnt, - (srcaddr + cnt) & 0x00ff, - reply->data[cnt].offset); - data[cnt] = reply->data[cnt].value; - } - result = 0; -out: - return result; -} - - -/** - * Upload a PHY firmware, wait for it to start - * - * @i1480: Device instance - * @fw_name: Name of the file that contains the firmware - * - * We assume the MAC fw is up and running. This means we can use the - * MPI interface to write the PHY firmware. Once done, we issue an - * MBOA Reset, which will force the MAC to reset and reinitialize the - * PHY. If that works, we are ready to go. - * - * Max packet size for the MPI write is 512, so the max buffer is 480 - * (which gives us 160 byte triads of MSB, LSB and VAL for the data). - */ -int i1480_phy_fw_upload(struct i1480 *i1480) -{ - int result; - const struct firmware *fw; - const char *data_itr, *data_top; - const size_t MAX_BLK_SIZE = 480; /* 160 triads */ - size_t data_size; - u8 phy_stat; - - result = request_firmware(&fw, i1480->phy_fw_name, i1480->dev); - if (result < 0) - goto out; - /* Loop writing data in chunks as big as possible until done. */ - for (data_itr = fw->data, data_top = data_itr + fw->size; - data_itr < data_top; data_itr += MAX_BLK_SIZE) { - data_size = min(MAX_BLK_SIZE, (size_t) (data_top - data_itr)); - result = i1480_mpi_write(i1480, data_itr, data_size); - if (result < 0) - goto error_mpi_write; - } - /* Read MPI page 0, offset 6; if 0, PHY was initialized correctly. */ - result = i1480_mpi_read(i1480, &phy_stat, 0x0006, 1); - if (result < 0) { - dev_err(i1480->dev, "PHY: can't get status: %d\n", result); - goto error_mpi_status; - } - if (phy_stat != 0) { - result = -ENODEV; - dev_info(i1480->dev, "error, PHY not ready: %u\n", phy_stat); - goto error_phy_status; - } - dev_info(i1480->dev, "PHY fw '%s': uploaded\n", i1480->phy_fw_name); -error_phy_status: -error_mpi_status: -error_mpi_write: - release_firmware(fw); - if (result < 0) - dev_err(i1480->dev, "PHY fw '%s': failed to upload (%d), " - "power cycle device\n", i1480->phy_fw_name, result); -out: - return result; -} diff --git a/drivers/staging/uwb/i1480/dfu/usb.c b/drivers/staging/uwb/i1480/dfu/usb.c deleted file mode 100644 index d41086bdd783..000000000000 --- a/drivers/staging/uwb/i1480/dfu/usb.c +++ /dev/null @@ -1,448 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Intel Wireless UWB Link 1480 - * USB SKU firmware upload implementation - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This driver will prepare the i1480 device to behave as a real - * Wireless USB HWA adaptor by uploading the firmware. - * - * When the device is connected or driver is loaded, i1480_usb_probe() - * is called--this will allocate and initialize the device structure, - * fill in the pointers to the common functions (read, write, - * wait_init_done and cmd for HWA command execution) and once that is - * done, call the common firmware uploading routine. Then clean up and - * return -ENODEV, as we don't attach to the device. - * - * The rest are the basic ops we implement that the fw upload code - * uses to do its job. All the ops in the common code are i1480->NAME, - * the functions are i1480_usb_NAME(). - */ -#include <linux/module.h> -#include <linux/usb.h> -#include <linux/interrupt.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include "../../uwb.h" -#include "../../../wusbcore/include/wusb.h" -#include "../../../wusbcore/include/wusb-wa.h" -#include "i1480-dfu.h" - -struct i1480_usb { - struct i1480 i1480; - struct usb_device *usb_dev; - struct usb_interface *usb_iface; - struct urb *neep_urb; /* URB for reading from EP1 */ -}; - - -static -void i1480_usb_init(struct i1480_usb *i1480_usb) -{ - i1480_init(&i1480_usb->i1480); -} - - -static -int i1480_usb_create(struct i1480_usb *i1480_usb, struct usb_interface *iface) -{ - struct usb_device *usb_dev = interface_to_usbdev(iface); - int result = -ENOMEM; - - i1480_usb->usb_dev = usb_get_dev(usb_dev); /* bind the USB device */ - i1480_usb->usb_iface = usb_get_intf(iface); - usb_set_intfdata(iface, i1480_usb); /* Bind the driver to iface0 */ - i1480_usb->neep_urb = usb_alloc_urb(0, GFP_KERNEL); - if (i1480_usb->neep_urb == NULL) - goto error; - return 0; - -error: - usb_set_intfdata(iface, NULL); - usb_put_intf(iface); - usb_put_dev(usb_dev); - return result; -} - - -static -void i1480_usb_destroy(struct i1480_usb *i1480_usb) -{ - usb_kill_urb(i1480_usb->neep_urb); - usb_free_urb(i1480_usb->neep_urb); - usb_set_intfdata(i1480_usb->usb_iface, NULL); - usb_put_intf(i1480_usb->usb_iface); - usb_put_dev(i1480_usb->usb_dev); -} - - -/** - * Write a buffer to a memory address in the i1480 device - * - * @i1480: i1480 instance - * @memory_address: - * Address where to write the data buffer to. - * @buffer: Buffer to the data - * @size: Size of the buffer [has to be < 512]. - * @returns: 0 if ok, < 0 errno code on error. - * - * Data buffers to USB cannot be on the stack or in vmalloc'ed areas, - * so we copy it to the local i1480 buffer before proceeding. In any - * case, we have a max size we can send. - */ -static -int i1480_usb_write(struct i1480 *i1480, u32 memory_address, - const void *buffer, size_t size) -{ - int result = 0; - struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); - size_t buffer_size, itr = 0; - - BUG_ON(size & 0x3); /* Needs to be a multiple of 4 */ - while (size > 0) { - buffer_size = size < i1480->buf_size ? size : i1480->buf_size; - memcpy(i1480->cmd_buf, buffer + itr, buffer_size); - result = usb_control_msg( - i1480_usb->usb_dev, usb_sndctrlpipe(i1480_usb->usb_dev, 0), - 0xf0, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - memory_address, (memory_address >> 16), - i1480->cmd_buf, buffer_size, 100 /* FIXME: arbitrary */); - if (result < 0) - break; - itr += result; - memory_address += result; - size -= result; - } - return result; -} - - -/** - * Read a block [max size 512] of the device's memory to @i1480's buffer. - * - * @i1480: i1480 instance - * @memory_address: - * Address where to read from. - * @size: Size to read. Smaller than or equal to 512. - * @returns: >= 0 number of bytes written if ok, < 0 errno code on error. - * - * NOTE: if the memory address or block is incorrect, you might get a - * stall or a different memory read. Caller has to verify the - * memory address and size passed back in the @neh structure. - */ -static -int i1480_usb_read(struct i1480 *i1480, u32 addr, size_t size) -{ - ssize_t result = 0, bytes = 0; - size_t itr, read_size = i1480->buf_size; - struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); - - BUG_ON(size > i1480->buf_size); - BUG_ON(size & 0x3); /* Needs to be a multiple of 4 */ - BUG_ON(read_size > 512); - - if (addr >= 0x8000d200 && addr < 0x8000d400) /* Yeah, HW quirk */ - read_size = 4; - - for (itr = 0; itr < size; itr += read_size) { - size_t itr_addr = addr + itr; - size_t itr_size = min(read_size, size - itr); - result = usb_control_msg( - i1480_usb->usb_dev, usb_rcvctrlpipe(i1480_usb->usb_dev, 0), - 0xf0, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - itr_addr, (itr_addr >> 16), - i1480->cmd_buf + itr, itr_size, - 100 /* FIXME: arbitrary */); - if (result < 0) { - dev_err(i1480->dev, "%s: USB read error: %zd\n", - __func__, result); - goto out; - } - if (result != itr_size) { - result = -EIO; - dev_err(i1480->dev, - "%s: partial read got only %zu bytes vs %zu expected\n", - __func__, result, itr_size); - goto out; - } - bytes += result; - } - result = bytes; -out: - return result; -} - - -/** - * Callback for reads on the notification/event endpoint - * - * Just enables the completion read handler. - */ -static -void i1480_usb_neep_cb(struct urb *urb) -{ - struct i1480 *i1480 = urb->context; - struct device *dev = i1480->dev; - - switch (urb->status) { - case 0: - break; - case -ECONNRESET: /* Not an error, but a controlled situation; */ - case -ENOENT: /* (we killed the URB)...so, no broadcast */ - dev_dbg(dev, "NEEP: reset/noent %d\n", urb->status); - break; - case -ESHUTDOWN: /* going away! */ - dev_dbg(dev, "NEEP: down %d\n", urb->status); - break; - default: - dev_err(dev, "NEEP: unknown status %d\n", urb->status); - break; - } - i1480->evt_result = urb->actual_length; - complete(&i1480->evt_complete); - return; -} - - -/** - * Wait for the MAC FW to initialize - * - * MAC FW sends a 0xfd/0101/00 notification to EP1 when done - * initializing. Get that notification into i1480->evt_buf; upper layer - * will verify it. - * - * Set i1480->evt_result with the result of getting the event or its - * size (if successful). - * - * Delivers the data directly to i1480->evt_buf - */ -static -int i1480_usb_wait_init_done(struct i1480 *i1480) -{ - int result; - struct device *dev = i1480->dev; - struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); - struct usb_endpoint_descriptor *epd; - - init_completion(&i1480->evt_complete); - i1480->evt_result = -EINPROGRESS; - epd = &i1480_usb->usb_iface->cur_altsetting->endpoint[0].desc; - usb_fill_int_urb(i1480_usb->neep_urb, i1480_usb->usb_dev, - usb_rcvintpipe(i1480_usb->usb_dev, epd->bEndpointAddress), - i1480->evt_buf, i1480->buf_size, - i1480_usb_neep_cb, i1480, epd->bInterval); - result = usb_submit_urb(i1480_usb->neep_urb, GFP_KERNEL); - if (result < 0) { - dev_err(dev, "init done: cannot submit NEEP read: %d\n", - result); - goto error_submit; - } - /* Wait for the USB callback to get the data */ - result = wait_for_completion_interruptible_timeout( - &i1480->evt_complete, HZ); - if (result <= 0) { - result = result == 0 ? -ETIMEDOUT : result; - goto error_wait; - } - usb_kill_urb(i1480_usb->neep_urb); - return 0; - -error_wait: - usb_kill_urb(i1480_usb->neep_urb); -error_submit: - i1480->evt_result = result; - return result; -} - - -/** - * Generic function for issuing commands to the i1480 - * - * @i1480: i1480 instance - * @cmd_name: Name of the command (for error messages) - * @cmd: Pointer to command buffer - * @cmd_size: Size of the command buffer - * @reply: Buffer for the reply event - * @reply_size: Expected size back (including RCEB); the reply buffer - * is assumed to be as big as this. - * @returns: >= 0 size of the returned event data if ok, - * < 0 errno code on error. - * - * Arms the NE handle, issues the command to the device and checks the - * basics of the reply event. - */ -static -int i1480_usb_cmd(struct i1480 *i1480, const char *cmd_name, size_t cmd_size) -{ - int result; - struct device *dev = i1480->dev; - struct i1480_usb *i1480_usb = container_of(i1480, struct i1480_usb, i1480); - struct usb_endpoint_descriptor *epd; - struct uwb_rccb *cmd = i1480->cmd_buf; - u8 iface_no; - - /* Post a read on the notification & event endpoint */ - iface_no = i1480_usb->usb_iface->cur_altsetting->desc.bInterfaceNumber; - epd = &i1480_usb->usb_iface->cur_altsetting->endpoint[0].desc; - usb_fill_int_urb( - i1480_usb->neep_urb, i1480_usb->usb_dev, - usb_rcvintpipe(i1480_usb->usb_dev, epd->bEndpointAddress), - i1480->evt_buf, i1480->buf_size, - i1480_usb_neep_cb, i1480, epd->bInterval); - result = usb_submit_urb(i1480_usb->neep_urb, GFP_KERNEL); - if (result < 0) { - dev_err(dev, "%s: cannot submit NEEP read: %d\n", - cmd_name, result); - goto error_submit_ep1; - } - /* Now post the command on EP0 */ - result = usb_control_msg( - i1480_usb->usb_dev, usb_sndctrlpipe(i1480_usb->usb_dev, 0), - WA_EXEC_RC_CMD, - USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, - 0, iface_no, - cmd, cmd_size, - 100 /* FIXME: this is totally arbitrary */); - if (result < 0) { - dev_err(dev, "%s: control request failed: %d\n", - cmd_name, result); - goto error_submit_ep0; - } - return result; - -error_submit_ep0: - usb_kill_urb(i1480_usb->neep_urb); -error_submit_ep1: - return result; -} - - -/* - * Probe a i1480 device for uploading firmware. - * - * We attach only to interface #0, which is the radio control interface. - */ -static -int i1480_usb_probe(struct usb_interface *iface, const struct usb_device_id *id) -{ - struct usb_device *udev = interface_to_usbdev(iface); - struct i1480_usb *i1480_usb; - struct i1480 *i1480; - struct device *dev = &iface->dev; - int result; - - result = -ENODEV; - if (iface->cur_altsetting->desc.bInterfaceNumber != 0) { - dev_dbg(dev, "not attaching to iface %d\n", - iface->cur_altsetting->desc.bInterfaceNumber); - goto error; - } - if (iface->num_altsetting > 1 && - le16_to_cpu(udev->descriptor.idProduct) == 0xbabe) { - /* Need altsetting #1 [HW QUIRK] or EP1 won't work */ - result = usb_set_interface(interface_to_usbdev(iface), 0, 1); - if (result < 0) - dev_warn(dev, - "can't set altsetting 1 on iface 0: %d\n", - result); - } - - if (iface->cur_altsetting->desc.bNumEndpoints < 1) - return -ENODEV; - - result = -ENOMEM; - i1480_usb = kzalloc(sizeof(*i1480_usb), GFP_KERNEL); - if (i1480_usb == NULL) { - dev_err(dev, "Unable to allocate instance\n"); - goto error; - } - i1480_usb_init(i1480_usb); - - i1480 = &i1480_usb->i1480; - i1480->buf_size = 512; - i1480->cmd_buf = kmalloc_array(2, i1480->buf_size, GFP_KERNEL); - if (i1480->cmd_buf == NULL) { - dev_err(dev, "Cannot allocate transfer buffers\n"); - result = -ENOMEM; - goto error_buf_alloc; - } - i1480->evt_buf = i1480->cmd_buf + i1480->buf_size; - - result = i1480_usb_create(i1480_usb, iface); - if (result < 0) { - dev_err(dev, "Cannot create instance: %d\n", result); - goto error_create; - } - - /* setup the fops and upload the firmware */ - i1480->pre_fw_name = "i1480-pre-phy-0.0.bin"; - i1480->mac_fw_name = "i1480-usb-0.0.bin"; - i1480->mac_fw_name_deprecate = "ptc-0.0.bin"; - i1480->phy_fw_name = "i1480-phy-0.0.bin"; - i1480->dev = &iface->dev; - i1480->write = i1480_usb_write; - i1480->read = i1480_usb_read; - i1480->rc_setup = NULL; - i1480->wait_init_done = i1480_usb_wait_init_done; - i1480->cmd = i1480_usb_cmd; - - result = i1480_fw_upload(&i1480_usb->i1480); /* the real thing */ - if (result >= 0) { - usb_reset_device(i1480_usb->usb_dev); - result = -ENODEV; /* we don't want to bind to the iface */ - } - i1480_usb_destroy(i1480_usb); -error_create: - kfree(i1480->cmd_buf); -error_buf_alloc: - kfree(i1480_usb); -error: - return result; -} - -MODULE_FIRMWARE("i1480-pre-phy-0.0.bin"); -MODULE_FIRMWARE("i1480-usb-0.0.bin"); -MODULE_FIRMWARE("i1480-phy-0.0.bin"); - -#define i1480_USB_DEV(v, p) \ -{ \ - .match_flags = USB_DEVICE_ID_MATCH_DEVICE \ - | USB_DEVICE_ID_MATCH_DEV_INFO \ - | USB_DEVICE_ID_MATCH_INT_INFO, \ - .idVendor = (v), \ - .idProduct = (p), \ - .bDeviceClass = 0xff, \ - .bDeviceSubClass = 0xff, \ - .bDeviceProtocol = 0xff, \ - .bInterfaceClass = 0xff, \ - .bInterfaceSubClass = 0xff, \ - .bInterfaceProtocol = 0xff, \ -} - - -/** USB device ID's that we handle */ -static const struct usb_device_id i1480_usb_id_table[] = { - i1480_USB_DEV(0x8086, 0xdf3b), - i1480_USB_DEV(0x15a9, 0x0005), - i1480_USB_DEV(0x07d1, 0x3802), - i1480_USB_DEV(0x050d, 0x305a), - i1480_USB_DEV(0x3495, 0x3007), - {}, -}; -MODULE_DEVICE_TABLE(usb, i1480_usb_id_table); - - -static struct usb_driver i1480_dfu_driver = { - .name = "i1480-dfu-usb", - .id_table = i1480_usb_id_table, - .probe = i1480_usb_probe, - .disconnect = NULL, -}; - -module_usb_driver(i1480_dfu_driver); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Intel Wireless UWB Link 1480 firmware uploader for USB"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/uwb/i1480/i1480-est.c b/drivers/staging/uwb/i1480/i1480-est.c deleted file mode 100644 index 106e0a44b138..000000000000 --- a/drivers/staging/uwb/i1480/i1480-est.c +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Intel Wireless UWB Link 1480 - * Event Size tables for Wired Adaptors - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ - -#include <linux/init.h> -#include <linux/module.h> -#include <linux/usb.h> -#include "../uwb.h" -#include "dfu/i1480-dfu.h" - - -/** Event size table for wEvents 0x00XX */ -static struct uwb_est_entry i1480_est_fd00[] = { - /* Anybody expecting this response has to use - * neh->extra_size to specify the real size that will - * come back. */ - [i1480_EVT_CONFIRM] = { .size = sizeof(struct i1480_evt_confirm) }, - [i1480_CMD_SET_IP_MAS] = { .size = sizeof(struct i1480_evt_confirm) }, -#ifdef i1480_RCEB_EXTENDED - [0x09] = { - .size = sizeof(struct i1480_rceb), - .offset = 1 + offsetof(struct i1480_rceb, wParamLength), - }, -#endif -}; - -/** Event size table for wEvents 0x01XX */ -static struct uwb_est_entry i1480_est_fd01[] = { - [0xff & i1480_EVT_RM_INIT_DONE] = { .size = sizeof(struct i1480_rceb) }, - [0xff & i1480_EVT_DEV_ADD] = { .size = sizeof(struct i1480_rceb) + 9 }, - [0xff & i1480_EVT_DEV_RM] = { .size = sizeof(struct i1480_rceb) + 9 }, - [0xff & i1480_EVT_DEV_ID_CHANGE] = { - .size = sizeof(struct i1480_rceb) + 2 }, -}; - -static int __init i1480_est_init(void) -{ - int result = uwb_est_register(i1480_CET_VS1, 0x00, 0x8086, 0x0c3b, - i1480_est_fd00, - ARRAY_SIZE(i1480_est_fd00)); - if (result < 0) { - printk(KERN_ERR "Can't register EST table fd00: %d\n", result); - return result; - } - result = uwb_est_register(i1480_CET_VS1, 0x01, 0x8086, 0x0c3b, - i1480_est_fd01, ARRAY_SIZE(i1480_est_fd01)); - if (result < 0) { - printk(KERN_ERR "Can't register EST table fd01: %d\n", result); - return result; - } - return 0; -} -module_init(i1480_est_init); - -static void __exit i1480_est_exit(void) -{ - uwb_est_unregister(i1480_CET_VS1, 0x00, 0x8086, 0x0c3b, - i1480_est_fd00, ARRAY_SIZE(i1480_est_fd00)); - uwb_est_unregister(i1480_CET_VS1, 0x01, 0x8086, 0x0c3b, - i1480_est_fd01, ARRAY_SIZE(i1480_est_fd01)); -} -module_exit(i1480_est_exit); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("i1480's Vendor Specific Event Size Tables"); -MODULE_LICENSE("GPL"); - -/** - * USB device ID's that we handle - * - * [so we are loaded when this kind device is connected] - */ -static struct usb_device_id __used i1480_est_id_table[] = { - { USB_DEVICE(0x8086, 0xdf3b), }, - { USB_DEVICE(0x8086, 0x0c3b), }, - { }, -}; -MODULE_DEVICE_TABLE(usb, i1480_est_id_table); diff --git a/drivers/staging/uwb/ie-rcv.c b/drivers/staging/uwb/ie-rcv.c deleted file mode 100644 index 51a4706e0dd3..000000000000 --- a/drivers/staging/uwb/ie-rcv.c +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * IE Received notification handling. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ - -#include <linux/errno.h> -#include <linux/module.h> -#include <linux/device.h> -#include <linux/bitmap.h> -#include "uwb-internal.h" - -/* - * Process an incoming IE Received notification. - */ -int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *evt) -{ - int result = -EINVAL; - struct device *dev = &evt->rc->uwb_dev.dev; - struct uwb_rc_evt_ie_rcv *iercv; - - /* Is there enough data to decode it? */ - if (evt->notif.size < sizeof(*iercv)) { - dev_err(dev, "IE Received notification: Not enough data to " - "decode (%zu vs %zu bytes needed)\n", - evt->notif.size, sizeof(*iercv)); - goto error; - } - iercv = container_of(evt->notif.rceb, struct uwb_rc_evt_ie_rcv, rceb); - - dev_dbg(dev, "IE received, element ID=%d\n", iercv->IEData[0]); - - if (iercv->IEData[0] == UWB_RELINQUISH_REQUEST_IE) { - dev_warn(dev, "unhandled Relinquish Request IE\n"); - } - - return 0; -error: - return result; -} diff --git a/drivers/staging/uwb/ie.c b/drivers/staging/uwb/ie.c deleted file mode 100644 index b11678dd0380..000000000000 --- a/drivers/staging/uwb/ie.c +++ /dev/null @@ -1,366 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Information Element Handling - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * Reinette Chatre <reinette.chatre@intel.com> - * - * FIXME: docs - */ - -#include <linux/slab.h> -#include <linux/export.h> -#include "uwb-internal.h" - -/** - * uwb_ie_next - get the next IE in a buffer - * @ptr: start of the buffer containing the IE data - * @len: length of the buffer - * - * Both @ptr and @len are updated so subsequent calls to uwb_ie_next() - * will get the next IE. - * - * NULL is returned (and @ptr and @len will not be updated) if there - * are no more IEs in the buffer or the buffer is too short. - */ -struct uwb_ie_hdr *uwb_ie_next(void **ptr, size_t *len) -{ - struct uwb_ie_hdr *hdr; - size_t ie_len; - - if (*len < sizeof(struct uwb_ie_hdr)) - return NULL; - - hdr = *ptr; - ie_len = sizeof(struct uwb_ie_hdr) + hdr->length; - - if (*len < ie_len) - return NULL; - - *ptr += ie_len; - *len -= ie_len; - - return hdr; -} -EXPORT_SYMBOL_GPL(uwb_ie_next); - -/** - * uwb_ie_dump_hex - print IEs to a character buffer - * @ies: the IEs to print. - * @len: length of all the IEs. - * @buf: the destination buffer. - * @size: size of @buf. - * - * Returns the number of characters written. - */ -int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len, - char *buf, size_t size) -{ - void *ptr; - const struct uwb_ie_hdr *ie; - int r = 0; - u8 *d; - - ptr = (void *)ies; - for (;;) { - ie = uwb_ie_next(&ptr, &len); - if (!ie) - break; - - r += scnprintf(buf + r, size - r, "%02x %02x", - (unsigned)ie->element_id, - (unsigned)ie->length); - d = (uint8_t *)ie + sizeof(struct uwb_ie_hdr); - while (d != ptr && r < size) - r += scnprintf(buf + r, size - r, " %02x", (unsigned)*d++); - if (r < size) - buf[r++] = '\n'; - }; - - return r; -} - -/** - * Get the IEs that a radio controller is sending in its beacon - * - * @uwb_rc: UWB Radio Controller - * @returns: Size read from the system - * - * We don't need to lock the uwb_rc's mutex because we don't modify - * anything. Once done with the iedata buffer, call - * uwb_rc_ie_release(iedata). Don't call kfree on it. - */ -static -ssize_t uwb_rc_get_ie(struct uwb_rc *uwb_rc, struct uwb_rc_evt_get_ie **pget_ie) -{ - ssize_t result; - struct device *dev = &uwb_rc->uwb_dev.dev; - struct uwb_rccb *cmd = NULL; - struct uwb_rceb *reply = NULL; - struct uwb_rc_evt_get_ie *get_ie; - - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - return -ENOMEM; - - cmd->bCommandType = UWB_RC_CET_GENERAL; - cmd->wCommand = cpu_to_le16(UWB_RC_CMD_GET_IE); - result = uwb_rc_vcmd(uwb_rc, "GET_IE", cmd, sizeof(*cmd), - UWB_RC_CET_GENERAL, UWB_RC_CMD_GET_IE, - &reply); - kfree(cmd); - if (result < 0) - return result; - - get_ie = container_of(reply, struct uwb_rc_evt_get_ie, rceb); - if (result < sizeof(*get_ie)) { - dev_err(dev, "not enough data returned for decoding GET IE " - "(%zu bytes received vs %zu needed)\n", - result, sizeof(*get_ie)); - return -EINVAL; - } else if (result < sizeof(*get_ie) + le16_to_cpu(get_ie->wIELength)) { - dev_err(dev, "not enough data returned for decoding GET IE " - "payload (%zu bytes received vs %zu needed)\n", result, - sizeof(*get_ie) + le16_to_cpu(get_ie->wIELength)); - return -EINVAL; - } - - *pget_ie = get_ie; - return result; -} - - -/** - * Replace all IEs currently being transmitted by a device - * - * @cmd: pointer to the SET-IE command with the IEs to set - * @size: size of @buf - */ -int uwb_rc_set_ie(struct uwb_rc *rc, struct uwb_rc_cmd_set_ie *cmd) -{ - int result; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_evt_set_ie reply; - - reply.rceb.bEventType = UWB_RC_CET_GENERAL; - reply.rceb.wEvent = UWB_RC_CMD_SET_IE; - result = uwb_rc_cmd(rc, "SET-IE", &cmd->rccb, - sizeof(*cmd) + le16_to_cpu(cmd->wIELength), - &reply.rceb, sizeof(reply)); - if (result < 0) - goto error_cmd; - else if (result != sizeof(reply)) { - dev_err(dev, "SET-IE: not enough data to decode reply " - "(%d bytes received vs %zu needed)\n", - result, sizeof(reply)); - result = -EIO; - } else if (reply.bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(dev, "SET-IE: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply.bResultCode), reply.bResultCode); - result = -EIO; - } else - result = 0; -error_cmd: - return result; -} - -/* Cleanup the whole IE management subsystem */ -void uwb_rc_ie_init(struct uwb_rc *uwb_rc) -{ - mutex_init(&uwb_rc->ies_mutex); -} - - -/** - * uwb_rc_ie_setup - setup a radio controller's IE manager - * @uwb_rc: the radio controller. - * - * The current set of IEs are obtained from the hardware with a GET-IE - * command (since the radio controller is not yet beaconing this will - * be just the hardware's MAC and PHY Capability IEs). - * - * Returns 0 on success; -ve on an error. - */ -int uwb_rc_ie_setup(struct uwb_rc *uwb_rc) -{ - struct uwb_rc_evt_get_ie *ie_info = NULL; - int capacity; - - capacity = uwb_rc_get_ie(uwb_rc, &ie_info); - if (capacity < 0) - return capacity; - - mutex_lock(&uwb_rc->ies_mutex); - - uwb_rc->ies = (struct uwb_rc_cmd_set_ie *)ie_info; - uwb_rc->ies->rccb.bCommandType = UWB_RC_CET_GENERAL; - uwb_rc->ies->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SET_IE); - uwb_rc->ies_capacity = capacity; - - mutex_unlock(&uwb_rc->ies_mutex); - - return 0; -} - - -/* Cleanup the whole IE management subsystem */ -void uwb_rc_ie_release(struct uwb_rc *uwb_rc) -{ - kfree(uwb_rc->ies); - uwb_rc->ies = NULL; - uwb_rc->ies_capacity = 0; -} - - -static int uwb_rc_ie_add_one(struct uwb_rc *rc, const struct uwb_ie_hdr *new_ie) -{ - struct uwb_rc_cmd_set_ie *new_ies; - void *ptr, *prev_ie; - struct uwb_ie_hdr *ie; - size_t length, new_ie_len, new_capacity, size, prev_size; - - length = le16_to_cpu(rc->ies->wIELength); - new_ie_len = sizeof(struct uwb_ie_hdr) + new_ie->length; - new_capacity = sizeof(struct uwb_rc_cmd_set_ie) + length + new_ie_len; - - if (new_capacity > rc->ies_capacity) { - new_ies = krealloc(rc->ies, new_capacity, GFP_KERNEL); - if (!new_ies) - return -ENOMEM; - rc->ies = new_ies; - } - - ptr = rc->ies->IEData; - size = length; - for (;;) { - prev_ie = ptr; - prev_size = size; - ie = uwb_ie_next(&ptr, &size); - if (!ie || ie->element_id > new_ie->element_id) - break; - } - - memmove(prev_ie + new_ie_len, prev_ie, prev_size); - memcpy(prev_ie, new_ie, new_ie_len); - rc->ies->wIELength = cpu_to_le16(length + new_ie_len); - - return 0; -} - -/** - * uwb_rc_ie_add - add new IEs to the radio controller's beacon - * @uwb_rc: the radio controller. - * @ies: the buffer containing the new IE or IEs to be added to - * the device's beacon. - * @size: length of all the IEs. - * - * According to WHCI 0.95 [4.13.6] the driver will only receive the RCEB - * after the device sent the first beacon that includes the IEs specified - * in the SET IE command. We thus cannot send this command if the device is - * not beaconing. Instead, a SET IE command will be sent later right after - * we start beaconing. - * - * Setting an IE on the device will overwrite all current IEs in device. So - * we take the current IEs being transmitted by the device, insert the - * new one, and call SET IE with all the IEs needed. - * - * Returns 0 on success; or -ENOMEM. - */ -int uwb_rc_ie_add(struct uwb_rc *uwb_rc, - const struct uwb_ie_hdr *ies, size_t size) -{ - int result = 0; - void *ptr; - const struct uwb_ie_hdr *ie; - - mutex_lock(&uwb_rc->ies_mutex); - - ptr = (void *)ies; - for (;;) { - ie = uwb_ie_next(&ptr, &size); - if (!ie) - break; - - result = uwb_rc_ie_add_one(uwb_rc, ie); - if (result < 0) - break; - } - if (result >= 0) { - if (size == 0) { - if (uwb_rc->beaconing != -1) - result = uwb_rc_set_ie(uwb_rc, uwb_rc->ies); - } else - result = -EINVAL; - } - - mutex_unlock(&uwb_rc->ies_mutex); - - return result; -} -EXPORT_SYMBOL_GPL(uwb_rc_ie_add); - - -/* - * Remove an IE from internal cache - * - * We are dealing with our internal IE cache so no need to verify that the - * IEs are valid (it has been done already). - * - * Should be called with ies_mutex held - * - * We do not break out once an IE is found in the cache. It is currently - * possible to have more than one IE with the same ID included in the - * beacon. We don't reallocate, we just mark the size smaller. - */ -static -void uwb_rc_ie_cache_rm(struct uwb_rc *uwb_rc, enum uwb_ie to_remove) -{ - struct uwb_ie_hdr *ie; - size_t len = le16_to_cpu(uwb_rc->ies->wIELength); - void *ptr; - size_t size; - - ptr = uwb_rc->ies->IEData; - size = len; - for (;;) { - ie = uwb_ie_next(&ptr, &size); - if (!ie) - break; - if (ie->element_id == to_remove) { - len -= sizeof(struct uwb_ie_hdr) + ie->length; - memmove(ie, ptr, size); - ptr = ie; - } - } - uwb_rc->ies->wIELength = cpu_to_le16(len); -} - - -/** - * uwb_rc_ie_rm - remove an IE from the radio controller's beacon - * @uwb_rc: the radio controller. - * @element_id: the element ID of the IE to remove. - * - * Only IEs previously added with uwb_rc_ie_add() may be removed. - * - * Returns 0 on success; or -ve the SET-IE command to the radio - * controller failed. - */ -int uwb_rc_ie_rm(struct uwb_rc *uwb_rc, enum uwb_ie element_id) -{ - int result = 0; - - mutex_lock(&uwb_rc->ies_mutex); - - uwb_rc_ie_cache_rm(uwb_rc, element_id); - - if (uwb_rc->beaconing != -1) - result = uwb_rc_set_ie(uwb_rc, uwb_rc->ies); - - mutex_unlock(&uwb_rc->ies_mutex); - - return result; -} -EXPORT_SYMBOL_GPL(uwb_rc_ie_rm); diff --git a/drivers/staging/uwb/include/debug-cmd.h b/drivers/staging/uwb/include/debug-cmd.h deleted file mode 100644 index f97db6c3bcc0..000000000000 --- a/drivers/staging/uwb/include/debug-cmd.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Ultra Wide Band - * Debug interface commands - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#ifndef __LINUX__UWB__DEBUG_CMD_H__ -#define __LINUX__UWB__DEBUG_CMD_H__ - -#include <linux/types.h> - -/* - * Debug interface commands - * - * UWB_DBG_CMD_RSV_ESTABLISH: Establish a new unicast reservation. - * - * UWB_DBG_CMD_RSV_TERMINATE: Terminate the Nth reservation. - */ - -enum uwb_dbg_cmd_type { - UWB_DBG_CMD_RSV_ESTABLISH = 1, - UWB_DBG_CMD_RSV_TERMINATE = 2, - UWB_DBG_CMD_IE_ADD = 3, - UWB_DBG_CMD_IE_RM = 4, - UWB_DBG_CMD_RADIO_START = 5, - UWB_DBG_CMD_RADIO_STOP = 6, -}; - -struct uwb_dbg_cmd_rsv_establish { - __u8 target[6]; - __u8 type; - __u16 max_mas; - __u16 min_mas; - __u8 max_interval; -}; - -struct uwb_dbg_cmd_rsv_terminate { - int index; -}; - -struct uwb_dbg_cmd_ie { - __u8 data[128]; - int len; -}; - -struct uwb_dbg_cmd { - __u32 type; - union { - struct uwb_dbg_cmd_rsv_establish rsv_establish; - struct uwb_dbg_cmd_rsv_terminate rsv_terminate; - struct uwb_dbg_cmd_ie ie_add; - struct uwb_dbg_cmd_ie ie_rm; - }; -}; - -#endif /* #ifndef __LINUX__UWB__DEBUG_CMD_H__ */ diff --git a/drivers/staging/uwb/include/spec.h b/drivers/staging/uwb/include/spec.h deleted file mode 100644 index 5f75caf7b4ba..000000000000 --- a/drivers/staging/uwb/include/spec.h +++ /dev/null @@ -1,767 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Ultra Wide Band - * UWB Standard definitions - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * All these definitions are based on the ECMA-368 standard. - * - * Note all definitions are Little Endian in the wire, and we will - * convert them to host order before operating on the bitfields (that - * yes, we use extensively). - */ - -#ifndef __LINUX__UWB_SPEC_H__ -#define __LINUX__UWB_SPEC_H__ - -#include <linux/types.h> -#include <linux/bitmap.h> -#include <linux/if_ether.h> - -#define i1480_FW 0x00000303 -/* #define i1480_FW 0x00000302 */ - -/** - * Number of Medium Access Slots in a superframe. - * - * UWB divides time in SuperFrames, each one divided in 256 pieces, or - * Medium Access Slots. See MBOA MAC[5.4.5] for details. The MAS is the - * basic bandwidth allocation unit in UWB. - */ -enum { UWB_NUM_MAS = 256 }; - -/** - * Number of Zones in superframe. - * - * UWB divides the superframe into zones with numbering starting from BPST. - * See MBOA MAC[16.8.6] - */ -enum { UWB_NUM_ZONES = 16 }; - -/* - * Number of MAS in a zone. - */ -#define UWB_MAS_PER_ZONE (UWB_NUM_MAS / UWB_NUM_ZONES) - -/* - * Number of MAS required before a row can be considered available. - */ -#define UWB_USABLE_MAS_PER_ROW (UWB_NUM_ZONES - 1) - -/* - * Number of streams per DRP reservation between a pair of devices. - * - * [ECMA-368] section 16.8.6. - */ -enum { UWB_NUM_STREAMS = 8 }; - -/* - * mMasLength - * - * The length of a MAS in microseconds. - * - * [ECMA-368] section 17.16. - */ -enum { UWB_MAS_LENGTH_US = 256 }; - -/* - * mBeaconSlotLength - * - * The length of the beacon slot in microseconds. - * - * [ECMA-368] section 17.16 - */ -enum { UWB_BEACON_SLOT_LENGTH_US = 85 }; - -/* - * mMaxLostBeacons - * - * The number beacons missing in consecutive superframes before a - * device can be considered as unreachable. - * - * [ECMA-368] section 17.16 - */ -enum { UWB_MAX_LOST_BEACONS = 3 }; - -/* - * mDRPBackOffWinMin - * - * The minimum number of superframes to wait before trying to reserve - * extra MAS. - * - * [ECMA-368] section 17.16 - */ -enum { UWB_DRP_BACKOFF_WIN_MIN = 2 }; - -/* - * mDRPBackOffWinMax - * - * The maximum number of superframes to wait before trying to reserve - * extra MAS. - * - * [ECMA-368] section 17.16 - */ -enum { UWB_DRP_BACKOFF_WIN_MAX = 16 }; - -/* - * Length of a superframe in microseconds. - */ -#define UWB_SUPERFRAME_LENGTH_US (UWB_MAS_LENGTH_US * UWB_NUM_MAS) - -/** - * UWB MAC address - * - * It is *imperative* that this struct is exactly 6 packed bytes (as - * it is also used to define headers sent down and up the wire/radio). - */ -struct uwb_mac_addr { - u8 data[ETH_ALEN]; -} __attribute__((packed)); - - -/** - * UWB device address - * - * It is *imperative* that this struct is exactly 6 packed bytes (as - * it is also used to define headers sent down and up the wire/radio). - */ -struct uwb_dev_addr { - u8 data[2]; -} __attribute__((packed)); - - -/** - * Types of UWB addresses - * - * Order matters (by size). - */ -enum uwb_addr_type { - UWB_ADDR_DEV = 0, - UWB_ADDR_MAC = 1, -}; - - -/** Size of a char buffer for printing a MAC/device address */ -enum { UWB_ADDR_STRSIZE = 32 }; - - -/** UWB WiMedia protocol IDs. */ -enum uwb_prid { - UWB_PRID_WLP_RESERVED = 0x0000, - UWB_PRID_WLP = 0x0001, - UWB_PRID_WUSB_BOT = 0x0010, - UWB_PRID_WUSB = 0x0010, - UWB_PRID_WUSB_TOP = 0x001F, -}; - - -/** PHY Rate (MBOA MAC[7.8.12, Table 61]) */ -enum uwb_phy_rate { - UWB_PHY_RATE_53 = 0, - UWB_PHY_RATE_80, - UWB_PHY_RATE_106, - UWB_PHY_RATE_160, - UWB_PHY_RATE_200, - UWB_PHY_RATE_320, - UWB_PHY_RATE_400, - UWB_PHY_RATE_480, - UWB_PHY_RATE_INVALID -}; - - -/** - * Different ways to scan (MBOA MAC[6.2.2, Table 8], WUSB[Table 8-78]) - */ -enum uwb_scan_type { - UWB_SCAN_ONLY = 0, - UWB_SCAN_OUTSIDE_BP, - UWB_SCAN_WHILE_INACTIVE, - UWB_SCAN_DISABLED, - UWB_SCAN_ONLY_STARTTIME, - UWB_SCAN_TOP -}; - - -/** ACK Policy types (MBOA MAC[7.2.1.3]) */ -enum uwb_ack_pol { - UWB_ACK_NO = 0, - UWB_ACK_INM = 1, - UWB_ACK_B = 2, - UWB_ACK_B_REQ = 3, -}; - - -/** DRP reservation types ([ECMA-368 table 106) */ -enum uwb_drp_type { - UWB_DRP_TYPE_ALIEN_BP = 0, - UWB_DRP_TYPE_HARD, - UWB_DRP_TYPE_SOFT, - UWB_DRP_TYPE_PRIVATE, - UWB_DRP_TYPE_PCA, -}; - - -/** DRP Reason Codes ([ECMA-368] table 107) */ -enum uwb_drp_reason { - UWB_DRP_REASON_ACCEPTED = 0, - UWB_DRP_REASON_CONFLICT, - UWB_DRP_REASON_PENDING, - UWB_DRP_REASON_DENIED, - UWB_DRP_REASON_MODIFIED, -}; - -/** Relinquish Request Reason Codes ([ECMA-368] table 113) */ -enum uwb_relinquish_req_reason { - UWB_RELINQUISH_REQ_REASON_NON_SPECIFIC = 0, - UWB_RELINQUISH_REQ_REASON_OVER_ALLOCATION, -}; - -/** - * DRP Notification Reason Codes (WHCI 0.95 [3.1.4.9]) - */ -enum uwb_drp_notif_reason { - UWB_DRP_NOTIF_DRP_IE_RCVD = 0, - UWB_DRP_NOTIF_CONFLICT, - UWB_DRP_NOTIF_TERMINATE, -}; - - -/** Allocation of MAS slots in a DRP request MBOA MAC[7.8.7] */ -struct uwb_drp_alloc { - __le16 zone_bm; - __le16 mas_bm; -} __attribute__((packed)); - - -/** General MAC Header format (ECMA-368[16.2]) */ -struct uwb_mac_frame_hdr { - __le16 Frame_Control; - struct uwb_dev_addr DestAddr; - struct uwb_dev_addr SrcAddr; - __le16 Sequence_Control; - __le16 Access_Information; -} __attribute__((packed)); - - -/** - * uwb_beacon_frame - a beacon frame including MAC headers - * - * [ECMA] section 16.3. - */ -struct uwb_beacon_frame { - struct uwb_mac_frame_hdr hdr; - struct uwb_mac_addr Device_Identifier; /* may be a NULL EUI-48 */ - u8 Beacon_Slot_Number; - u8 Device_Control; - u8 IEData[]; -} __attribute__((packed)); - - -/** Information Element codes (MBOA MAC[T54]) */ -enum uwb_ie { - UWB_PCA_AVAILABILITY = 2, - UWB_IE_DRP_AVAILABILITY = 8, - UWB_IE_DRP = 9, - UWB_BP_SWITCH_IE = 11, - UWB_MAC_CAPABILITIES_IE = 12, - UWB_PHY_CAPABILITIES_IE = 13, - UWB_APP_SPEC_PROBE_IE = 15, - UWB_IDENTIFICATION_IE = 19, - UWB_MASTER_KEY_ID_IE = 20, - UWB_RELINQUISH_REQUEST_IE = 21, - UWB_IE_WLP = 250, /* WiMedia Logical Link Control Protocol WLP 0.99 */ - UWB_APP_SPEC_IE = 255, -}; - - -/** - * Header common to all Information Elements (IEs) - */ -struct uwb_ie_hdr { - u8 element_id; /* enum uwb_ie */ - u8 length; -} __attribute__((packed)); - - -/** Dynamic Reservation Protocol IE (MBOA MAC[7.8.6]) */ -struct uwb_ie_drp { - struct uwb_ie_hdr hdr; - __le16 drp_control; - struct uwb_dev_addr dev_addr; - struct uwb_drp_alloc allocs[]; -} __attribute__((packed)); - -static inline int uwb_ie_drp_type(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 0) & 0x7; -} - -static inline int uwb_ie_drp_stream_index(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 3) & 0x7; -} - -static inline int uwb_ie_drp_reason_code(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 6) & 0x7; -} - -static inline int uwb_ie_drp_status(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 9) & 0x1; -} - -static inline int uwb_ie_drp_owner(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 10) & 0x1; -} - -static inline int uwb_ie_drp_tiebreaker(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 11) & 0x1; -} - -static inline int uwb_ie_drp_unsafe(struct uwb_ie_drp *ie) -{ - return (le16_to_cpu(ie->drp_control) >> 12) & 0x1; -} - -static inline void uwb_ie_drp_set_type(struct uwb_ie_drp *ie, enum uwb_drp_type type) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x7 << 0)) | (type << 0); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_stream_index(struct uwb_ie_drp *ie, int stream_index) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x7 << 3)) | (stream_index << 3); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_reason_code(struct uwb_ie_drp *ie, - enum uwb_drp_reason reason_code) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (ie->drp_control & ~(0x7 << 6)) | (reason_code << 6); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_status(struct uwb_ie_drp *ie, int status) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x1 << 9)) | (status << 9); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_owner(struct uwb_ie_drp *ie, int owner) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x1 << 10)) | (owner << 10); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_tiebreaker(struct uwb_ie_drp *ie, int tiebreaker) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x1 << 11)) | (tiebreaker << 11); - ie->drp_control = cpu_to_le16(drp_control); -} - -static inline void uwb_ie_drp_set_unsafe(struct uwb_ie_drp *ie, int unsafe) -{ - u16 drp_control = le16_to_cpu(ie->drp_control); - drp_control = (drp_control & ~(0x1 << 12)) | (unsafe << 12); - ie->drp_control = cpu_to_le16(drp_control); -} - -/** Dynamic Reservation Protocol IE (MBOA MAC[7.8.7]) */ -struct uwb_ie_drp_avail { - struct uwb_ie_hdr hdr; - DECLARE_BITMAP(bmp, UWB_NUM_MAS); -} __attribute__((packed)); - -/* Relinqish Request IE ([ECMA-368] section 16.8.19). */ -struct uwb_relinquish_request_ie { - struct uwb_ie_hdr hdr; - __le16 relinquish_req_control; - struct uwb_dev_addr dev_addr; - struct uwb_drp_alloc allocs[]; -} __attribute__((packed)); - -static inline int uwb_ie_relinquish_req_reason_code(struct uwb_relinquish_request_ie *ie) -{ - return (le16_to_cpu(ie->relinquish_req_control) >> 0) & 0xf; -} - -static inline void uwb_ie_relinquish_req_set_reason_code(struct uwb_relinquish_request_ie *ie, - int reason_code) -{ - u16 ctrl = le16_to_cpu(ie->relinquish_req_control); - ctrl = (ctrl & ~(0xf << 0)) | (reason_code << 0); - ie->relinquish_req_control = cpu_to_le16(ctrl); -} - -/** - * The Vendor ID is set to an OUI that indicates the vendor of the device. - * ECMA-368 [16.8.10] - */ -struct uwb_vendor_id { - u8 data[3]; -} __attribute__((packed)); - -/** - * The device type ID - * FIXME: clarify what this means - * ECMA-368 [16.8.10] - */ -struct uwb_device_type_id { - u8 data[3]; -} __attribute__((packed)); - - -/** - * UWB device information types - * ECMA-368 [16.8.10] - */ -enum uwb_dev_info_type { - UWB_DEV_INFO_VENDOR_ID = 0, - UWB_DEV_INFO_VENDOR_TYPE, - UWB_DEV_INFO_NAME, -}; - -/** - * UWB device information found in Identification IE - * ECMA-368 [16.8.10] - */ -struct uwb_dev_info { - u8 type; /* enum uwb_dev_info_type */ - u8 length; - u8 data[]; -} __attribute__((packed)); - -/** - * UWB Identification IE - * ECMA-368 [16.8.10] - */ -struct uwb_identification_ie { - struct uwb_ie_hdr hdr; - struct uwb_dev_info info[]; -} __attribute__((packed)); - -/* - * UWB Radio Controller - * - * These definitions are common to the Radio Control layers as - * exported by the WUSB1.0 HWA and WHCI interfaces. - */ - -/** Radio Control Command Block (WUSB1.0[Table 8-65] and WHCI 0.95) */ -struct uwb_rccb { - u8 bCommandType; /* enum hwa_cet */ - __le16 wCommand; /* Command code */ - u8 bCommandContext; /* Context ID */ -} __attribute__((packed)); - - -/** Radio Control Event Block (WUSB[table 8-66], WHCI 0.95) */ -struct uwb_rceb { - u8 bEventType; /* enum hwa_cet */ - __le16 wEvent; /* Event code */ - u8 bEventContext; /* Context ID */ -} __attribute__((packed)); - - -enum { - UWB_RC_CET_GENERAL = 0, /* General Command/Event type */ - UWB_RC_CET_EX_TYPE_1 = 1, /* Extended Type 1 Command/Event type */ -}; - -/* Commands to the radio controller */ -enum uwb_rc_cmd { - UWB_RC_CMD_CHANNEL_CHANGE = 16, - UWB_RC_CMD_DEV_ADDR_MGMT = 17, /* Device Address Management */ - UWB_RC_CMD_GET_IE = 18, /* GET Information Elements */ - UWB_RC_CMD_RESET = 19, - UWB_RC_CMD_SCAN = 20, /* Scan management */ - UWB_RC_CMD_SET_BEACON_FILTER = 21, - UWB_RC_CMD_SET_DRP_IE = 22, /* Dynamic Reservation Protocol IEs */ - UWB_RC_CMD_SET_IE = 23, /* Information Element management */ - UWB_RC_CMD_SET_NOTIFICATION_FILTER = 24, - UWB_RC_CMD_SET_TX_POWER = 25, - UWB_RC_CMD_SLEEP = 26, - UWB_RC_CMD_START_BEACON = 27, - UWB_RC_CMD_STOP_BEACON = 28, - UWB_RC_CMD_BP_MERGE = 29, - UWB_RC_CMD_SEND_COMMAND_FRAME = 30, - UWB_RC_CMD_SET_ASIE_NOTIF = 31, -}; - -/* Notifications from the radio controller */ -enum uwb_rc_evt { - UWB_RC_EVT_IE_RCV = 0, - UWB_RC_EVT_BEACON = 1, - UWB_RC_EVT_BEACON_SIZE = 2, - UWB_RC_EVT_BPOIE_CHANGE = 3, - UWB_RC_EVT_BP_SLOT_CHANGE = 4, - UWB_RC_EVT_BP_SWITCH_IE_RCV = 5, - UWB_RC_EVT_DEV_ADDR_CONFLICT = 6, - UWB_RC_EVT_DRP_AVAIL = 7, - UWB_RC_EVT_DRP = 8, - UWB_RC_EVT_BP_SWITCH_STATUS = 9, - UWB_RC_EVT_CMD_FRAME_RCV = 10, - UWB_RC_EVT_CHANNEL_CHANGE_IE_RCV = 11, - /* Events (command responses) use the same code as the command */ - UWB_RC_EVT_UNKNOWN_CMD_RCV = 65535, -}; - -enum uwb_rc_extended_type_1_cmd { - UWB_RC_SET_DAA_ENERGY_MASK = 32, - UWB_RC_SET_NOTIFICATION_FILTER_EX = 33, -}; - -enum uwb_rc_extended_type_1_evt { - UWB_RC_DAA_ENERGY_DETECTED = 0, -}; - -/* Radio Control Result Code. [WHCI] table 3-3. */ -enum { - UWB_RC_RES_SUCCESS = 0, - UWB_RC_RES_FAIL, - UWB_RC_RES_FAIL_HARDWARE, - UWB_RC_RES_FAIL_NO_SLOTS, - UWB_RC_RES_FAIL_BEACON_TOO_LARGE, - UWB_RC_RES_FAIL_INVALID_PARAMETER, - UWB_RC_RES_FAIL_UNSUPPORTED_PWR_LEVEL, - UWB_RC_RES_FAIL_INVALID_IE_DATA, - UWB_RC_RES_FAIL_BEACON_SIZE_EXCEEDED, - UWB_RC_RES_FAIL_CANCELLED, - UWB_RC_RES_FAIL_INVALID_STATE, - UWB_RC_RES_FAIL_INVALID_SIZE, - UWB_RC_RES_FAIL_ACK_NOT_RECEIVED, - UWB_RC_RES_FAIL_NO_MORE_ASIE_NOTIF, - UWB_RC_RES_FAIL_TIME_OUT = 255, -}; - -/* Confirm event. [WHCI] section 3.1.3.1 etc. */ -struct uwb_rc_evt_confirm { - struct uwb_rceb rceb; - u8 bResultCode; -} __attribute__((packed)); - -/* Device Address Management event. [WHCI] section 3.1.3.2. */ -struct uwb_rc_evt_dev_addr_mgmt { - struct uwb_rceb rceb; - u8 baAddr[ETH_ALEN]; - u8 bResultCode; -} __attribute__((packed)); - - -/* Get IE Event. [WHCI] section 3.1.3.3. */ -struct uwb_rc_evt_get_ie { - struct uwb_rceb rceb; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/* Set DRP IE Event. [WHCI] section 3.1.3.7. */ -struct uwb_rc_evt_set_drp_ie { - struct uwb_rceb rceb; - __le16 wRemainingSpace; - u8 bResultCode; -} __attribute__((packed)); - -/* Set IE Event. [WHCI] section 3.1.3.8. */ -struct uwb_rc_evt_set_ie { - struct uwb_rceb rceb; - __le16 RemainingSpace; - u8 bResultCode; -} __attribute__((packed)); - -/* Scan command. [WHCI] 3.1.3.5. */ -struct uwb_rc_cmd_scan { - struct uwb_rccb rccb; - u8 bChannelNumber; - u8 bScanState; - __le16 wStartTime; -} __attribute__((packed)); - -/* Set DRP IE command. [WHCI] section 3.1.3.7. */ -struct uwb_rc_cmd_set_drp_ie { - struct uwb_rccb rccb; - __le16 wIELength; - struct uwb_ie_drp IEData[]; -} __attribute__((packed)); - -/* Set IE command. [WHCI] section 3.1.3.8. */ -struct uwb_rc_cmd_set_ie { - struct uwb_rccb rccb; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/* Set DAA Energy Mask event. [WHCI 0.96] section 3.1.3.17. */ -struct uwb_rc_evt_set_daa_energy_mask { - struct uwb_rceb rceb; - __le16 wLength; - u8 result; -} __attribute__((packed)); - -/* Set Notification Filter Extended event. [WHCI 0.96] section 3.1.3.18. */ -struct uwb_rc_evt_set_notification_filter_ex { - struct uwb_rceb rceb; - __le16 wLength; - u8 result; -} __attribute__((packed)); - -/* IE Received notification. [WHCI] section 3.1.4.1. */ -struct uwb_rc_evt_ie_rcv { - struct uwb_rceb rceb; - struct uwb_dev_addr SrcAddr; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/* Type of the received beacon. [WHCI] section 3.1.4.2. */ -enum uwb_rc_beacon_type { - UWB_RC_BEACON_TYPE_SCAN = 0, - UWB_RC_BEACON_TYPE_NEIGHBOR, - UWB_RC_BEACON_TYPE_OL_ALIEN, - UWB_RC_BEACON_TYPE_NOL_ALIEN, -}; - -/* Beacon received notification. [WHCI] 3.1.4.2. */ -struct uwb_rc_evt_beacon { - struct uwb_rceb rceb; - u8 bChannelNumber; - u8 bBeaconType; - __le16 wBPSTOffset; - u8 bLQI; - u8 bRSSI; - __le16 wBeaconInfoLength; - u8 BeaconInfo[]; -} __attribute__((packed)); - - -/* Beacon Size Change notification. [WHCI] section 3.1.4.3 */ -struct uwb_rc_evt_beacon_size { - struct uwb_rceb rceb; - __le16 wNewBeaconSize; -} __attribute__((packed)); - - -/* BPOIE Change notification. [WHCI] section 3.1.4.4. */ -struct uwb_rc_evt_bpoie_change { - struct uwb_rceb rceb; - __le16 wBPOIELength; - u8 BPOIE[]; -} __attribute__((packed)); - - -/* Beacon Slot Change notification. [WHCI] section 3.1.4.5. */ -struct uwb_rc_evt_bp_slot_change { - struct uwb_rceb rceb; - u8 slot_info; -} __attribute__((packed)); - -static inline int uwb_rc_evt_bp_slot_change_slot_num( - const struct uwb_rc_evt_bp_slot_change *evt) -{ - return evt->slot_info & 0x7f; -} - -static inline int uwb_rc_evt_bp_slot_change_no_slot( - const struct uwb_rc_evt_bp_slot_change *evt) -{ - return (evt->slot_info & 0x80) >> 7; -} - -/* BP Switch IE Received notification. [WHCI] section 3.1.4.6. */ -struct uwb_rc_evt_bp_switch_ie_rcv { - struct uwb_rceb rceb; - struct uwb_dev_addr wSrcAddr; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/* DevAddr Conflict notification. [WHCI] section 3.1.4.7. */ -struct uwb_rc_evt_dev_addr_conflict { - struct uwb_rceb rceb; -} __attribute__((packed)); - -/* DRP notification. [WHCI] section 3.1.4.9. */ -struct uwb_rc_evt_drp { - struct uwb_rceb rceb; - struct uwb_dev_addr src_addr; - u8 reason; - u8 beacon_slot_number; - __le16 ie_length; - u8 ie_data[]; -} __attribute__((packed)); - -static inline enum uwb_drp_notif_reason uwb_rc_evt_drp_reason(struct uwb_rc_evt_drp *evt) -{ - return evt->reason & 0x0f; -} - - -/* DRP Availability Change notification. [WHCI] section 3.1.4.8. */ -struct uwb_rc_evt_drp_avail { - struct uwb_rceb rceb; - DECLARE_BITMAP(bmp, UWB_NUM_MAS); -} __attribute__((packed)); - -/* BP switch status notification. [WHCI] section 3.1.4.10. */ -struct uwb_rc_evt_bp_switch_status { - struct uwb_rceb rceb; - u8 status; - u8 slot_offset; - __le16 bpst_offset; - u8 move_countdown; -} __attribute__((packed)); - -/* Command Frame Received notification. [WHCI] section 3.1.4.11. */ -struct uwb_rc_evt_cmd_frame_rcv { - struct uwb_rceb rceb; - __le16 receive_time; - struct uwb_dev_addr wSrcAddr; - struct uwb_dev_addr wDstAddr; - __le16 control; - __le16 reserved; - __le16 dataLength; - u8 data[]; -} __attribute__((packed)); - -/* Channel Change IE Received notification. [WHCI] section 3.1.4.12. */ -struct uwb_rc_evt_channel_change_ie_rcv { - struct uwb_rceb rceb; - struct uwb_dev_addr wSrcAddr; - __le16 wIELength; - u8 IEData[]; -} __attribute__((packed)); - -/* DAA Energy Detected notification. [WHCI 0.96] section 3.1.4.14. */ -struct uwb_rc_evt_daa_energy_detected { - struct uwb_rceb rceb; - __le16 wLength; - u8 bandID; - u8 reserved; - u8 toneBmp[16]; -} __attribute__((packed)); - - -/** - * Radio Control Interface Class Descriptor - * - * WUSB 1.0 [8.6.1.2] - */ -struct uwb_rc_control_intf_class_desc { - u8 bLength; - u8 bDescriptorType; - __le16 bcdRCIVersion; -} __attribute__((packed)); - -#endif /* #ifndef __LINUX__UWB_SPEC_H__ */ diff --git a/drivers/staging/uwb/include/umc.h b/drivers/staging/uwb/include/umc.h deleted file mode 100644 index ddbceb39ad15..000000000000 --- a/drivers/staging/uwb/include/umc.h +++ /dev/null @@ -1,192 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * UWB Multi-interface Controller support. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - * - * UMC (UWB Multi-interface Controller) capabilities (e.g., radio - * controller, host controller) are presented as devices on the "umc" - * bus. - * - * The radio controller is not strictly a UMC capability but it's - * useful to present it as such. - * - * References: - * - * [WHCI] Wireless Host Controller Interface Specification for - * Certified Wireless Universal Serial Bus, revision 0.95. - * - * How this works is kind of convoluted but simple. The whci.ko driver - * loads when WHCI devices are detected. These WHCI devices expose - * many devices in the same PCI function (they couldn't have reused - * functions, no), so for each PCI function that exposes these many - * devices, whci ceates a umc_dev [whci_probe() -> whci_add_cap()] - * with umc_device_create() and adds it to the bus with - * umc_device_register(). - * - * umc_device_register() calls device_register() which will push the - * bus management code to load your UMC driver's somehting_probe() - * that you have registered for that capability code. - * - * Now when the WHCI device is removed, whci_remove() will go over - * each umc_dev assigned to each of the PCI function's capabilities - * and through whci_del_cap() call umc_device_unregister() each - * created umc_dev. Of course, if you are bound to the device, your - * driver's something_remove() will be called. - */ - -#ifndef _LINUX_UWB_UMC_H_ -#define _LINUX_UWB_UMC_H_ - -#include <linux/device.h> -#include <linux/pci.h> - -/* - * UMC capability IDs. - * - * 0x00 is reserved so use it for the radio controller device. - * - * [WHCI] table 2-8 - */ -#define UMC_CAP_ID_WHCI_RC 0x00 /* radio controller */ -#define UMC_CAP_ID_WHCI_WUSB_HC 0x01 /* WUSB host controller */ - -/** - * struct umc_dev - UMC capability device - * - * @version: version of the specification this capability conforms to. - * @cap_id: capability ID. - * @bar: PCI Bar (64 bit) where the resource lies - * @resource: register space resource. - * @irq: interrupt line. - */ -struct umc_dev { - u16 version; - u8 cap_id; - u8 bar; - struct resource resource; - unsigned irq; - struct device dev; -}; - -#define to_umc_dev(d) container_of(d, struct umc_dev, dev) - -/** - * struct umc_driver - UMC capability driver - * @cap_id: supported capability ID. - * @match: driver specific capability matching function. - * @match_data: driver specific data for match() (e.g., a - * table of pci_device_id's if umc_match_pci_id() is used). - */ -struct umc_driver { - char *name; - u8 cap_id; - int (*match)(struct umc_driver *, struct umc_dev *); - const void *match_data; - - int (*probe)(struct umc_dev *); - void (*remove)(struct umc_dev *); - int (*pre_reset)(struct umc_dev *); - int (*post_reset)(struct umc_dev *); - - struct device_driver driver; -}; - -#define to_umc_driver(d) container_of(d, struct umc_driver, driver) - -extern struct bus_type umc_bus_type; - -struct umc_dev *umc_device_create(struct device *parent, int n); -int __must_check umc_device_register(struct umc_dev *umc); -void umc_device_unregister(struct umc_dev *umc); - -int __must_check __umc_driver_register(struct umc_driver *umc_drv, - struct module *mod, - const char *mod_name); - -/** - * umc_driver_register - register a UMC capabiltity driver. - * @umc_drv: pointer to the driver. - */ -#define umc_driver_register(umc_drv) \ - __umc_driver_register(umc_drv, THIS_MODULE, KBUILD_MODNAME) - -void umc_driver_unregister(struct umc_driver *umc_drv); - -/* - * Utility function you can use to match (umc_driver->match) against a - * null-terminated array of 'struct pci_device_id' in - * umc_driver->match_data. - */ -int umc_match_pci_id(struct umc_driver *umc_drv, struct umc_dev *umc); - -/** - * umc_parent_pci_dev - return the UMC's parent PCI device or NULL if none - * @umc_dev: UMC device whose parent PCI device we are looking for - * - * DIRTY!!! DON'T RELY ON THIS - * - * FIXME: This is as dirty as it gets, but we need some way to check - * the correct type of umc_dev->parent (so that for example, we can - * cast to pci_dev). Casting to pci_dev is necessary because at some - * point we need to request resources from the device. Mapping is - * easily over come (ioremap and stuff are bus agnostic), but hooking - * up to some error handlers (such as pci error handlers) might need - * this. - * - * THIS might (probably will) be removed in the future, so don't count - * on it. - */ -static inline struct pci_dev *umc_parent_pci_dev(struct umc_dev *umc_dev) -{ - struct pci_dev *pci_dev = NULL; - if (dev_is_pci(umc_dev->dev.parent)) - pci_dev = to_pci_dev(umc_dev->dev.parent); - return pci_dev; -} - -/** - * umc_dev_get() - reference a UMC device. - * @umc_dev: Pointer to UMC device. - * - * NOTE: we are assuming in this whole scheme that the parent device - * is referenced at _probe() time and unreferenced at _remove() - * time by the parent's subsystem. - */ -static inline struct umc_dev *umc_dev_get(struct umc_dev *umc_dev) -{ - get_device(&umc_dev->dev); - return umc_dev; -} - -/** - * umc_dev_put() - unreference a UMC device. - * @umc_dev: Pointer to UMC device. - */ -static inline void umc_dev_put(struct umc_dev *umc_dev) -{ - put_device(&umc_dev->dev); -} - -/** - * umc_set_drvdata - set UMC device's driver data. - * @umc_dev: Pointer to UMC device. - * @data: Data to set. - */ -static inline void umc_set_drvdata(struct umc_dev *umc_dev, void *data) -{ - dev_set_drvdata(&umc_dev->dev, data); -} - -/** - * umc_get_drvdata - recover UMC device's driver data. - * @umc_dev: Pointer to UMC device. - */ -static inline void *umc_get_drvdata(struct umc_dev *umc_dev) -{ - return dev_get_drvdata(&umc_dev->dev); -} - -int umc_controller_reset(struct umc_dev *umc); - -#endif /* #ifndef _LINUX_UWB_UMC_H_ */ diff --git a/drivers/staging/uwb/include/whci.h b/drivers/staging/uwb/include/whci.h deleted file mode 100644 index 1a5c2cc2b008..000000000000 --- a/drivers/staging/uwb/include/whci.h +++ /dev/null @@ -1,102 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Wireless Host Controller Interface for Ultra-Wide-Band and Wireless USB - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * References: - * [WHCI] Wireless Host Controller Interface Specification for - * Certified Wireless Universal Serial Bus, revision 0.95. - */ -#ifndef _LINUX_UWB_WHCI_H_ -#define _LINUX_UWB_WHCI_H_ - -#include <linux/pci.h> - -/* - * UWB interface capability registers (offsets from UWBBASE) - * - * [WHCI] section 2.2 - */ -#define UWBCAPINFO 0x00 /* == UWBCAPDATA(0) */ -# define UWBCAPINFO_TO_N_CAPS(c) (((c) >> 0) & 0xFull) -#define UWBCAPDATA(n) (8*(n)) -# define UWBCAPDATA_TO_VERSION(c) (((c) >> 32) & 0xFFFFull) -# define UWBCAPDATA_TO_OFFSET(c) (((c) >> 18) & 0x3FFFull) -# define UWBCAPDATA_TO_BAR(c) (((c) >> 16) & 0x3ull) -# define UWBCAPDATA_TO_SIZE(c) ((((c) >> 8) & 0xFFull) * sizeof(u32)) -# define UWBCAPDATA_TO_CAP_ID(c) (((c) >> 0) & 0xFFull) - -/* Size of the WHCI capability data (including the RC capability) for - a device with n capabilities. */ -#define UWBCAPDATA_SIZE(n) (8 + 8*(n)) - - -/* - * URC registers (offsets from URCBASE) - * - * [WHCI] section 2.3 - */ -#define URCCMD 0x00 -# define URCCMD_RESET (1 << 31) /* UMC Hardware reset */ -# define URCCMD_RS (1 << 30) /* Run/Stop */ -# define URCCMD_EARV (1 << 29) /* Event Address Register Valid */ -# define URCCMD_ACTIVE (1 << 15) /* Command is active */ -# define URCCMD_IWR (1 << 14) /* Interrupt When Ready */ -# define URCCMD_SIZE_MASK 0x00000fff /* Command size mask */ -#define URCSTS 0x04 -# define URCSTS_EPS (1 << 17) /* Event Processing Status */ -# define URCSTS_HALTED (1 << 16) /* RC halted */ -# define URCSTS_HSE (1 << 10) /* Host System Error...fried */ -# define URCSTS_ER (1 << 9) /* Event Ready */ -# define URCSTS_RCI (1 << 8) /* Ready for Command Interrupt */ -# define URCSTS_INT_MASK 0x00000700 /* URC interrupt sources */ -# define URCSTS_ISI 0x000000ff /* Interrupt Source Identification */ -#define URCINTR 0x08 -# define URCINTR_EN_ALL 0x000007ff /* Enable all interrupt sources */ -#define URCCMDADDR 0x10 -#define URCEVTADDR 0x18 -# define URCEVTADDR_OFFSET_MASK 0xfff /* Event pointer offset mask */ - - -/** Write 32 bit @value to little endian register at @addr */ -static inline -void le_writel(u32 value, void __iomem *addr) -{ - iowrite32(value, addr); -} - - -/** Read from 32 bit little endian register at @addr */ -static inline -u32 le_readl(void __iomem *addr) -{ - return ioread32(addr); -} - - -/** Write 64 bit @value to little endian register at @addr */ -static inline -void le_writeq(u64 value, void __iomem *addr) -{ - iowrite32(value, addr); - iowrite32(value >> 32, addr + 4); -} - - -/** Read from 64 bit little endian register at @addr */ -static inline -u64 le_readq(void __iomem *addr) -{ - u64 value; - value = ioread32(addr); - value |= (u64)ioread32(addr + 4) << 32; - return value; -} - -extern int whci_wait_for(struct device *dev, u32 __iomem *reg, - u32 mask, u32 result, - unsigned long max_ms, const char *tag); - -#endif /* #ifndef _LINUX_UWB_WHCI_H_ */ diff --git a/drivers/staging/uwb/lc-dev.c b/drivers/staging/uwb/lc-dev.c deleted file mode 100644 index 3e5c07fd6b10..000000000000 --- a/drivers/staging/uwb/lc-dev.c +++ /dev/null @@ -1,457 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Life cycle of devices - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/device.h> -#include <linux/export.h> -#include <linux/err.h> -#include <linux/kdev_t.h> -#include <linux/random.h> -#include <linux/stat.h> -#include "uwb-internal.h" - -/* We initialize addresses to 0xff (invalid, as it is bcast) */ -static inline void uwb_dev_addr_init(struct uwb_dev_addr *addr) -{ - memset(&addr->data, 0xff, sizeof(addr->data)); -} - -static inline void uwb_mac_addr_init(struct uwb_mac_addr *addr) -{ - memset(&addr->data, 0xff, sizeof(addr->data)); -} - -/* - * Add callback @new to be called when an event occurs in @rc. - */ -int uwb_notifs_register(struct uwb_rc *rc, struct uwb_notifs_handler *new) -{ - if (mutex_lock_interruptible(&rc->notifs_chain.mutex)) - return -ERESTARTSYS; - list_add(&new->list_node, &rc->notifs_chain.list); - mutex_unlock(&rc->notifs_chain.mutex); - return 0; -} -EXPORT_SYMBOL_GPL(uwb_notifs_register); - -/* - * Remove event handler (callback) - */ -int uwb_notifs_deregister(struct uwb_rc *rc, struct uwb_notifs_handler *entry) -{ - if (mutex_lock_interruptible(&rc->notifs_chain.mutex)) - return -ERESTARTSYS; - list_del(&entry->list_node); - mutex_unlock(&rc->notifs_chain.mutex); - return 0; -} -EXPORT_SYMBOL_GPL(uwb_notifs_deregister); - -/* - * Notify all event handlers of a given event on @rc - * - * We are called with a valid reference to the device, or NULL if the - * event is not for a particular event (e.g., a BG join event). - */ -void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event) -{ - struct uwb_notifs_handler *handler; - if (mutex_lock_interruptible(&rc->notifs_chain.mutex)) - return; - if (!list_empty(&rc->notifs_chain.list)) { - list_for_each_entry(handler, &rc->notifs_chain.list, list_node) { - handler->cb(handler->data, uwb_dev, event); - } - } - mutex_unlock(&rc->notifs_chain.mutex); -} - -/* - * Release the backing device of a uwb_dev that has been dynamically allocated. - */ -static void uwb_dev_sys_release(struct device *dev) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - - uwb_bce_put(uwb_dev->bce); - memset(uwb_dev, 0x69, sizeof(*uwb_dev)); - kfree(uwb_dev); -} - -/* - * Initialize a UWB device instance - * - * Alloc, zero and call this function. - */ -void uwb_dev_init(struct uwb_dev *uwb_dev) -{ - mutex_init(&uwb_dev->mutex); - device_initialize(&uwb_dev->dev); - uwb_dev->dev.release = uwb_dev_sys_release; - uwb_dev_addr_init(&uwb_dev->dev_addr); - uwb_mac_addr_init(&uwb_dev->mac_addr); - bitmap_fill(uwb_dev->streams, UWB_NUM_GLOBAL_STREAMS); -} - -static ssize_t uwb_dev_EUI_48_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - char addr[UWB_ADDR_STRSIZE]; - - uwb_mac_addr_print(addr, sizeof(addr), &uwb_dev->mac_addr); - return sprintf(buf, "%s\n", addr); -} -static DEVICE_ATTR(EUI_48, S_IRUGO, uwb_dev_EUI_48_show, NULL); - -static ssize_t uwb_dev_DevAddr_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - char addr[UWB_ADDR_STRSIZE]; - - uwb_dev_addr_print(addr, sizeof(addr), &uwb_dev->dev_addr); - return sprintf(buf, "%s\n", addr); -} -static DEVICE_ATTR(DevAddr, S_IRUGO, uwb_dev_DevAddr_show, NULL); - -/* - * Show the BPST of this device. - * - * Calculated from the receive time of the device's beacon and it's - * slot number. - */ -static ssize_t uwb_dev_BPST_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_beca_e *bce; - struct uwb_beacon_frame *bf; - u16 bpst; - - bce = uwb_dev->bce; - mutex_lock(&bce->mutex); - bf = (struct uwb_beacon_frame *)bce->be->BeaconInfo; - bpst = bce->be->wBPSTOffset - - (u16)(bf->Beacon_Slot_Number * UWB_BEACON_SLOT_LENGTH_US); - mutex_unlock(&bce->mutex); - - return sprintf(buf, "%d\n", bpst); -} -static DEVICE_ATTR(BPST, S_IRUGO, uwb_dev_BPST_show, NULL); - -/* - * Show the IEs a device is beaconing - * - * We need to access the beacon cache, so we just lock it really - * quick, print the IEs and unlock. - * - * We have a reference on the cache entry, so that should be - * quite safe. - */ -static ssize_t uwb_dev_IEs_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - - return uwb_bce_print_IEs(uwb_dev, uwb_dev->bce, buf, PAGE_SIZE); -} -static DEVICE_ATTR(IEs, S_IRUGO | S_IWUSR, uwb_dev_IEs_show, NULL); - -static ssize_t uwb_dev_LQE_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_beca_e *bce = uwb_dev->bce; - size_t result; - - mutex_lock(&bce->mutex); - result = stats_show(&uwb_dev->bce->lqe_stats, buf); - mutex_unlock(&bce->mutex); - return result; -} - -static ssize_t uwb_dev_LQE_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_beca_e *bce = uwb_dev->bce; - ssize_t result; - - mutex_lock(&bce->mutex); - result = stats_store(&uwb_dev->bce->lqe_stats, buf, size); - mutex_unlock(&bce->mutex); - return result; -} -static DEVICE_ATTR(LQE, S_IRUGO | S_IWUSR, uwb_dev_LQE_show, uwb_dev_LQE_store); - -static ssize_t uwb_dev_RSSI_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_beca_e *bce = uwb_dev->bce; - size_t result; - - mutex_lock(&bce->mutex); - result = stats_show(&uwb_dev->bce->rssi_stats, buf); - mutex_unlock(&bce->mutex); - return result; -} - -static ssize_t uwb_dev_RSSI_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_beca_e *bce = uwb_dev->bce; - ssize_t result; - - mutex_lock(&bce->mutex); - result = stats_store(&uwb_dev->bce->rssi_stats, buf, size); - mutex_unlock(&bce->mutex); - return result; -} -static DEVICE_ATTR(RSSI, S_IRUGO | S_IWUSR, uwb_dev_RSSI_show, uwb_dev_RSSI_store); - - -static struct attribute *uwb_dev_attrs[] = { - &dev_attr_EUI_48.attr, - &dev_attr_DevAddr.attr, - &dev_attr_BPST.attr, - &dev_attr_IEs.attr, - &dev_attr_LQE.attr, - &dev_attr_RSSI.attr, - NULL, -}; -ATTRIBUTE_GROUPS(uwb_dev); - -/* UWB bus type. */ -struct bus_type uwb_bus_type = { - .name = "uwb", - .dev_groups = uwb_dev_groups, -}; - -/** - * Device SYSFS registration - */ -static int __uwb_dev_sys_add(struct uwb_dev *uwb_dev, struct device *parent_dev) -{ - struct device *dev; - - dev = &uwb_dev->dev; - dev->parent = parent_dev; - dev_set_drvdata(dev, uwb_dev); - - return device_add(dev); -} - - -static void __uwb_dev_sys_rm(struct uwb_dev *uwb_dev) -{ - dev_set_drvdata(&uwb_dev->dev, NULL); - device_del(&uwb_dev->dev); -} - - -/** - * Register and initialize a new UWB device - * - * Did you call uwb_dev_init() on it? - * - * @parent_rc: is the parent radio controller who has the link to the - * device. When registering the UWB device that is a UWB - * Radio Controller, we point back to it. - * - * If registering the device that is part of a radio, caller has set - * rc->uwb_dev->dev. Otherwise it is to be left NULL--a new one will - * be allocated. - */ -int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev, - struct uwb_rc *parent_rc) -{ - int result; - struct device *dev; - - BUG_ON(uwb_dev == NULL); - BUG_ON(parent_dev == NULL); - BUG_ON(parent_rc == NULL); - - mutex_lock(&uwb_dev->mutex); - dev = &uwb_dev->dev; - uwb_dev->rc = parent_rc; - result = __uwb_dev_sys_add(uwb_dev, parent_dev); - if (result < 0) - printk(KERN_ERR "UWB: unable to register dev %s with sysfs: %d\n", - dev_name(dev), result); - mutex_unlock(&uwb_dev->mutex); - return result; -} - - -void uwb_dev_rm(struct uwb_dev *uwb_dev) -{ - mutex_lock(&uwb_dev->mutex); - __uwb_dev_sys_rm(uwb_dev); - mutex_unlock(&uwb_dev->mutex); -} - - -static -int __uwb_dev_try_get(struct device *dev, void *__target_uwb_dev) -{ - struct uwb_dev *target_uwb_dev = __target_uwb_dev; - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - if (uwb_dev == target_uwb_dev) { - uwb_dev_get(uwb_dev); - return 1; - } else - return 0; -} - - -/** - * Given a UWB device descriptor, validate and refcount it - * - * @returns NULL if the device does not exist or is quiescing; the ptr to - * it otherwise. - */ -struct uwb_dev *uwb_dev_try_get(struct uwb_rc *rc, struct uwb_dev *uwb_dev) -{ - if (uwb_dev_for_each(rc, __uwb_dev_try_get, uwb_dev)) - return uwb_dev; - else - return NULL; -} -EXPORT_SYMBOL_GPL(uwb_dev_try_get); - - -/** - * Remove a device from the system [grunt for other functions] - */ -int __uwb_dev_offair(struct uwb_dev *uwb_dev, struct uwb_rc *rc) -{ - struct device *dev = &uwb_dev->dev; - char macbuf[UWB_ADDR_STRSIZE], devbuf[UWB_ADDR_STRSIZE]; - - uwb_mac_addr_print(macbuf, sizeof(macbuf), &uwb_dev->mac_addr); - uwb_dev_addr_print(devbuf, sizeof(devbuf), &uwb_dev->dev_addr); - dev_info(dev, "uwb device (mac %s dev %s) disconnected from %s %s\n", - macbuf, devbuf, - uwb_dev->dev.bus->name, - rc ? dev_name(&(rc->uwb_dev.dev)) : ""); - uwb_dev_rm(uwb_dev); - list_del(&uwb_dev->bce->node); - uwb_bce_put(uwb_dev->bce); - uwb_dev_put(uwb_dev); /* for the creation in _onair() */ - - return 0; -} - - -/** - * A device went off the air, clean up after it! - * - * This is called by the UWB Daemon (through the beacon purge function - * uwb_bcn_cache_purge) when it is detected that a device has been in - * radio silence for a while. - * - * If this device is actually a local radio controller we don't need - * to go through the offair process, as it is not registered as that. - * - * NOTE: uwb_bcn_cache.mutex is held! - */ -void uwbd_dev_offair(struct uwb_beca_e *bce) -{ - struct uwb_dev *uwb_dev; - - uwb_dev = bce->uwb_dev; - if (uwb_dev) { - uwb_notify(uwb_dev->rc, uwb_dev, UWB_NOTIF_OFFAIR); - __uwb_dev_offair(uwb_dev, uwb_dev->rc); - } -} - - -/** - * A device went on the air, start it up! - * - * This is called by the UWB Daemon when it is detected that a device - * has popped up in the radio range of the radio controller. - * - * It will just create the freaking device, register the beacon and - * stuff and yatla, done. - * - * - * NOTE: uwb_beca.mutex is held, bce->mutex is held - */ -void uwbd_dev_onair(struct uwb_rc *rc, struct uwb_beca_e *bce) -{ - int result; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_dev *uwb_dev; - char macbuf[UWB_ADDR_STRSIZE], devbuf[UWB_ADDR_STRSIZE]; - - uwb_mac_addr_print(macbuf, sizeof(macbuf), bce->mac_addr); - uwb_dev_addr_print(devbuf, sizeof(devbuf), &bce->dev_addr); - uwb_dev = kzalloc(sizeof(struct uwb_dev), GFP_KERNEL); - if (uwb_dev == NULL) { - dev_err(dev, "new device %s: Cannot allocate memory\n", - macbuf); - return; - } - uwb_dev_init(uwb_dev); /* This sets refcnt to one, we own it */ - uwb_dev->dev.bus = &uwb_bus_type; - uwb_dev->mac_addr = *bce->mac_addr; - uwb_dev->dev_addr = bce->dev_addr; - dev_set_name(&uwb_dev->dev, "%s", macbuf); - - /* plug the beacon cache */ - bce->uwb_dev = uwb_dev; - uwb_dev->bce = bce; - uwb_bce_get(bce); /* released in uwb_dev_sys_release() */ - - result = uwb_dev_add(uwb_dev, &rc->uwb_dev.dev, rc); - if (result < 0) { - dev_err(dev, "new device %s: cannot instantiate device\n", - macbuf); - goto error_dev_add; - } - - dev_info(dev, "uwb device (mac %s dev %s) connected to %s %s\n", - macbuf, devbuf, uwb_dev->dev.bus->name, - dev_name(&(rc->uwb_dev.dev))); - uwb_notify(rc, uwb_dev, UWB_NOTIF_ONAIR); - return; - -error_dev_add: - bce->uwb_dev = NULL; - uwb_bce_put(bce); - kfree(uwb_dev); - return; -} - -/** - * Iterate over the list of UWB devices, calling a @function on each - * - * See docs for bus_for_each().... - * - * @rc: radio controller for the devices. - * @function: function to call. - * @priv: data to pass to @function. - * @returns: 0 if no invocation of function() returned a value - * different to zero. That value otherwise. - */ -int uwb_dev_for_each(struct uwb_rc *rc, uwb_dev_for_each_f function, void *priv) -{ - return device_for_each_child(&rc->uwb_dev.dev, priv, function); -} -EXPORT_SYMBOL_GPL(uwb_dev_for_each); diff --git a/drivers/staging/uwb/lc-rc.c b/drivers/staging/uwb/lc-rc.c deleted file mode 100644 index ee31b221cdc2..000000000000 --- a/drivers/staging/uwb/lc-rc.c +++ /dev/null @@ -1,569 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Life cycle of radio controllers - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * - * A UWB radio controller is also a UWB device, so it embeds one... - * - * List of RCs comes from the 'struct class uwb_rc_class'. - */ - -#include <linux/kernel.h> -#include <linux/string.h> -#include <linux/device.h> -#include <linux/err.h> -#include <linux/random.h> -#include <linux/kdev_t.h> -#include <linux/etherdevice.h> -#include <linux/usb.h> -#include <linux/slab.h> -#include <linux/export.h> - -#include "uwb-internal.h" - -static int uwb_rc_index_match(struct device *dev, const void *data) -{ - const int *index = data; - struct uwb_rc *rc = dev_get_drvdata(dev); - - if (rc->index == *index) - return 1; - return 0; -} - -static struct uwb_rc *uwb_rc_find_by_index(int index) -{ - struct device *dev; - struct uwb_rc *rc = NULL; - - dev = class_find_device(&uwb_rc_class, NULL, &index, uwb_rc_index_match); - if (dev) { - rc = dev_get_drvdata(dev); - put_device(dev); - } - - return rc; -} - -static int uwb_rc_new_index(void) -{ - int index = 0; - - for (;;) { - if (!uwb_rc_find_by_index(index)) - return index; - if (++index < 0) - index = 0; - } -} - -/** - * Release the backing device of a uwb_rc that has been dynamically allocated. - */ -static void uwb_rc_sys_release(struct device *dev) -{ - struct uwb_dev *uwb_dev = container_of(dev, struct uwb_dev, dev); - struct uwb_rc *rc = container_of(uwb_dev, struct uwb_rc, uwb_dev); - - uwb_rc_ie_release(rc); - kfree(rc); -} - - -void uwb_rc_init(struct uwb_rc *rc) -{ - struct uwb_dev *uwb_dev = &rc->uwb_dev; - - uwb_dev_init(uwb_dev); - rc->uwb_dev.dev.class = &uwb_rc_class; - rc->uwb_dev.dev.release = uwb_rc_sys_release; - uwb_rc_neh_create(rc); - rc->beaconing = -1; - rc->scan_type = UWB_SCAN_DISABLED; - INIT_LIST_HEAD(&rc->notifs_chain.list); - mutex_init(&rc->notifs_chain.mutex); - INIT_LIST_HEAD(&rc->uwb_beca.list); - mutex_init(&rc->uwb_beca.mutex); - uwb_drp_avail_init(rc); - uwb_rc_ie_init(rc); - uwb_rsv_init(rc); - uwb_rc_pal_init(rc); -} -EXPORT_SYMBOL_GPL(uwb_rc_init); - - -struct uwb_rc *uwb_rc_alloc(void) -{ - struct uwb_rc *rc; - rc = kzalloc(sizeof(*rc), GFP_KERNEL); - if (rc == NULL) - return NULL; - uwb_rc_init(rc); - return rc; -} -EXPORT_SYMBOL_GPL(uwb_rc_alloc); - -/* - * Show the ASIE that is broadcast in the UWB beacon by this uwb_rc device. - */ -static ssize_t ASIE_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - struct uwb_ie_hdr *ie; - void *ptr; - size_t len; - int result = 0; - - /* init empty buffer. */ - result = scnprintf(buf, PAGE_SIZE, "\n"); - mutex_lock(&rc->ies_mutex); - /* walk IEData looking for an ASIE. */ - ptr = rc->ies->IEData; - len = le16_to_cpu(rc->ies->wIELength); - for (;;) { - ie = uwb_ie_next(&ptr, &len); - if (!ie) - break; - if (ie->element_id == UWB_APP_SPEC_IE) { - result = uwb_ie_dump_hex(ie, - ie->length + sizeof(struct uwb_ie_hdr), - buf, PAGE_SIZE); - break; - } - } - mutex_unlock(&rc->ies_mutex); - - return result; -} - -/* - * Update the ASIE that is broadcast in the UWB beacon by this uwb_rc device. - */ -static ssize_t ASIE_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - char ie_buf[255]; - int result, ie_len = 0; - const char *cur_ptr = buf; - struct uwb_ie_hdr *ie; - - /* empty string means clear the ASIE. */ - if (strlen(buf) <= 1) { - uwb_rc_ie_rm(rc, UWB_APP_SPEC_IE); - return size; - } - - /* if non-empty string, convert string of hex chars to binary. */ - while (ie_len < sizeof(ie_buf)) { - int char_count; - - if (sscanf(cur_ptr, " %02hhX %n", - &(ie_buf[ie_len]), &char_count) > 0) { - ++ie_len; - /* skip chars read from cur_ptr. */ - cur_ptr += char_count; - } else { - break; - } - } - - /* validate IE length and type. */ - if (ie_len < sizeof(struct uwb_ie_hdr)) { - dev_err(dev, "%s: Invalid ASIE size %d.\n", __func__, ie_len); - return -EINVAL; - } - - ie = (struct uwb_ie_hdr *)ie_buf; - if (ie->element_id != UWB_APP_SPEC_IE) { - dev_err(dev, "%s: Invalid IE element type size = 0x%02X.\n", - __func__, ie->element_id); - return -EINVAL; - } - - /* bounds check length field from user. */ - if (ie->length > (ie_len - sizeof(struct uwb_ie_hdr))) - ie->length = ie_len - sizeof(struct uwb_ie_hdr); - - /* - * Valid ASIE received. Remove current ASIE then add the new one using - * uwb_rc_ie_add. - */ - uwb_rc_ie_rm(rc, UWB_APP_SPEC_IE); - - result = uwb_rc_ie_add(rc, ie, ie->length + sizeof(struct uwb_ie_hdr)); - - return result >= 0 ? size : result; -} -static DEVICE_ATTR_RW(ASIE); - -static struct attribute *rc_attrs[] = { - &dev_attr_mac_address.attr, - &dev_attr_scan.attr, - &dev_attr_beacon.attr, - &dev_attr_ASIE.attr, - NULL, -}; - -static const struct attribute_group rc_attr_group = { - .attrs = rc_attrs, -}; - -/* - * Registration of sysfs specific stuff - */ -static int uwb_rc_sys_add(struct uwb_rc *rc) -{ - return sysfs_create_group(&rc->uwb_dev.dev.kobj, &rc_attr_group); -} - - -static void __uwb_rc_sys_rm(struct uwb_rc *rc) -{ - sysfs_remove_group(&rc->uwb_dev.dev.kobj, &rc_attr_group); -} - -/** - * uwb_rc_mac_addr_setup - get an RC's EUI-48 address or set it - * @rc: the radio controller. - * - * If the EUI-48 address is 00:00:00:00:00:00 or FF:FF:FF:FF:FF:FF - * then a random locally administered EUI-48 is generated and set on - * the device. The probability of address collisions is sufficiently - * unlikely (1/2^40 = 9.1e-13) that they're not checked for. - */ -static -int uwb_rc_mac_addr_setup(struct uwb_rc *rc) -{ - int result; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_dev *uwb_dev = &rc->uwb_dev; - char devname[UWB_ADDR_STRSIZE]; - struct uwb_mac_addr addr; - - result = uwb_rc_mac_addr_get(rc, &addr); - if (result < 0) { - dev_err(dev, "cannot retrieve UWB EUI-48 address: %d\n", result); - return result; - } - - if (uwb_mac_addr_unset(&addr) || uwb_mac_addr_bcast(&addr)) { - addr.data[0] = 0x02; /* locally administered and unicast */ - get_random_bytes(&addr.data[1], sizeof(addr.data)-1); - - result = uwb_rc_mac_addr_set(rc, &addr); - if (result < 0) { - uwb_mac_addr_print(devname, sizeof(devname), &addr); - dev_err(dev, "cannot set EUI-48 address %s: %d\n", - devname, result); - return result; - } - } - uwb_dev->mac_addr = addr; - return 0; -} - - - -static int uwb_rc_setup(struct uwb_rc *rc) -{ - int result; - struct device *dev = &rc->uwb_dev.dev; - - result = uwb_radio_setup(rc); - if (result < 0) { - dev_err(dev, "cannot setup UWB radio: %d\n", result); - goto error; - } - result = uwb_rc_mac_addr_setup(rc); - if (result < 0) { - dev_err(dev, "cannot setup UWB MAC address: %d\n", result); - goto error; - } - result = uwb_rc_dev_addr_assign(rc); - if (result < 0) { - dev_err(dev, "cannot assign UWB DevAddr: %d\n", result); - goto error; - } - result = uwb_rc_ie_setup(rc); - if (result < 0) { - dev_err(dev, "cannot setup IE subsystem: %d\n", result); - goto error_ie_setup; - } - result = uwb_rsv_setup(rc); - if (result < 0) { - dev_err(dev, "cannot setup reservation subsystem: %d\n", result); - goto error_rsv_setup; - } - uwb_dbg_add_rc(rc); - return 0; - -error_rsv_setup: - uwb_rc_ie_release(rc); -error_ie_setup: -error: - return result; -} - - -/** - * Register a new UWB radio controller - * - * Did you call uwb_rc_init() on your rc? - * - * We assume that this is being called with a > 0 refcount on - * it [through ops->{get|put}_device(). We'll take our own, though. - * - * @parent_dev is our real device, the one that provides the actual UWB device - */ -int uwb_rc_add(struct uwb_rc *rc, struct device *parent_dev, void *priv) -{ - int result; - struct device *dev; - char macbuf[UWB_ADDR_STRSIZE], devbuf[UWB_ADDR_STRSIZE]; - - rc->index = uwb_rc_new_index(); - - dev = &rc->uwb_dev.dev; - dev_set_name(dev, "uwb%d", rc->index); - - rc->priv = priv; - - init_waitqueue_head(&rc->uwbd.wq); - INIT_LIST_HEAD(&rc->uwbd.event_list); - spin_lock_init(&rc->uwbd.event_list_lock); - - uwbd_start(rc); - - result = rc->start(rc); - if (result < 0) - goto error_rc_start; - - result = uwb_rc_setup(rc); - if (result < 0) { - dev_err(dev, "cannot setup UWB radio controller: %d\n", result); - goto error_rc_setup; - } - - result = uwb_dev_add(&rc->uwb_dev, parent_dev, rc); - if (result < 0 && result != -EADDRNOTAVAIL) - goto error_dev_add; - - result = uwb_rc_sys_add(rc); - if (result < 0) { - dev_err(parent_dev, "cannot register UWB radio controller " - "dev attributes: %d\n", result); - goto error_sys_add; - } - - uwb_mac_addr_print(macbuf, sizeof(macbuf), &rc->uwb_dev.mac_addr); - uwb_dev_addr_print(devbuf, sizeof(devbuf), &rc->uwb_dev.dev_addr); - dev_info(dev, - "new uwb radio controller (mac %s dev %s) on %s %s\n", - macbuf, devbuf, parent_dev->bus->name, dev_name(parent_dev)); - rc->ready = 1; - return 0; - -error_sys_add: - uwb_dev_rm(&rc->uwb_dev); -error_dev_add: -error_rc_setup: - rc->stop(rc); -error_rc_start: - uwbd_stop(rc); - return result; -} -EXPORT_SYMBOL_GPL(uwb_rc_add); - - -static int uwb_dev_offair_helper(struct device *dev, void *priv) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - - return __uwb_dev_offair(uwb_dev, uwb_dev->rc); -} - -/* - * Remove a Radio Controller; stop beaconing/scanning, disconnect all children - */ -void uwb_rc_rm(struct uwb_rc *rc) -{ - rc->ready = 0; - - uwb_dbg_del_rc(rc); - uwb_rsv_remove_all(rc); - uwb_radio_shutdown(rc); - - rc->stop(rc); - - uwbd_stop(rc); - uwb_rc_neh_destroy(rc); - - uwb_dev_lock(&rc->uwb_dev); - rc->priv = NULL; - rc->cmd = NULL; - uwb_dev_unlock(&rc->uwb_dev); - mutex_lock(&rc->uwb_beca.mutex); - uwb_dev_for_each(rc, uwb_dev_offair_helper, NULL); - __uwb_rc_sys_rm(rc); - mutex_unlock(&rc->uwb_beca.mutex); - uwb_rsv_cleanup(rc); - uwb_beca_release(rc); - uwb_dev_rm(&rc->uwb_dev); -} -EXPORT_SYMBOL_GPL(uwb_rc_rm); - -static int find_rc_try_get(struct device *dev, const void *data) -{ - const struct uwb_rc *target_rc = data; - struct uwb_rc *rc = dev_get_drvdata(dev); - - if (rc == NULL) { - WARN_ON(1); - return 0; - } - if (rc == target_rc) { - if (rc->ready == 0) - return 0; - else - return 1; - } - return 0; -} - -/** - * Given a radio controller descriptor, validate and refcount it - * - * @returns NULL if the rc does not exist or is quiescing; the ptr to - * it otherwise. - */ -struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *target_rc) -{ - struct device *dev; - struct uwb_rc *rc = NULL; - - dev = class_find_device(&uwb_rc_class, NULL, target_rc, - find_rc_try_get); - if (dev) { - rc = dev_get_drvdata(dev); - __uwb_rc_get(rc); - put_device(dev); - } - - return rc; -} -EXPORT_SYMBOL_GPL(__uwb_rc_try_get); - -/* - * RC get for external refcount acquirers... - * - * Increments the refcount of the device and it's backend modules - */ -static inline struct uwb_rc *uwb_rc_get(struct uwb_rc *rc) -{ - if (rc->ready == 0) - return NULL; - uwb_dev_get(&rc->uwb_dev); - return rc; -} - -static int find_rc_grandpa(struct device *dev, const void *data) -{ - const struct device *grandpa_dev = data; - struct uwb_rc *rc = dev_get_drvdata(dev); - - if (rc->uwb_dev.dev.parent->parent == grandpa_dev) { - rc = uwb_rc_get(rc); - return 1; - } - return 0; -} - -/** - * Locate and refcount a radio controller given a common grand-parent - * - * @grandpa_dev Pointer to the 'grandparent' device structure. - * @returns NULL If the rc does not exist or is quiescing; the ptr to - * it otherwise, properly referenced. - * - * The Radio Control interface (or the UWB Radio Controller) is always - * an interface of a device. The parent is the interface, the - * grandparent is the device that encapsulates the interface. - * - * There is no need to lock around as the "grandpa" would be - * refcounted by the target, and to remove the referemes, the - * uwb_rc_class->sem would have to be taken--we hold it, ergo we - * should be safe. - */ -struct uwb_rc *uwb_rc_get_by_grandpa(const struct device *grandpa_dev) -{ - struct device *dev; - struct uwb_rc *rc = NULL; - - dev = class_find_device(&uwb_rc_class, NULL, grandpa_dev, - find_rc_grandpa); - if (dev) { - rc = dev_get_drvdata(dev); - put_device(dev); - } - - return rc; -} -EXPORT_SYMBOL_GPL(uwb_rc_get_by_grandpa); - -/** - * Find a radio controller by device address - * - * @returns the pointer to the radio controller, properly referenced - */ -static int find_rc_dev(struct device *dev, const void *data) -{ - const struct uwb_dev_addr *addr = data; - struct uwb_rc *rc = dev_get_drvdata(dev); - - if (rc == NULL) { - WARN_ON(1); - return 0; - } - if (!uwb_dev_addr_cmp(&rc->uwb_dev.dev_addr, addr)) { - rc = uwb_rc_get(rc); - return 1; - } - return 0; -} - -struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr *addr) -{ - struct device *dev; - struct uwb_rc *rc = NULL; - - dev = class_find_device(&uwb_rc_class, NULL, addr, find_rc_dev); - if (dev) { - rc = dev_get_drvdata(dev); - put_device(dev); - } - - return rc; -} -EXPORT_SYMBOL_GPL(uwb_rc_get_by_dev); - -/** - * Drop a reference on a radio controller - * - * This is the version that should be done by entities external to the - * UWB Radio Control stack (ie: clients of the API). - */ -void uwb_rc_put(struct uwb_rc *rc) -{ - __uwb_rc_put(rc); -} -EXPORT_SYMBOL_GPL(uwb_rc_put); diff --git a/drivers/staging/uwb/neh.c b/drivers/staging/uwb/neh.c deleted file mode 100644 index 1695584be412..000000000000 --- a/drivers/staging/uwb/neh.c +++ /dev/null @@ -1,606 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * WUSB Wire Adapter: Radio Control Interface (WUSB[8]) - * Notification and Event Handling - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * The RC interface of the Host Wire Adapter (USB dongle) or WHCI PCI - * card delivers a stream of notifications and events to the - * notification end event endpoint or area. This code takes care of - * getting a buffer with that data, breaking it up in separate - * notifications and events and then deliver those. - * - * Events are answers to commands and they carry a context ID that - * associates them to the command. Notifications are that, - * notifications, they come out of the blue and have a context ID of - * zero. Think of the context ID kind of like a handler. The - * uwb_rc_neh_* code deals with managing context IDs. - * - * This is why you require a handle to operate on a UWB host. When you - * open a handle a context ID is assigned to you. - * - * So, as it is done is: - * - * 1. Add an event handler [uwb_rc_neh_add()] (assigns a ctx id) - * 2. Issue command [rc->cmd(rc, ...)] - * 3. Arm the timeout timer [uwb_rc_neh_arm()] - * 4, Release the reference to the neh [uwb_rc_neh_put()] - * 5. Wait for the callback - * 6. Command result (RCEB) is passed to the callback - * - * If (2) fails, you should remove the handle [uwb_rc_neh_rm()] - * instead of arming the timer. - * - * Handles are for using in *serialized* code, single thread. - * - * When the notification/event comes, the IRQ handler/endpoint - * callback passes the data read to uwb_rc_neh_grok() which will break - * it up in a discrete series of events, look up who is listening for - * them and execute the pertinent callbacks. - * - * If the reader detects an error while reading the data stream, call - * uwb_rc_neh_error(). - * - * CONSTRAINTS/ASSUMPTIONS: - * - * - Most notifications/events are small (less thank .5k), copying - * around is ok. - * - * - Notifications/events are ALWAYS smaller than PAGE_SIZE - * - * - Notifications/events always come in a single piece (ie: a buffer - * will always contain entire notifications/events). - * - * - we cannot know in advance how long each event is (because they - * lack a length field in their header--smart move by the standards - * body, btw). So we need a facility to get the event size given the - * header. This is what the EST code does (notif/Event Size - * Tables), check nest.c--as well, you can associate the size to - * the handle [w/ neh->extra_size()]. - * - * - Most notifications/events are fixed size; only a few are variable - * size (NEST takes care of that). - * - * - Listeners of events expect them, so they usually provide a - * buffer, as they know the size. Listeners to notifications don't, - * so we allocate their buffers dynamically. - */ -#include <linux/kernel.h> -#include <linux/timer.h> -#include <linux/slab.h> -#include <linux/err.h> -#include <linux/export.h> - -#include "uwb-internal.h" - -/* - * UWB Radio Controller Notification/Event Handle - * - * Represents an entity waiting for an event coming from the UWB Radio - * Controller with a given context id (context) and type (evt_type and - * evt). On reception of the notification/event, the callback (cb) is - * called with the event. - * - * If the timer expires before the event is received, the callback is - * called with -ETIMEDOUT as the event size. - */ -struct uwb_rc_neh { - struct kref kref; - - struct uwb_rc *rc; - u8 evt_type; - __le16 evt; - u8 context; - u8 completed; - uwb_rc_cmd_cb_f cb; - void *arg; - - struct timer_list timer; - struct list_head list_node; -}; - -static void uwb_rc_neh_timer(struct timer_list *t); - -static void uwb_rc_neh_release(struct kref *kref) -{ - struct uwb_rc_neh *neh = container_of(kref, struct uwb_rc_neh, kref); - - kfree(neh); -} - -static void uwb_rc_neh_get(struct uwb_rc_neh *neh) -{ - kref_get(&neh->kref); -} - -/** - * uwb_rc_neh_put - release reference to a neh - * @neh: the neh - */ -void uwb_rc_neh_put(struct uwb_rc_neh *neh) -{ - kref_put(&neh->kref, uwb_rc_neh_release); -} - - -/** - * Assigns @neh a context id from @rc's pool - * - * @rc: UWB Radio Controller descriptor; @rc->neh_lock taken - * @neh: Notification/Event Handle - * @returns 0 if context id was assigned ok; < 0 errno on error (if - * all the context IDs are taken). - * - * (assumes @wa is locked). - * - * NOTE: WUSB spec reserves context ids 0x00 for notifications and - * 0xff is invalid, so they must not be used. Initialization - * fills up those two in the bitmap so they are not allocated. - * - * We spread the allocation around to reduce the possibility of two - * consecutive opened @neh's getting the same context ID assigned (to - * avoid surprises with late events that timed out long time ago). So - * first we search from where @rc->ctx_roll is, if not found, we - * search from zero. - */ -static -int __uwb_rc_ctx_get(struct uwb_rc *rc, struct uwb_rc_neh *neh) -{ - int result; - result = find_next_zero_bit(rc->ctx_bm, UWB_RC_CTX_MAX, - rc->ctx_roll++); - if (result < UWB_RC_CTX_MAX) - goto found; - result = find_first_zero_bit(rc->ctx_bm, UWB_RC_CTX_MAX); - if (result < UWB_RC_CTX_MAX) - goto found; - return -ENFILE; -found: - set_bit(result, rc->ctx_bm); - neh->context = result; - return 0; -} - - -/** Releases @neh's context ID back to @rc (@rc->neh_lock is locked). */ -static -void __uwb_rc_ctx_put(struct uwb_rc *rc, struct uwb_rc_neh *neh) -{ - struct device *dev = &rc->uwb_dev.dev; - if (neh->context == 0) - return; - if (test_bit(neh->context, rc->ctx_bm) == 0) { - dev_err(dev, "context %u not set in bitmap\n", - neh->context); - WARN_ON(1); - } - clear_bit(neh->context, rc->ctx_bm); - neh->context = 0; -} - -/** - * uwb_rc_neh_add - add a neh for a radio controller command - * @rc: the radio controller - * @cmd: the radio controller command - * @expected_type: the type of the expected response event - * @expected_event: the expected event ID - * @cb: callback for when the event is received - * @arg: argument for the callback - * - * Creates a neh and adds it to the list of those waiting for an - * event. A context ID will be assigned to the command. - */ -struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd, - u8 expected_type, u16 expected_event, - uwb_rc_cmd_cb_f cb, void *arg) -{ - int result; - unsigned long flags; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_neh *neh; - - neh = kzalloc(sizeof(*neh), GFP_KERNEL); - if (neh == NULL) { - result = -ENOMEM; - goto error_kzalloc; - } - - kref_init(&neh->kref); - INIT_LIST_HEAD(&neh->list_node); - timer_setup(&neh->timer, uwb_rc_neh_timer, 0); - - neh->rc = rc; - neh->evt_type = expected_type; - neh->evt = cpu_to_le16(expected_event); - neh->cb = cb; - neh->arg = arg; - - spin_lock_irqsave(&rc->neh_lock, flags); - result = __uwb_rc_ctx_get(rc, neh); - if (result >= 0) { - cmd->bCommandContext = neh->context; - list_add_tail(&neh->list_node, &rc->neh_list); - uwb_rc_neh_get(neh); - } - spin_unlock_irqrestore(&rc->neh_lock, flags); - if (result < 0) - goto error_ctx_get; - - return neh; - -error_ctx_get: - kfree(neh); -error_kzalloc: - dev_err(dev, "cannot open handle to radio controller: %d\n", result); - return ERR_PTR(result); -} - -static void __uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh) -{ - __uwb_rc_ctx_put(rc, neh); - list_del(&neh->list_node); -} - -/** - * uwb_rc_neh_rm - remove a neh. - * @rc: the radio controller - * @neh: the neh to remove - * - * Remove an active neh immediately instead of waiting for the event - * (or a time out). - */ -void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh) -{ - unsigned long flags; - - spin_lock_irqsave(&rc->neh_lock, flags); - __uwb_rc_neh_rm(rc, neh); - spin_unlock_irqrestore(&rc->neh_lock, flags); - - del_timer_sync(&neh->timer); - uwb_rc_neh_put(neh); -} - -/** - * uwb_rc_neh_arm - arm an event handler timeout timer - * - * @rc: UWB Radio Controller - * @neh: Notification/event handler for @rc - * - * The timer is only armed if the neh is active. - */ -void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh) -{ - unsigned long flags; - - spin_lock_irqsave(&rc->neh_lock, flags); - if (neh->context) - mod_timer(&neh->timer, - jiffies + msecs_to_jiffies(UWB_RC_CMD_TIMEOUT_MS)); - spin_unlock_irqrestore(&rc->neh_lock, flags); -} - -static void uwb_rc_neh_cb(struct uwb_rc_neh *neh, struct uwb_rceb *rceb, size_t size) -{ - (*neh->cb)(neh->rc, neh->arg, rceb, size); - uwb_rc_neh_put(neh); -} - -static bool uwb_rc_neh_match(struct uwb_rc_neh *neh, const struct uwb_rceb *rceb) -{ - return neh->evt_type == rceb->bEventType - && neh->evt == rceb->wEvent - && neh->context == rceb->bEventContext; -} - -/** - * Find the handle waiting for a RC Radio Control Event - * - * @rc: UWB Radio Controller - * @rceb: Pointer to the RCEB buffer - * @event_size: Pointer to the size of the RCEB buffer. Might be - * adjusted to take into account the @neh->extra_size - * settings. - * - * If the listener has no buffer (NULL buffer), one is allocated for - * the right size (the amount of data received). @neh->ptr will point - * to the event payload, which always starts with a 'struct - * uwb_rceb'. kfree() it when done. - */ -static -struct uwb_rc_neh *uwb_rc_neh_lookup(struct uwb_rc *rc, - const struct uwb_rceb *rceb) -{ - struct uwb_rc_neh *neh = NULL, *h; - unsigned long flags; - - spin_lock_irqsave(&rc->neh_lock, flags); - - list_for_each_entry(h, &rc->neh_list, list_node) { - if (uwb_rc_neh_match(h, rceb)) { - neh = h; - break; - } - } - - if (neh) - __uwb_rc_neh_rm(rc, neh); - - spin_unlock_irqrestore(&rc->neh_lock, flags); - - return neh; -} - - -/* - * Process notifications coming from the radio control interface - * - * @rc: UWB Radio Control Interface descriptor - * @neh: Notification/Event Handler @neh->ptr points to - * @uwb_evt->buffer. - * - * This function is called by the event/notif handling subsystem when - * notifications arrive (hwarc_probe() arms a notification/event handle - * that calls back this function for every received notification; this - * function then will rearm itself). - * - * Notification data buffers are dynamically allocated by the NEH - * handling code in neh.c [uwb_rc_neh_lookup()]. What is actually - * allocated is space to contain the notification data. - * - * Buffers are prefixed with a Radio Control Event Block (RCEB) as - * defined by the WUSB Wired-Adapter Radio Control interface. We - * just use it for the notification code. - * - * On each case statement we just transcode endianess of the different - * fields. We declare a pointer to a RCI definition of an event, and - * then to a UWB definition of the same event (which are the same, - * remember). Event if we use different pointers - */ -static -void uwb_rc_notif(struct uwb_rc *rc, struct uwb_rceb *rceb, ssize_t size) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_event *uwb_evt; - - if (size == -ESHUTDOWN) - return; - if (size < 0) { - dev_err(dev, "ignoring event with error code %zu\n", - size); - return; - } - - uwb_evt = kzalloc(sizeof(*uwb_evt), GFP_ATOMIC); - if (unlikely(uwb_evt == NULL)) { - dev_err(dev, "no memory to queue event 0x%02x/%04x/%02x\n", - rceb->bEventType, le16_to_cpu(rceb->wEvent), - rceb->bEventContext); - return; - } - uwb_evt->rc = __uwb_rc_get(rc); /* will be put by uwbd's uwbd_event_handle() */ - uwb_evt->ts_jiffies = jiffies; - uwb_evt->type = UWB_EVT_TYPE_NOTIF; - uwb_evt->notif.size = size; - uwb_evt->notif.rceb = rceb; - - uwbd_event_queue(uwb_evt); -} - -static void uwb_rc_neh_grok_event(struct uwb_rc *rc, struct uwb_rceb *rceb, size_t size) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_neh *neh; - struct uwb_rceb *notif; - unsigned long flags; - - if (rceb->bEventContext == 0) { - notif = kmalloc(size, GFP_ATOMIC); - if (notif) { - memcpy(notif, rceb, size); - uwb_rc_notif(rc, notif, size); - } else - dev_err(dev, "event 0x%02x/%04x/%02x (%zu bytes): no memory\n", - rceb->bEventType, le16_to_cpu(rceb->wEvent), - rceb->bEventContext, size); - } else { - neh = uwb_rc_neh_lookup(rc, rceb); - if (neh) { - spin_lock_irqsave(&rc->neh_lock, flags); - /* to guard against a timeout */ - neh->completed = 1; - del_timer(&neh->timer); - spin_unlock_irqrestore(&rc->neh_lock, flags); - uwb_rc_neh_cb(neh, rceb, size); - } else - dev_warn(dev, "event 0x%02x/%04x/%02x (%zu bytes): nobody cared\n", - rceb->bEventType, le16_to_cpu(rceb->wEvent), - rceb->bEventContext, size); - } -} - -/** - * Given a buffer with one or more UWB RC events/notifications, break - * them up and dispatch them. - * - * @rc: UWB Radio Controller - * @buf: Buffer with the stream of notifications/events - * @buf_size: Amount of data in the buffer - * - * Note each notification/event starts always with a 'struct - * uwb_rceb', so the minimum size if 4 bytes. - * - * The device may pass us events formatted differently than expected. - * These are first filtered, potentially creating a new event in a new - * memory location. If a new event is created by the filter it is also - * freed here. - * - * For each notif/event, tries to guess the size looking at the EST - * tables, then looks for a neh that is waiting for that event and if - * found, copies the payload to the neh's buffer and calls it back. If - * not, the data is ignored. - * - * Note that if we can't find a size description in the EST tables, we - * still might find a size in the 'neh' handle in uwb_rc_neh_lookup(). - * - * Assumptions: - * - * @rc->neh_lock is NOT taken - * - * We keep track of various sizes here: - * size: contains the size of the buffer that is processed for the - * incoming event. this buffer may contain events that are not - * formatted as WHCI. - * real_size: the actual space taken by this event in the buffer. - * We need to keep track of the real size of an event to be able to - * advance the buffer correctly. - * event_size: the size of the event as expected by the core layer - * [OR] the size of the event after filtering. if the filtering - * created a new event in a new memory location then this is - * effectively the size of a new event buffer - */ -void uwb_rc_neh_grok(struct uwb_rc *rc, void *buf, size_t buf_size) -{ - struct device *dev = &rc->uwb_dev.dev; - void *itr; - struct uwb_rceb *rceb; - size_t size, real_size, event_size; - int needtofree; - - itr = buf; - size = buf_size; - while (size > 0) { - if (size < sizeof(*rceb)) { - dev_err(dev, "not enough data in event buffer to " - "process incoming events (%zu left, minimum is " - "%zu)\n", size, sizeof(*rceb)); - break; - } - - rceb = itr; - if (rc->filter_event) { - needtofree = rc->filter_event(rc, &rceb, size, - &real_size, &event_size); - if (needtofree < 0 && needtofree != -ENOANO) { - dev_err(dev, "BUG: Unable to filter event " - "(0x%02x/%04x/%02x) from " - "device. \n", rceb->bEventType, - le16_to_cpu(rceb->wEvent), - rceb->bEventContext); - break; - } - } else - needtofree = -ENOANO; - /* do real processing if there was no filtering or the - * filtering didn't act */ - if (needtofree == -ENOANO) { - ssize_t ret = uwb_est_find_size(rc, rceb, size); - if (ret < 0) - break; - if (ret > size) { - dev_err(dev, "BUG: hw sent incomplete event " - "0x%02x/%04x/%02x (%zd bytes), only got " - "%zu bytes. We don't handle that.\n", - rceb->bEventType, le16_to_cpu(rceb->wEvent), - rceb->bEventContext, ret, size); - break; - } - real_size = event_size = ret; - } - uwb_rc_neh_grok_event(rc, rceb, event_size); - - if (needtofree == 1) - kfree(rceb); - - itr += real_size; - size -= real_size; - } -} -EXPORT_SYMBOL_GPL(uwb_rc_neh_grok); - - -/** - * The entity that reads from the device notification/event channel has - * detected an error. - * - * @rc: UWB Radio Controller - * @error: Errno error code - * - */ -void uwb_rc_neh_error(struct uwb_rc *rc, int error) -{ - struct uwb_rc_neh *neh; - unsigned long flags; - - for (;;) { - spin_lock_irqsave(&rc->neh_lock, flags); - if (list_empty(&rc->neh_list)) { - spin_unlock_irqrestore(&rc->neh_lock, flags); - break; - } - neh = list_first_entry(&rc->neh_list, struct uwb_rc_neh, list_node); - __uwb_rc_neh_rm(rc, neh); - spin_unlock_irqrestore(&rc->neh_lock, flags); - - del_timer_sync(&neh->timer); - uwb_rc_neh_cb(neh, NULL, error); - } -} -EXPORT_SYMBOL_GPL(uwb_rc_neh_error); - - -static void uwb_rc_neh_timer(struct timer_list *t) -{ - struct uwb_rc_neh *neh = from_timer(neh, t, timer); - struct uwb_rc *rc = neh->rc; - unsigned long flags; - - spin_lock_irqsave(&rc->neh_lock, flags); - if (neh->completed) { - spin_unlock_irqrestore(&rc->neh_lock, flags); - return; - } - if (neh->context) - __uwb_rc_neh_rm(rc, neh); - else - neh = NULL; - spin_unlock_irqrestore(&rc->neh_lock, flags); - - if (neh) - uwb_rc_neh_cb(neh, NULL, -ETIMEDOUT); -} - -/** Initializes the @rc's neh subsystem - */ -void uwb_rc_neh_create(struct uwb_rc *rc) -{ - spin_lock_init(&rc->neh_lock); - INIT_LIST_HEAD(&rc->neh_list); - set_bit(0, rc->ctx_bm); /* 0 is reserved (see [WUSB] table 8-65) */ - set_bit(0xff, rc->ctx_bm); /* and 0xff is invalid */ - rc->ctx_roll = 1; -} - - -/** Release's the @rc's neh subsystem */ -void uwb_rc_neh_destroy(struct uwb_rc *rc) -{ - unsigned long flags; - struct uwb_rc_neh *neh; - - for (;;) { - spin_lock_irqsave(&rc->neh_lock, flags); - if (list_empty(&rc->neh_list)) { - spin_unlock_irqrestore(&rc->neh_lock, flags); - break; - } - neh = list_first_entry(&rc->neh_list, struct uwb_rc_neh, list_node); - __uwb_rc_neh_rm(rc, neh); - spin_unlock_irqrestore(&rc->neh_lock, flags); - - del_timer_sync(&neh->timer); - uwb_rc_neh_put(neh); - } -} diff --git a/drivers/staging/uwb/pal.c b/drivers/staging/uwb/pal.c deleted file mode 100644 index a541e646a603..000000000000 --- a/drivers/staging/uwb/pal.c +++ /dev/null @@ -1,128 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB PAL support. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/debugfs.h> -#include <linux/export.h> - -#include "uwb.h" -#include "uwb-internal.h" - -/** - * uwb_pal_init - initialize a UWB PAL - * @pal: the PAL to initialize - */ -void uwb_pal_init(struct uwb_pal *pal) -{ - INIT_LIST_HEAD(&pal->node); -} -EXPORT_SYMBOL_GPL(uwb_pal_init); - -/** - * uwb_pal_register - register a UWB PAL - * @pal: the PAL - * - * The PAL must be initialized with uwb_pal_init(). - */ -int uwb_pal_register(struct uwb_pal *pal) -{ - struct uwb_rc *rc = pal->rc; - int ret; - - if (pal->device) { - /* create a link to the uwb_rc in the PAL device's directory. */ - ret = sysfs_create_link(&pal->device->kobj, - &rc->uwb_dev.dev.kobj, "uwb_rc"); - if (ret < 0) - return ret; - /* create a link to the PAL in the UWB device's directory. */ - ret = sysfs_create_link(&rc->uwb_dev.dev.kobj, - &pal->device->kobj, pal->name); - if (ret < 0) { - sysfs_remove_link(&pal->device->kobj, "uwb_rc"); - return ret; - } - } - - pal->debugfs_dir = uwb_dbg_create_pal_dir(pal); - - mutex_lock(&rc->uwb_dev.mutex); - list_add(&pal->node, &rc->pals); - mutex_unlock(&rc->uwb_dev.mutex); - - return 0; -} -EXPORT_SYMBOL_GPL(uwb_pal_register); - -static int find_rc(struct device *dev, const void *data) -{ - const struct uwb_rc *target_rc = data; - struct uwb_rc *rc = dev_get_drvdata(dev); - - if (rc == NULL) { - WARN_ON(1); - return 0; - } - if (rc == target_rc) { - if (rc->ready == 0) - return 0; - else - return 1; - } - return 0; -} - -/** - * Given a radio controller descriptor see if it is registered. - * - * @returns false if the rc does not exist or is quiescing; true otherwise. - */ -static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc) -{ - struct device *dev; - - dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc); - - put_device(dev); - - return (dev != NULL); -} - -/** - * uwb_pal_unregister - unregister a UWB PAL - * @pal: the PAL - */ -void uwb_pal_unregister(struct uwb_pal *pal) -{ - struct uwb_rc *rc = pal->rc; - - uwb_radio_stop(pal); - - mutex_lock(&rc->uwb_dev.mutex); - list_del(&pal->node); - mutex_unlock(&rc->uwb_dev.mutex); - - debugfs_remove(pal->debugfs_dir); - - if (pal->device) { - /* remove link to the PAL in the UWB device's directory. */ - if (uwb_rc_class_device_exists(rc)) - sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name); - - /* remove link to uwb_rc in the PAL device's directory. */ - sysfs_remove_link(&pal->device->kobj, "uwb_rc"); - } -} -EXPORT_SYMBOL_GPL(uwb_pal_unregister); - -/** - * uwb_rc_pal_init - initialize the PAL related parts of a radio controller - * @rc: the radio controller - */ -void uwb_rc_pal_init(struct uwb_rc *rc) -{ - INIT_LIST_HEAD(&rc->pals); -} diff --git a/drivers/staging/uwb/radio.c b/drivers/staging/uwb/radio.c deleted file mode 100644 index 6afb75ce1b5f..000000000000 --- a/drivers/staging/uwb/radio.c +++ /dev/null @@ -1,196 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB radio (channel) management. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/export.h> - -#include "uwb.h" -#include "uwb-internal.h" - - -static int uwb_radio_select_channel(struct uwb_rc *rc) -{ - /* - * Default to channel 9 (BG1, TFC1) unless the user has - * selected a specific channel or there are no active PALs. - */ - if (rc->active_pals == 0) - return -1; - if (rc->beaconing_forced) - return rc->beaconing_forced; - return 9; -} - - -/* - * Notify all active PALs that the channel has changed. - */ -static void uwb_radio_channel_changed(struct uwb_rc *rc, int channel) -{ - struct uwb_pal *pal; - - list_for_each_entry(pal, &rc->pals, node) { - if (pal->channel && channel != pal->channel) { - pal->channel = channel; - if (pal->channel_changed) - pal->channel_changed(pal, pal->channel); - } - } -} - -/* - * Change to a new channel and notify any active PALs of the new - * channel. - * - * When stopping the radio, PALs need to be notified first so they can - * terminate any active reservations. - */ -static int uwb_radio_change_channel(struct uwb_rc *rc, int channel) -{ - int ret = 0; - struct device *dev = &rc->uwb_dev.dev; - - dev_dbg(dev, "%s: channel = %d, rc->beaconing = %d\n", __func__, - channel, rc->beaconing); - - if (channel == -1) - uwb_radio_channel_changed(rc, channel); - - if (channel != rc->beaconing) { - if (rc->beaconing != -1 && channel != -1) { - /* - * FIXME: should signal the channel change - * with a Channel Change IE. - */ - ret = uwb_radio_change_channel(rc, -1); - if (ret < 0) - return ret; - } - ret = uwb_rc_beacon(rc, channel, 0); - } - - if (channel != -1) - uwb_radio_channel_changed(rc, rc->beaconing); - - return ret; -} - -/** - * uwb_radio_start - request that the radio be started - * @pal: the PAL making the request. - * - * If the radio is not already active, a suitable channel is selected - * and beacons are started. - */ -int uwb_radio_start(struct uwb_pal *pal) -{ - struct uwb_rc *rc = pal->rc; - int ret = 0; - - mutex_lock(&rc->uwb_dev.mutex); - - if (!pal->channel) { - pal->channel = -1; - rc->active_pals++; - ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); - } - - mutex_unlock(&rc->uwb_dev.mutex); - return ret; -} -EXPORT_SYMBOL_GPL(uwb_radio_start); - -/** - * uwb_radio_stop - request that the radio be stopped. - * @pal: the PAL making the request. - * - * Stops the radio if no other PAL is making use of it. - */ -void uwb_radio_stop(struct uwb_pal *pal) -{ - struct uwb_rc *rc = pal->rc; - - mutex_lock(&rc->uwb_dev.mutex); - - if (pal->channel) { - rc->active_pals--; - uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); - pal->channel = 0; - } - - mutex_unlock(&rc->uwb_dev.mutex); -} -EXPORT_SYMBOL_GPL(uwb_radio_stop); - -/* - * uwb_radio_force_channel - force a specific channel to be used - * @rc: the radio controller. - * @channel: the channel to use; -1 to force the radio to stop; 0 to - * use the default channel selection algorithm. - */ -int uwb_radio_force_channel(struct uwb_rc *rc, int channel) -{ - int ret = 0; - - mutex_lock(&rc->uwb_dev.mutex); - - rc->beaconing_forced = channel; - ret = uwb_radio_change_channel(rc, uwb_radio_select_channel(rc)); - - mutex_unlock(&rc->uwb_dev.mutex); - return ret; -} - -/* - * uwb_radio_setup - setup the radio manager - * @rc: the radio controller. - * - * The radio controller is reset to ensure it's in a known state - * before it's used. - */ -int uwb_radio_setup(struct uwb_rc *rc) -{ - return uwb_rc_reset(rc); -} - -/* - * uwb_radio_reset_state - reset any radio manager state - * @rc: the radio controller. - * - * All internal radio manager state is reset to values corresponding - * to a reset radio controller. - */ -void uwb_radio_reset_state(struct uwb_rc *rc) -{ - struct uwb_pal *pal; - - mutex_lock(&rc->uwb_dev.mutex); - - list_for_each_entry(pal, &rc->pals, node) { - if (pal->channel) { - pal->channel = -1; - if (pal->channel_changed) - pal->channel_changed(pal, -1); - } - } - - rc->beaconing = -1; - rc->scanning = -1; - - mutex_unlock(&rc->uwb_dev.mutex); -} - -/* - * uwb_radio_shutdown - shutdown the radio manager - * @rc: the radio controller. - * - * The radio controller is reset. - */ -void uwb_radio_shutdown(struct uwb_rc *rc) -{ - uwb_radio_reset_state(rc); - uwb_rc_reset(rc); -} diff --git a/drivers/staging/uwb/reset.c b/drivers/staging/uwb/reset.c deleted file mode 100644 index 8fc7c14d903e..000000000000 --- a/drivers/staging/uwb/reset.c +++ /dev/null @@ -1,379 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * UWB basic command support and radio reset - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: - * - * - docs - * - * - Now we are serializing (using the uwb_dev->mutex) the command - * execution; it should be parallelized as much as possible some - * day. - */ -#include <linux/kernel.h> -#include <linux/err.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include <linux/export.h> - -#include "uwb-internal.h" - -/** - * Command result codes (WUSB1.0[T8-69]) - */ -static -const char *__strerror[] = { - "success", - "failure", - "hardware failure", - "no more slots", - "beacon is too large", - "invalid parameter", - "unsupported power level", - "time out (wa) or invalid ie data (whci)", - "beacon size exceeded", - "cancelled", - "invalid state", - "invalid size", - "ack not received", - "no more asie notification", -}; - - -/** Return a string matching the given error code */ -const char *uwb_rc_strerror(unsigned code) -{ - if (code == 255) - return "time out"; - if (code >= ARRAY_SIZE(__strerror)) - return "unknown error"; - return __strerror[code]; -} - -int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - u8 expected_type, u16 expected_event, - uwb_rc_cmd_cb_f cb, void *arg) -{ - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_neh *neh; - int needtofree = 0; - int result; - - uwb_dev_lock(&rc->uwb_dev); /* Protect against rc->priv being removed */ - if (rc->priv == NULL) { - uwb_dev_unlock(&rc->uwb_dev); - return -ESHUTDOWN; - } - - if (rc->filter_cmd) { - needtofree = rc->filter_cmd(rc, &cmd, &cmd_size); - if (needtofree < 0 && needtofree != -ENOANO) { - dev_err(dev, "%s: filter error: %d\n", - cmd_name, needtofree); - uwb_dev_unlock(&rc->uwb_dev); - return needtofree; - } - } - - neh = uwb_rc_neh_add(rc, cmd, expected_type, expected_event, cb, arg); - if (IS_ERR(neh)) { - result = PTR_ERR(neh); - uwb_dev_unlock(&rc->uwb_dev); - goto out; - } - - result = rc->cmd(rc, cmd, cmd_size); - uwb_dev_unlock(&rc->uwb_dev); - if (result < 0) - uwb_rc_neh_rm(rc, neh); - else - uwb_rc_neh_arm(rc, neh); - uwb_rc_neh_put(neh); -out: - if (needtofree == 1) - kfree(cmd); - return result < 0 ? result : 0; -} -EXPORT_SYMBOL_GPL(uwb_rc_cmd_async); - -struct uwb_rc_cmd_done_params { - struct completion completion; - struct uwb_rceb *reply; - ssize_t reply_size; -}; - -static void uwb_rc_cmd_done(struct uwb_rc *rc, void *arg, - struct uwb_rceb *reply, ssize_t reply_size) -{ - struct uwb_rc_cmd_done_params *p = (struct uwb_rc_cmd_done_params *)arg; - - if (reply_size > 0) { - if (p->reply) - reply_size = min(p->reply_size, reply_size); - else - p->reply = kmalloc(reply_size, GFP_ATOMIC); - - if (p->reply) - memcpy(p->reply, reply, reply_size); - else - reply_size = -ENOMEM; - } - p->reply_size = reply_size; - complete(&p->completion); -} - - -/** - * Generic function for issuing commands to the Radio Control Interface - * - * @rc: UWB Radio Control descriptor - * @cmd_name: Name of the command being issued (for error messages) - * @cmd: Pointer to rccb structure containing the command; - * normally you embed this structure as the first member of - * the full command structure. - * @cmd_size: Size of the whole command buffer pointed to by @cmd. - * @reply: Pointer to where to store the reply - * @reply_size: @reply's size - * @expected_type: Expected type in the return event - * @expected_event: Expected event code in the return event - * @preply: Here a pointer to where the event data is received will - * be stored. Once done with the data, free with kfree(). - * - * This function is generic; it works for commands that return a fixed - * and known size or for commands that return a variable amount of data. - * - * If a buffer is provided, that is used, although it could be chopped - * to the maximum size of the buffer. If the buffer is NULL, then one - * be allocated in *preply with the whole contents of the reply. - * - * @rc needs to be referenced - */ -static -ssize_t __uwb_rc_cmd(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - struct uwb_rceb *reply, size_t reply_size, - u8 expected_type, u16 expected_event, - struct uwb_rceb **preply) -{ - ssize_t result = 0; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rc_cmd_done_params params; - - init_completion(¶ms.completion); - params.reply = reply; - params.reply_size = reply_size; - - result = uwb_rc_cmd_async(rc, cmd_name, cmd, cmd_size, - expected_type, expected_event, - uwb_rc_cmd_done, ¶ms); - if (result) - return result; - - wait_for_completion(¶ms.completion); - - if (preply) - *preply = params.reply; - - if (params.reply_size < 0) - dev_err(dev, "%s: confirmation event 0x%02x/%04x/%02x " - "reception failed: %d\n", cmd_name, - expected_type, expected_event, cmd->bCommandContext, - (int)params.reply_size); - return params.reply_size; -} - - -/** - * Generic function for issuing commands to the Radio Control Interface - * - * @rc: UWB Radio Control descriptor - * @cmd_name: Name of the command being issued (for error messages) - * @cmd: Pointer to rccb structure containing the command; - * normally you embed this structure as the first member of - * the full command structure. - * @cmd_size: Size of the whole command buffer pointed to by @cmd. - * @reply: Pointer to the beginning of the confirmation event - * buffer. Normally bigger than an 'struct hwarc_rceb'. - * You need to fill out reply->bEventType and reply->wEvent (in - * cpu order) as the function will use them to verify the - * confirmation event. - * @reply_size: Size of the reply buffer - * - * The function checks that the length returned in the reply is at - * least as big as @reply_size; if not, it will be deemed an error and - * -EIO returned. - * - * @rc needs to be referenced - */ -ssize_t uwb_rc_cmd(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - struct uwb_rceb *reply, size_t reply_size) -{ - struct device *dev = &rc->uwb_dev.dev; - ssize_t result; - - result = __uwb_rc_cmd(rc, cmd_name, - cmd, cmd_size, reply, reply_size, - reply->bEventType, reply->wEvent, NULL); - - if (result > 0 && result < reply_size) { - dev_err(dev, "%s: not enough data returned for decoding reply " - "(%zu bytes received vs at least %zu needed)\n", - cmd_name, result, reply_size); - result = -EIO; - } - return result; -} -EXPORT_SYMBOL_GPL(uwb_rc_cmd); - - -/** - * Generic function for issuing commands to the Radio Control - * Interface that return an unknown amount of data - * - * @rc: UWB Radio Control descriptor - * @cmd_name: Name of the command being issued (for error messages) - * @cmd: Pointer to rccb structure containing the command; - * normally you embed this structure as the first member of - * the full command structure. - * @cmd_size: Size of the whole command buffer pointed to by @cmd. - * @expected_type: Expected type in the return event - * @expected_event: Expected event code in the return event - * @preply: Here a pointer to where the event data is received will - * be stored. Once done with the data, free with kfree(). - * - * The function checks that the length returned in the reply is at - * least as big as a 'struct uwb_rceb *'; if not, it will be deemed an - * error and -EIO returned. - * - * @rc needs to be referenced - */ -ssize_t uwb_rc_vcmd(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - u8 expected_type, u16 expected_event, - struct uwb_rceb **preply) -{ - return __uwb_rc_cmd(rc, cmd_name, cmd, cmd_size, NULL, 0, - expected_type, expected_event, preply); -} -EXPORT_SYMBOL_GPL(uwb_rc_vcmd); - - -/** - * Reset a UWB Host Controller (and all radio settings) - * - * @rc: Host Controller descriptor - * @returns: 0 if ok, < 0 errno code on error - * - * We put the command on kmalloc'ed memory as some arches cannot do - * USB from the stack. The reply event is copied from an stage buffer, - * so it can be in the stack. See WUSB1.0[8.6.2.4] for more details. - */ -int uwb_rc_reset(struct uwb_rc *rc) -{ - int result = -ENOMEM; - struct uwb_rc_evt_confirm reply; - struct uwb_rccb *cmd; - size_t cmd_size = sizeof(*cmd); - - mutex_lock(&rc->uwb_dev.mutex); - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - goto error_kzalloc; - cmd->bCommandType = UWB_RC_CET_GENERAL; - cmd->wCommand = cpu_to_le16(UWB_RC_CMD_RESET); - reply.rceb.bEventType = UWB_RC_CET_GENERAL; - reply.rceb.wEvent = UWB_RC_CMD_RESET; - result = uwb_rc_cmd(rc, "RESET", cmd, cmd_size, - &reply.rceb, sizeof(reply)); - if (result < 0) - goto error_cmd; - if (reply.bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(&rc->uwb_dev.dev, - "RESET: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply.bResultCode), reply.bResultCode); - result = -EIO; - } -error_cmd: - kfree(cmd); -error_kzalloc: - mutex_unlock(&rc->uwb_dev.mutex); - return result; -} - -int uwbd_msg_handle_reset(struct uwb_event *evt) -{ - struct uwb_rc *rc = evt->rc; - int ret; - - dev_info(&rc->uwb_dev.dev, "resetting radio controller\n"); - ret = rc->reset(rc); - if (ret < 0) { - dev_err(&rc->uwb_dev.dev, "failed to reset hardware: %d\n", ret); - goto error; - } - return 0; -error: - /* Nothing can be done except try the reset again. Wait a bit - to avoid reset loops during probe() or remove(). */ - msleep(1000); - uwb_rc_reset_all(rc); - return ret; -} - -/** - * uwb_rc_reset_all - request a reset of the radio controller and PALs - * @rc: the radio controller of the hardware device to be reset. - * - * The full hardware reset of the radio controller and all the PALs - * will be scheduled. - */ -void uwb_rc_reset_all(struct uwb_rc *rc) -{ - struct uwb_event *evt; - - evt = kzalloc(sizeof(struct uwb_event), GFP_ATOMIC); - if (unlikely(evt == NULL)) - return; - - evt->rc = __uwb_rc_get(rc); /* will be put by uwbd's uwbd_event_handle() */ - evt->ts_jiffies = jiffies; - evt->type = UWB_EVT_TYPE_MSG; - evt->message = UWB_EVT_MSG_RESET; - - uwbd_event_queue(evt); -} -EXPORT_SYMBOL_GPL(uwb_rc_reset_all); - -void uwb_rc_pre_reset(struct uwb_rc *rc) -{ - rc->stop(rc); - uwbd_flush(rc); - - uwb_radio_reset_state(rc); - uwb_rsv_remove_all(rc); -} -EXPORT_SYMBOL_GPL(uwb_rc_pre_reset); - -int uwb_rc_post_reset(struct uwb_rc *rc) -{ - int ret; - - ret = rc->start(rc); - if (ret) - goto out; - ret = uwb_rc_mac_addr_set(rc, &rc->uwb_dev.mac_addr); - if (ret) - goto out; - ret = uwb_rc_dev_addr_set(rc, &rc->uwb_dev.dev_addr); - if (ret) - goto out; -out: - return ret; -} -EXPORT_SYMBOL_GPL(uwb_rc_post_reset); diff --git a/drivers/staging/uwb/rsv.c b/drivers/staging/uwb/rsv.c deleted file mode 100644 index d593a41c3d8d..000000000000 --- a/drivers/staging/uwb/rsv.c +++ /dev/null @@ -1,1000 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB reservation management. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/random.h> -#include <linux/export.h> - -#include "uwb.h" -#include "uwb-internal.h" - -static void uwb_rsv_timer(struct timer_list *t); - -static const char *rsv_states[] = { - [UWB_RSV_STATE_NONE] = "none ", - [UWB_RSV_STATE_O_INITIATED] = "o initiated ", - [UWB_RSV_STATE_O_PENDING] = "o pending ", - [UWB_RSV_STATE_O_MODIFIED] = "o modified ", - [UWB_RSV_STATE_O_ESTABLISHED] = "o established ", - [UWB_RSV_STATE_O_TO_BE_MOVED] = "o to be moved ", - [UWB_RSV_STATE_O_MOVE_EXPANDING] = "o move expanding", - [UWB_RSV_STATE_O_MOVE_COMBINING] = "o move combining", - [UWB_RSV_STATE_O_MOVE_REDUCING] = "o move reducing ", - [UWB_RSV_STATE_T_ACCEPTED] = "t accepted ", - [UWB_RSV_STATE_T_CONFLICT] = "t conflict ", - [UWB_RSV_STATE_T_PENDING] = "t pending ", - [UWB_RSV_STATE_T_DENIED] = "t denied ", - [UWB_RSV_STATE_T_RESIZED] = "t resized ", - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = "t expanding acc ", - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = "t expanding conf", - [UWB_RSV_STATE_T_EXPANDING_PENDING] = "t expanding pend", - [UWB_RSV_STATE_T_EXPANDING_DENIED] = "t expanding den ", -}; - -static const char *rsv_types[] = { - [UWB_DRP_TYPE_ALIEN_BP] = "alien-bp", - [UWB_DRP_TYPE_HARD] = "hard", - [UWB_DRP_TYPE_SOFT] = "soft", - [UWB_DRP_TYPE_PRIVATE] = "private", - [UWB_DRP_TYPE_PCA] = "pca", -}; - -bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv) -{ - static const bool has_two_drp_ies[] = { - [UWB_RSV_STATE_O_INITIATED] = false, - [UWB_RSV_STATE_O_PENDING] = false, - [UWB_RSV_STATE_O_MODIFIED] = false, - [UWB_RSV_STATE_O_ESTABLISHED] = false, - [UWB_RSV_STATE_O_TO_BE_MOVED] = false, - [UWB_RSV_STATE_O_MOVE_COMBINING] = false, - [UWB_RSV_STATE_O_MOVE_REDUCING] = false, - [UWB_RSV_STATE_O_MOVE_EXPANDING] = true, - [UWB_RSV_STATE_T_ACCEPTED] = false, - [UWB_RSV_STATE_T_CONFLICT] = false, - [UWB_RSV_STATE_T_PENDING] = false, - [UWB_RSV_STATE_T_DENIED] = false, - [UWB_RSV_STATE_T_RESIZED] = false, - [UWB_RSV_STATE_T_EXPANDING_ACCEPTED] = true, - [UWB_RSV_STATE_T_EXPANDING_CONFLICT] = true, - [UWB_RSV_STATE_T_EXPANDING_PENDING] = true, - [UWB_RSV_STATE_T_EXPANDING_DENIED] = true, - }; - - return has_two_drp_ies[rsv->state]; -} - -/** - * uwb_rsv_state_str - return a string for a reservation state - * @state: the reservation state. - */ -const char *uwb_rsv_state_str(enum uwb_rsv_state state) -{ - if (state < UWB_RSV_STATE_NONE || state >= UWB_RSV_STATE_LAST) - return "unknown"; - return rsv_states[state]; -} -EXPORT_SYMBOL_GPL(uwb_rsv_state_str); - -/** - * uwb_rsv_type_str - return a string for a reservation type - * @type: the reservation type - */ -const char *uwb_rsv_type_str(enum uwb_drp_type type) -{ - if (type < UWB_DRP_TYPE_ALIEN_BP || type > UWB_DRP_TYPE_PCA) - return "invalid"; - return rsv_types[type]; -} -EXPORT_SYMBOL_GPL(uwb_rsv_type_str); - -void uwb_rsv_dump(char *text, struct uwb_rsv *rsv) -{ - struct device *dev = &rsv->rc->uwb_dev.dev; - struct uwb_dev_addr devaddr; - char owner[UWB_ADDR_STRSIZE], target[UWB_ADDR_STRSIZE]; - - uwb_dev_addr_print(owner, sizeof(owner), &rsv->owner->dev_addr); - if (rsv->target.type == UWB_RSV_TARGET_DEV) - devaddr = rsv->target.dev->dev_addr; - else - devaddr = rsv->target.devaddr; - uwb_dev_addr_print(target, sizeof(target), &devaddr); - - dev_dbg(dev, "rsv %s %s -> %s: %s\n", - text, owner, target, uwb_rsv_state_str(rsv->state)); -} - -static void uwb_rsv_release(struct kref *kref) -{ - struct uwb_rsv *rsv = container_of(kref, struct uwb_rsv, kref); - - kfree(rsv); -} - -void uwb_rsv_get(struct uwb_rsv *rsv) -{ - kref_get(&rsv->kref); -} - -void uwb_rsv_put(struct uwb_rsv *rsv) -{ - kref_put(&rsv->kref, uwb_rsv_release); -} - -/* - * Get a free stream index for a reservation. - * - * If the target is a DevAddr (e.g., a WUSB cluster reservation) then - * the stream is allocated from a pool of per-RC stream indexes, - * otherwise a unique stream index for the target is selected. - */ -static int uwb_rsv_get_stream(struct uwb_rsv *rsv) -{ - struct uwb_rc *rc = rsv->rc; - struct device *dev = &rc->uwb_dev.dev; - unsigned long *streams_bm; - int stream; - - switch (rsv->target.type) { - case UWB_RSV_TARGET_DEV: - streams_bm = rsv->target.dev->streams; - break; - case UWB_RSV_TARGET_DEVADDR: - streams_bm = rc->uwb_dev.streams; - break; - default: - return -EINVAL; - } - - stream = find_first_zero_bit(streams_bm, UWB_NUM_STREAMS); - if (stream >= UWB_NUM_STREAMS) { - dev_err(dev, "%s: no available stream found\n", __func__); - return -EBUSY; - } - - rsv->stream = stream; - set_bit(stream, streams_bm); - - dev_dbg(dev, "get stream %d\n", rsv->stream); - - return 0; -} - -static void uwb_rsv_put_stream(struct uwb_rsv *rsv) -{ - struct uwb_rc *rc = rsv->rc; - struct device *dev = &rc->uwb_dev.dev; - unsigned long *streams_bm; - - switch (rsv->target.type) { - case UWB_RSV_TARGET_DEV: - streams_bm = rsv->target.dev->streams; - break; - case UWB_RSV_TARGET_DEVADDR: - streams_bm = rc->uwb_dev.streams; - break; - default: - return; - } - - clear_bit(rsv->stream, streams_bm); - - dev_dbg(dev, "put stream %d\n", rsv->stream); -} - -void uwb_rsv_backoff_win_timer(struct timer_list *t) -{ - struct uwb_drp_backoff_win *bow = from_timer(bow, t, timer); - struct uwb_rc *rc = container_of(bow, struct uwb_rc, bow); - struct device *dev = &rc->uwb_dev.dev; - - bow->can_reserve_extra_mases = true; - if (bow->total_expired <= 4) { - bow->total_expired++; - } else { - /* after 4 backoff window has expired we can exit from - * the backoff procedure */ - bow->total_expired = 0; - bow->window = UWB_DRP_BACKOFF_WIN_MIN >> 1; - } - dev_dbg(dev, "backoff_win_timer total_expired=%d, n=%d\n", bow->total_expired, bow->n); - - /* try to relocate all the "to be moved" relocations */ - uwb_rsv_handle_drp_avail_change(rc); -} - -void uwb_rsv_backoff_win_increment(struct uwb_rc *rc) -{ - struct uwb_drp_backoff_win *bow = &rc->bow; - struct device *dev = &rc->uwb_dev.dev; - unsigned timeout_us; - - dev_dbg(dev, "backoff_win_increment: window=%d\n", bow->window); - - bow->can_reserve_extra_mases = false; - - if((bow->window << 1) == UWB_DRP_BACKOFF_WIN_MAX) - return; - - bow->window <<= 1; - bow->n = prandom_u32() & (bow->window - 1); - dev_dbg(dev, "new_window=%d, n=%d\n", bow->window, bow->n); - - /* reset the timer associated variables */ - timeout_us = bow->n * UWB_SUPERFRAME_LENGTH_US; - bow->total_expired = 0; - mod_timer(&bow->timer, jiffies + usecs_to_jiffies(timeout_us)); -} - -static void uwb_rsv_stroke_timer(struct uwb_rsv *rsv) -{ - int sframes = UWB_MAX_LOST_BEACONS; - - /* - * Multicast reservations can become established within 1 - * super frame and should not be terminated if no response is - * received. - */ - if (rsv->state == UWB_RSV_STATE_NONE) { - sframes = 0; - } else if (rsv->is_multicast) { - if (rsv->state == UWB_RSV_STATE_O_INITIATED - || rsv->state == UWB_RSV_STATE_O_MOVE_EXPANDING - || rsv->state == UWB_RSV_STATE_O_MOVE_COMBINING - || rsv->state == UWB_RSV_STATE_O_MOVE_REDUCING) - sframes = 1; - if (rsv->state == UWB_RSV_STATE_O_ESTABLISHED) - sframes = 0; - - } - - if (sframes > 0) { - /* - * Add an additional 2 superframes to account for the - * time to send the SET DRP IE command. - */ - unsigned timeout_us = (sframes + 2) * UWB_SUPERFRAME_LENGTH_US; - mod_timer(&rsv->timer, jiffies + usecs_to_jiffies(timeout_us)); - } else - del_timer(&rsv->timer); -} - -/* - * Update a reservations state, and schedule an update of the - * transmitted DRP IEs. - */ -static void uwb_rsv_state_update(struct uwb_rsv *rsv, - enum uwb_rsv_state new_state) -{ - rsv->state = new_state; - rsv->ie_valid = false; - - uwb_rsv_dump("SU", rsv); - - uwb_rsv_stroke_timer(rsv); - uwb_rsv_sched_update(rsv->rc); -} - -static void uwb_rsv_callback(struct uwb_rsv *rsv) -{ - if (rsv->callback) - rsv->callback(rsv); -} - -void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state) -{ - struct uwb_rsv_move *mv = &rsv->mv; - - if (rsv->state == new_state) { - switch (rsv->state) { - case UWB_RSV_STATE_O_ESTABLISHED: - case UWB_RSV_STATE_O_MOVE_EXPANDING: - case UWB_RSV_STATE_O_MOVE_COMBINING: - case UWB_RSV_STATE_O_MOVE_REDUCING: - case UWB_RSV_STATE_T_ACCEPTED: - case UWB_RSV_STATE_T_EXPANDING_ACCEPTED: - case UWB_RSV_STATE_T_RESIZED: - case UWB_RSV_STATE_NONE: - uwb_rsv_stroke_timer(rsv); - break; - default: - /* Expecting a state transition so leave timer - as-is. */ - break; - } - return; - } - - uwb_rsv_dump("SC", rsv); - - switch (new_state) { - case UWB_RSV_STATE_NONE: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_NONE); - uwb_rsv_remove(rsv); - uwb_rsv_callback(rsv); - break; - case UWB_RSV_STATE_O_INITIATED: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_INITIATED); - break; - case UWB_RSV_STATE_O_PENDING: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_PENDING); - break; - case UWB_RSV_STATE_O_MODIFIED: - /* in the companion there are the MASes to drop */ - bitmap_andnot(rsv->mas.bm, rsv->mas.bm, mv->companion_mas.bm, UWB_NUM_MAS); - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_MODIFIED); - break; - case UWB_RSV_STATE_O_ESTABLISHED: - if (rsv->state == UWB_RSV_STATE_O_MODIFIED - || rsv->state == UWB_RSV_STATE_O_MOVE_REDUCING) { - uwb_drp_avail_release(rsv->rc, &mv->companion_mas); - rsv->needs_release_companion_mas = false; - } - uwb_drp_avail_reserve(rsv->rc, &rsv->mas); - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_ESTABLISHED); - uwb_rsv_callback(rsv); - break; - case UWB_RSV_STATE_O_MOVE_EXPANDING: - rsv->needs_release_companion_mas = true; - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_MOVE_EXPANDING); - break; - case UWB_RSV_STATE_O_MOVE_COMBINING: - rsv->needs_release_companion_mas = false; - uwb_drp_avail_reserve(rsv->rc, &mv->companion_mas); - bitmap_or(rsv->mas.bm, rsv->mas.bm, mv->companion_mas.bm, UWB_NUM_MAS); - rsv->mas.safe += mv->companion_mas.safe; - rsv->mas.unsafe += mv->companion_mas.unsafe; - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_MOVE_COMBINING); - break; - case UWB_RSV_STATE_O_MOVE_REDUCING: - bitmap_andnot(mv->companion_mas.bm, rsv->mas.bm, mv->final_mas.bm, UWB_NUM_MAS); - rsv->needs_release_companion_mas = true; - rsv->mas.safe = mv->final_mas.safe; - rsv->mas.unsafe = mv->final_mas.unsafe; - bitmap_copy(rsv->mas.bm, mv->final_mas.bm, UWB_NUM_MAS); - bitmap_copy(rsv->mas.unsafe_bm, mv->final_mas.unsafe_bm, UWB_NUM_MAS); - uwb_rsv_state_update(rsv, UWB_RSV_STATE_O_MOVE_REDUCING); - break; - case UWB_RSV_STATE_T_ACCEPTED: - case UWB_RSV_STATE_T_RESIZED: - rsv->needs_release_companion_mas = false; - uwb_drp_avail_reserve(rsv->rc, &rsv->mas); - uwb_rsv_state_update(rsv, UWB_RSV_STATE_T_ACCEPTED); - uwb_rsv_callback(rsv); - break; - case UWB_RSV_STATE_T_DENIED: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_T_DENIED); - break; - case UWB_RSV_STATE_T_CONFLICT: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_T_CONFLICT); - break; - case UWB_RSV_STATE_T_PENDING: - uwb_rsv_state_update(rsv, UWB_RSV_STATE_T_PENDING); - break; - case UWB_RSV_STATE_T_EXPANDING_ACCEPTED: - rsv->needs_release_companion_mas = true; - uwb_drp_avail_reserve(rsv->rc, &mv->companion_mas); - uwb_rsv_state_update(rsv, UWB_RSV_STATE_T_EXPANDING_ACCEPTED); - break; - default: - dev_err(&rsv->rc->uwb_dev.dev, "unhandled state: %s (%d)\n", - uwb_rsv_state_str(new_state), new_state); - } -} - -static void uwb_rsv_handle_timeout_work(struct work_struct *work) -{ - struct uwb_rsv *rsv = container_of(work, struct uwb_rsv, - handle_timeout_work); - struct uwb_rc *rc = rsv->rc; - - mutex_lock(&rc->rsvs_mutex); - - uwb_rsv_dump("TO", rsv); - - switch (rsv->state) { - case UWB_RSV_STATE_O_INITIATED: - if (rsv->is_multicast) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_ESTABLISHED); - goto unlock; - } - break; - case UWB_RSV_STATE_O_MOVE_EXPANDING: - if (rsv->is_multicast) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_COMBINING); - goto unlock; - } - break; - case UWB_RSV_STATE_O_MOVE_COMBINING: - if (rsv->is_multicast) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_REDUCING); - goto unlock; - } - break; - case UWB_RSV_STATE_O_MOVE_REDUCING: - if (rsv->is_multicast) { - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_ESTABLISHED); - goto unlock; - } - break; - case UWB_RSV_STATE_O_ESTABLISHED: - if (rsv->is_multicast) - goto unlock; - break; - case UWB_RSV_STATE_T_EXPANDING_ACCEPTED: - /* - * The time out could be for the main or of the - * companion DRP, assume it's for the companion and - * drop that first. A further time out is required to - * drop the main. - */ - uwb_rsv_set_state(rsv, UWB_RSV_STATE_T_ACCEPTED); - uwb_drp_avail_release(rsv->rc, &rsv->mv.companion_mas); - goto unlock; - case UWB_RSV_STATE_NONE: - goto unlock; - default: - break; - } - - uwb_rsv_remove(rsv); - -unlock: - mutex_unlock(&rc->rsvs_mutex); -} - -static struct uwb_rsv *uwb_rsv_alloc(struct uwb_rc *rc) -{ - struct uwb_rsv *rsv; - - rsv = kzalloc(sizeof(struct uwb_rsv), GFP_KERNEL); - if (!rsv) - return NULL; - - INIT_LIST_HEAD(&rsv->rc_node); - INIT_LIST_HEAD(&rsv->pal_node); - kref_init(&rsv->kref); - timer_setup(&rsv->timer, uwb_rsv_timer, 0); - - rsv->rc = rc; - INIT_WORK(&rsv->handle_timeout_work, uwb_rsv_handle_timeout_work); - - return rsv; -} - -/** - * uwb_rsv_create - allocate and initialize a UWB reservation structure - * @rc: the radio controller - * @cb: callback to use when the reservation completes or terminates - * @pal_priv: data private to the PAL to be passed in the callback - * - * The callback is called when the state of the reservation changes from: - * - * - pending to accepted - * - pending to denined - * - accepted to terminated - * - pending to terminated - */ -struct uwb_rsv *uwb_rsv_create(struct uwb_rc *rc, uwb_rsv_cb_f cb, void *pal_priv) -{ - struct uwb_rsv *rsv; - - rsv = uwb_rsv_alloc(rc); - if (!rsv) - return NULL; - - rsv->callback = cb; - rsv->pal_priv = pal_priv; - - return rsv; -} -EXPORT_SYMBOL_GPL(uwb_rsv_create); - -void uwb_rsv_remove(struct uwb_rsv *rsv) -{ - uwb_rsv_dump("RM", rsv); - - if (rsv->state != UWB_RSV_STATE_NONE) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); - - if (rsv->needs_release_companion_mas) - uwb_drp_avail_release(rsv->rc, &rsv->mv.companion_mas); - uwb_drp_avail_release(rsv->rc, &rsv->mas); - - if (uwb_rsv_is_owner(rsv)) - uwb_rsv_put_stream(rsv); - - uwb_dev_put(rsv->owner); - if (rsv->target.type == UWB_RSV_TARGET_DEV) - uwb_dev_put(rsv->target.dev); - - list_del_init(&rsv->rc_node); - uwb_rsv_put(rsv); -} - -/** - * uwb_rsv_destroy - free a UWB reservation structure - * @rsv: the reservation to free - * - * The reservation must already be terminated. - */ -void uwb_rsv_destroy(struct uwb_rsv *rsv) -{ - uwb_rsv_put(rsv); -} -EXPORT_SYMBOL_GPL(uwb_rsv_destroy); - -/** - * usb_rsv_establish - start a reservation establishment - * @rsv: the reservation - * - * The PAL should fill in @rsv's owner, target, type, max_mas, - * min_mas, max_interval and is_multicast fields. If the target is a - * uwb_dev it must be referenced. - * - * The reservation's callback will be called when the reservation is - * accepted, denied or times out. - */ -int uwb_rsv_establish(struct uwb_rsv *rsv) -{ - struct uwb_rc *rc = rsv->rc; - struct uwb_mas_bm available; - struct device *dev = &rc->uwb_dev.dev; - int ret; - - mutex_lock(&rc->rsvs_mutex); - ret = uwb_rsv_get_stream(rsv); - if (ret) { - dev_err(dev, "%s: uwb_rsv_get_stream failed: %d\n", - __func__, ret); - goto out; - } - - rsv->tiebreaker = prandom_u32() & 1; - /* get available mas bitmap */ - uwb_drp_available(rc, &available); - - ret = uwb_rsv_find_best_allocation(rsv, &available, &rsv->mas); - if (ret == UWB_RSV_ALLOC_NOT_FOUND) { - ret = -EBUSY; - uwb_rsv_put_stream(rsv); - dev_err(dev, "%s: uwb_rsv_find_best_allocation failed: %d\n", - __func__, ret); - goto out; - } - - ret = uwb_drp_avail_reserve_pending(rc, &rsv->mas); - if (ret != 0) { - uwb_rsv_put_stream(rsv); - dev_err(dev, "%s: uwb_drp_avail_reserve_pending failed: %d\n", - __func__, ret); - goto out; - } - - uwb_rsv_get(rsv); - list_add_tail(&rsv->rc_node, &rc->reservations); - rsv->owner = &rc->uwb_dev; - uwb_dev_get(rsv->owner); - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_INITIATED); -out: - mutex_unlock(&rc->rsvs_mutex); - return ret; -} -EXPORT_SYMBOL_GPL(uwb_rsv_establish); - -/** - * uwb_rsv_modify - modify an already established reservation - * @rsv: the reservation to modify - * @max_mas: new maximum MAS to reserve - * @min_mas: new minimum MAS to reserve - * @max_interval: new max_interval to use - * - * FIXME: implement this once there are PALs that use it. - */ -int uwb_rsv_modify(struct uwb_rsv *rsv, int max_mas, int min_mas, int max_interval) -{ - return -ENOSYS; -} -EXPORT_SYMBOL_GPL(uwb_rsv_modify); - -/* - * move an already established reservation (rc->rsvs_mutex must to be - * taken when tis function is called) - */ -int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available) -{ - struct uwb_rc *rc = rsv->rc; - struct uwb_drp_backoff_win *bow = &rc->bow; - struct device *dev = &rc->uwb_dev.dev; - struct uwb_rsv_move *mv; - int ret = 0; - - if (!bow->can_reserve_extra_mases) - return -EBUSY; - - mv = &rsv->mv; - - if (uwb_rsv_find_best_allocation(rsv, available, &mv->final_mas) == UWB_RSV_ALLOC_FOUND) { - - if (!bitmap_equal(rsv->mas.bm, mv->final_mas.bm, UWB_NUM_MAS)) { - /* We want to move the reservation */ - bitmap_andnot(mv->companion_mas.bm, mv->final_mas.bm, rsv->mas.bm, UWB_NUM_MAS); - uwb_drp_avail_reserve_pending(rc, &mv->companion_mas); - uwb_rsv_set_state(rsv, UWB_RSV_STATE_O_MOVE_EXPANDING); - } - } else { - dev_dbg(dev, "new allocation not found\n"); - } - - return ret; -} - -/* It will try to move every reservation in state O_ESTABLISHED giving - * to the MAS allocator algorithm an availability that is the real one - * plus the allocation already established from the reservation. */ -void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc) -{ - struct uwb_drp_backoff_win *bow = &rc->bow; - struct uwb_rsv *rsv; - struct uwb_mas_bm mas; - - if (!bow->can_reserve_extra_mases) - return; - - list_for_each_entry(rsv, &rc->reservations, rc_node) { - if (rsv->state == UWB_RSV_STATE_O_ESTABLISHED || - rsv->state == UWB_RSV_STATE_O_TO_BE_MOVED) { - uwb_drp_available(rc, &mas); - bitmap_or(mas.bm, mas.bm, rsv->mas.bm, UWB_NUM_MAS); - uwb_rsv_try_move(rsv, &mas); - } - } - -} - -/** - * uwb_rsv_terminate - terminate an established reservation - * @rsv: the reservation to terminate - * - * A reservation is terminated by removing the DRP IE from the beacon, - * the other end will consider the reservation to be terminated when - * it does not see the DRP IE for at least mMaxLostBeacons. - * - * If applicable, the reference to the target uwb_dev will be released. - */ -void uwb_rsv_terminate(struct uwb_rsv *rsv) -{ - struct uwb_rc *rc = rsv->rc; - - mutex_lock(&rc->rsvs_mutex); - - if (rsv->state != UWB_RSV_STATE_NONE) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); - - mutex_unlock(&rc->rsvs_mutex); -} -EXPORT_SYMBOL_GPL(uwb_rsv_terminate); - -/** - * uwb_rsv_accept - accept a new reservation from a peer - * @rsv: the reservation - * @cb: call back for reservation changes - * @pal_priv: data to be passed in the above call back - * - * Reservation requests from peers are denied unless a PAL accepts it - * by calling this function. - * - * The PAL call uwb_rsv_destroy() for all accepted reservations before - * calling uwb_pal_unregister(). - */ -void uwb_rsv_accept(struct uwb_rsv *rsv, uwb_rsv_cb_f cb, void *pal_priv) -{ - uwb_rsv_get(rsv); - - rsv->callback = cb; - rsv->pal_priv = pal_priv; - rsv->state = UWB_RSV_STATE_T_ACCEPTED; -} -EXPORT_SYMBOL_GPL(uwb_rsv_accept); - -/* - * Is a received DRP IE for this reservation? - */ -static bool uwb_rsv_match(struct uwb_rsv *rsv, struct uwb_dev *src, - struct uwb_ie_drp *drp_ie) -{ - struct uwb_dev_addr *rsv_src; - int stream; - - stream = uwb_ie_drp_stream_index(drp_ie); - - if (rsv->stream != stream) - return false; - - switch (rsv->target.type) { - case UWB_RSV_TARGET_DEVADDR: - return rsv->stream == stream; - case UWB_RSV_TARGET_DEV: - if (uwb_ie_drp_owner(drp_ie)) - rsv_src = &rsv->owner->dev_addr; - else - rsv_src = &rsv->target.dev->dev_addr; - return uwb_dev_addr_cmp(&src->dev_addr, rsv_src) == 0; - } - return false; -} - -static struct uwb_rsv *uwb_rsv_new_target(struct uwb_rc *rc, - struct uwb_dev *src, - struct uwb_ie_drp *drp_ie) -{ - struct uwb_rsv *rsv; - struct uwb_pal *pal; - enum uwb_rsv_state state; - - rsv = uwb_rsv_alloc(rc); - if (!rsv) - return NULL; - - rsv->rc = rc; - rsv->owner = src; - uwb_dev_get(rsv->owner); - rsv->target.type = UWB_RSV_TARGET_DEV; - rsv->target.dev = &rc->uwb_dev; - uwb_dev_get(&rc->uwb_dev); - rsv->type = uwb_ie_drp_type(drp_ie); - rsv->stream = uwb_ie_drp_stream_index(drp_ie); - uwb_drp_ie_to_bm(&rsv->mas, drp_ie); - - /* - * See if any PALs are interested in this reservation. If not, - * deny the request. - */ - rsv->state = UWB_RSV_STATE_T_DENIED; - mutex_lock(&rc->uwb_dev.mutex); - list_for_each_entry(pal, &rc->pals, node) { - if (pal->new_rsv) - pal->new_rsv(pal, rsv); - if (rsv->state == UWB_RSV_STATE_T_ACCEPTED) - break; - } - mutex_unlock(&rc->uwb_dev.mutex); - - list_add_tail(&rsv->rc_node, &rc->reservations); - state = rsv->state; - rsv->state = UWB_RSV_STATE_NONE; - - /* FIXME: do something sensible here */ - if (state == UWB_RSV_STATE_T_ACCEPTED - && uwb_drp_avail_reserve_pending(rc, &rsv->mas) == -EBUSY) { - /* FIXME: do something sensible here */ - } else { - uwb_rsv_set_state(rsv, state); - } - - return rsv; -} - -/** - * uwb_rsv_get_usable_mas - get the bitmap of the usable MAS of a reservations - * @rsv: the reservation. - * @mas: returns the available MAS. - * - * The usable MAS of a reservation may be less than the negotiated MAS - * if alien BPs are present. - */ -void uwb_rsv_get_usable_mas(struct uwb_rsv *rsv, struct uwb_mas_bm *mas) -{ - bitmap_zero(mas->bm, UWB_NUM_MAS); - bitmap_andnot(mas->bm, rsv->mas.bm, rsv->rc->cnflt_alien_bitmap.bm, UWB_NUM_MAS); -} -EXPORT_SYMBOL_GPL(uwb_rsv_get_usable_mas); - -/** - * uwb_rsv_find - find a reservation for a received DRP IE. - * @rc: the radio controller - * @src: source of the DRP IE - * @drp_ie: the DRP IE - * - * If the reservation cannot be found and the DRP IE is from a peer - * attempting to establish a new reservation, create a new reservation - * and add it to the list. - */ -struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src, - struct uwb_ie_drp *drp_ie) -{ - struct uwb_rsv *rsv; - - list_for_each_entry(rsv, &rc->reservations, rc_node) { - if (uwb_rsv_match(rsv, src, drp_ie)) - return rsv; - } - - if (uwb_ie_drp_owner(drp_ie)) - return uwb_rsv_new_target(rc, src, drp_ie); - - return NULL; -} - -/* - * Go through all the reservations and check for timeouts and (if - * necessary) update their DRP IEs. - * - * FIXME: look at building the SET_DRP_IE command here rather than - * having to rescan the list in uwb_rc_send_all_drp_ie(). - */ -static bool uwb_rsv_update_all(struct uwb_rc *rc) -{ - struct uwb_rsv *rsv, *t; - bool ie_updated = false; - - list_for_each_entry_safe(rsv, t, &rc->reservations, rc_node) { - if (!rsv->ie_valid) { - uwb_drp_ie_update(rsv); - ie_updated = true; - } - } - - return ie_updated; -} - -void uwb_rsv_queue_update(struct uwb_rc *rc) -{ - unsigned long delay_us = UWB_MAS_LENGTH_US * UWB_MAS_PER_ZONE; - - queue_delayed_work(rc->rsv_workq, &rc->rsv_update_work, usecs_to_jiffies(delay_us)); -} - -/** - * uwb_rsv_sched_update - schedule an update of the DRP IEs - * @rc: the radio controller. - * - * To improve performance and ensure correctness with [ECMA-368] the - * number of SET-DRP-IE commands that are done are limited. - * - * DRP IEs update come from two sources: DRP events from the hardware - * which all occur at the beginning of the superframe ('syncronous' - * events) and reservation establishment/termination requests from - * PALs or timers ('asynchronous' events). - * - * A delayed work ensures that all the synchronous events result in - * one SET-DRP-IE command. - * - * Additional logic (the set_drp_ie_pending and rsv_updated_postponed - * flags) will prevent an asynchrous event starting a SET-DRP-IE - * command if one is currently awaiting a response. - * - * FIXME: this does leave a window where an asynchrous event can delay - * the SET-DRP-IE for a synchronous event by one superframe. - */ -void uwb_rsv_sched_update(struct uwb_rc *rc) -{ - spin_lock_irq(&rc->rsvs_lock); - if (!delayed_work_pending(&rc->rsv_update_work)) { - if (rc->set_drp_ie_pending > 0) { - rc->set_drp_ie_pending++; - goto unlock; - } - uwb_rsv_queue_update(rc); - } -unlock: - spin_unlock_irq(&rc->rsvs_lock); -} - -/* - * Update DRP IEs and, if necessary, the DRP Availability IE and send - * the updated IEs to the radio controller. - */ -static void uwb_rsv_update_work(struct work_struct *work) -{ - struct uwb_rc *rc = container_of(work, struct uwb_rc, - rsv_update_work.work); - bool ie_updated; - - mutex_lock(&rc->rsvs_mutex); - - ie_updated = uwb_rsv_update_all(rc); - - if (!rc->drp_avail.ie_valid) { - uwb_drp_avail_ie_update(rc); - ie_updated = true; - } - - if (ie_updated && (rc->set_drp_ie_pending == 0)) - uwb_rc_send_all_drp_ie(rc); - - mutex_unlock(&rc->rsvs_mutex); -} - -static void uwb_rsv_alien_bp_work(struct work_struct *work) -{ - struct uwb_rc *rc = container_of(work, struct uwb_rc, - rsv_alien_bp_work.work); - struct uwb_rsv *rsv; - - mutex_lock(&rc->rsvs_mutex); - - list_for_each_entry(rsv, &rc->reservations, rc_node) { - if (rsv->type != UWB_DRP_TYPE_ALIEN_BP) { - uwb_rsv_callback(rsv); - } - } - - mutex_unlock(&rc->rsvs_mutex); -} - -static void uwb_rsv_timer(struct timer_list *t) -{ - struct uwb_rsv *rsv = from_timer(rsv, t, timer); - - queue_work(rsv->rc->rsv_workq, &rsv->handle_timeout_work); -} - -/** - * uwb_rsv_remove_all - remove all reservations - * @rc: the radio controller - * - * A DRP IE update is not done. - */ -void uwb_rsv_remove_all(struct uwb_rc *rc) -{ - struct uwb_rsv *rsv, *t; - - mutex_lock(&rc->rsvs_mutex); - list_for_each_entry_safe(rsv, t, &rc->reservations, rc_node) { - if (rsv->state != UWB_RSV_STATE_NONE) - uwb_rsv_set_state(rsv, UWB_RSV_STATE_NONE); - del_timer_sync(&rsv->timer); - } - /* Cancel any postponed update. */ - rc->set_drp_ie_pending = 0; - mutex_unlock(&rc->rsvs_mutex); - - cancel_delayed_work_sync(&rc->rsv_update_work); - flush_workqueue(rc->rsv_workq); - - mutex_lock(&rc->rsvs_mutex); - list_for_each_entry_safe(rsv, t, &rc->reservations, rc_node) { - uwb_rsv_remove(rsv); - } - mutex_unlock(&rc->rsvs_mutex); -} - -void uwb_rsv_init(struct uwb_rc *rc) -{ - INIT_LIST_HEAD(&rc->reservations); - INIT_LIST_HEAD(&rc->cnflt_alien_list); - mutex_init(&rc->rsvs_mutex); - spin_lock_init(&rc->rsvs_lock); - INIT_DELAYED_WORK(&rc->rsv_update_work, uwb_rsv_update_work); - INIT_DELAYED_WORK(&rc->rsv_alien_bp_work, uwb_rsv_alien_bp_work); - rc->bow.can_reserve_extra_mases = true; - rc->bow.total_expired = 0; - rc->bow.window = UWB_DRP_BACKOFF_WIN_MIN >> 1; - timer_setup(&rc->bow.timer, uwb_rsv_backoff_win_timer, 0); - - bitmap_complement(rc->uwb_dev.streams, rc->uwb_dev.streams, UWB_NUM_STREAMS); -} - -int uwb_rsv_setup(struct uwb_rc *rc) -{ - char name[16]; - - snprintf(name, sizeof(name), "%s_rsvd", dev_name(&rc->uwb_dev.dev)); - rc->rsv_workq = create_singlethread_workqueue(name); - if (rc->rsv_workq == NULL) - return -ENOMEM; - - return 0; -} - -void uwb_rsv_cleanup(struct uwb_rc *rc) -{ - uwb_rsv_remove_all(rc); - destroy_workqueue(rc->rsv_workq); -} diff --git a/drivers/staging/uwb/scan.c b/drivers/staging/uwb/scan.c deleted file mode 100644 index ffc3f452302d..000000000000 --- a/drivers/staging/uwb/scan.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Scanning management - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * FIXME: there are issues here on how BEACON and SCAN on USB RCI deal - * with each other. Currently seems that START_BEACON while - * SCAN_ONLY will cancel the scan, so we need to update the - * state here. Clarification request sent by email on - * 10/05/2005. - * 10/28/2005 No clear answer heard--maybe we'll hack the API - * so that when we start beaconing, if the HC is - * scanning in a mode not compatible with beaconing - * we just fail. - */ - -#include <linux/device.h> -#include <linux/err.h> -#include <linux/slab.h> -#include <linux/stat.h> -#include "uwb-internal.h" - - -/** - * Start/stop scanning in a radio controller - * - * @rc: UWB Radio Controller - * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12] - * @type: Type of scanning to do. - * @bpst_offset: value at which to start scanning (if type == - * UWB_SCAN_ONLY_STARTTIME) - * @returns: 0 if ok, < 0 errno code on error - * - * We put the command on kmalloc'ed memory as some arches cannot do - * USB from the stack. The reply event is copied from an stage buffer, - * so it can be in the stack. See WUSB1.0[8.6.2.4] for more details. - */ -int uwb_rc_scan(struct uwb_rc *rc, - unsigned channel, enum uwb_scan_type type, - unsigned bpst_offset) -{ - int result; - struct uwb_rc_cmd_scan *cmd; - struct uwb_rc_evt_confirm reply; - - result = -ENOMEM; - cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); - if (cmd == NULL) - goto error_kzalloc; - mutex_lock(&rc->uwb_dev.mutex); - cmd->rccb.bCommandType = UWB_RC_CET_GENERAL; - cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SCAN); - cmd->bChannelNumber = channel; - cmd->bScanState = type; - cmd->wStartTime = cpu_to_le16(bpst_offset); - reply.rceb.bEventType = UWB_RC_CET_GENERAL; - reply.rceb.wEvent = UWB_RC_CMD_SCAN; - result = uwb_rc_cmd(rc, "SCAN", &cmd->rccb, sizeof(*cmd), - &reply.rceb, sizeof(reply)); - if (result < 0) - goto error_cmd; - if (reply.bResultCode != UWB_RC_RES_SUCCESS) { - dev_err(&rc->uwb_dev.dev, - "SCAN: command execution failed: %s (%d)\n", - uwb_rc_strerror(reply.bResultCode), reply.bResultCode); - result = -EIO; - goto error_cmd; - } - rc->scanning = channel; - rc->scan_type = type; -error_cmd: - mutex_unlock(&rc->uwb_dev.mutex); - kfree(cmd); -error_kzalloc: - return result; -} - -/* - * Print scanning state - */ -static ssize_t uwb_rc_scan_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - ssize_t result; - - mutex_lock(&rc->uwb_dev.mutex); - result = sprintf(buf, "%d %d\n", rc->scanning, rc->scan_type); - mutex_unlock(&rc->uwb_dev.mutex); - return result; -} - -/* - * - */ -static ssize_t uwb_rc_scan_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct uwb_dev *uwb_dev = to_uwb_dev(dev); - struct uwb_rc *rc = uwb_dev->rc; - unsigned channel; - unsigned type; - unsigned bpst_offset = 0; - ssize_t result = -EINVAL; - - result = sscanf(buf, "%u %u %u\n", &channel, &type, &bpst_offset); - if (result >= 2 && type < UWB_SCAN_TOP) - result = uwb_rc_scan(rc, channel, type, bpst_offset); - - return result < 0 ? result : size; -} - -/** Radio Control sysfs interface (declaration) */ -DEVICE_ATTR(scan, S_IRUGO | S_IWUSR, uwb_rc_scan_show, uwb_rc_scan_store); diff --git a/drivers/staging/uwb/umc-bus.c b/drivers/staging/uwb/umc-bus.c deleted file mode 100644 index 8b931f66a720..000000000000 --- a/drivers/staging/uwb/umc-bus.c +++ /dev/null @@ -1,211 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Bus for UWB Multi-interface Controller capabilities. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/sysfs.h> -#include <linux/workqueue.h> -#include <linux/module.h> -#include <linux/pci.h> -#include "include/umc.h" - -static int umc_bus_pre_reset_helper(struct device *dev, void *data) -{ - int ret = 0; - - if (dev->driver) { - struct umc_dev *umc = to_umc_dev(dev); - struct umc_driver *umc_drv = to_umc_driver(dev->driver); - - if (umc_drv->pre_reset) - ret = umc_drv->pre_reset(umc); - else - device_release_driver(dev); - } - return ret; -} - -static int umc_bus_post_reset_helper(struct device *dev, void *data) -{ - int ret = 0; - - if (dev->driver) { - struct umc_dev *umc = to_umc_dev(dev); - struct umc_driver *umc_drv = to_umc_driver(dev->driver); - - if (umc_drv->post_reset) - ret = umc_drv->post_reset(umc); - } else - ret = device_attach(dev); - - return ret; -} - -/** - * umc_controller_reset - reset the whole UMC controller - * @umc: the UMC device for the radio controller. - * - * Drivers or all capabilities of the controller will have their - * pre_reset methods called or be unbound from their device. Then all - * post_reset methods will be called or the drivers will be rebound. - * - * Radio controllers must provide pre_reset and post_reset methods and - * reset the hardware in their start method. - * - * If this is called while a probe() or remove() is in progress it - * will return -EAGAIN and not perform the reset. - */ -int umc_controller_reset(struct umc_dev *umc) -{ - struct device *parent = umc->dev.parent; - int ret = 0; - - if (!device_trylock(parent)) - return -EAGAIN; - ret = device_for_each_child(parent, parent, umc_bus_pre_reset_helper); - if (ret >= 0) - ret = device_for_each_child(parent, parent, umc_bus_post_reset_helper); - device_unlock(parent); - - return ret; -} -EXPORT_SYMBOL_GPL(umc_controller_reset); - -/** - * umc_match_pci_id - match a UMC driver to a UMC device's parent PCI device. - * @umc_drv: umc driver with match_data pointing to a zero-terminated - * table of pci_device_id's. - * @umc: umc device whose parent is to be matched. - */ -int umc_match_pci_id(struct umc_driver *umc_drv, struct umc_dev *umc) -{ - const struct pci_device_id *id_table = umc_drv->match_data; - struct pci_dev *pci; - - if (!dev_is_pci(umc->dev.parent)) - return 0; - - pci = to_pci_dev(umc->dev.parent); - return pci_match_id(id_table, pci) != NULL; -} -EXPORT_SYMBOL_GPL(umc_match_pci_id); - -static int umc_bus_rescan_helper(struct device *dev, void *data) -{ - int ret = 0; - - if (!dev->driver) - ret = device_attach(dev); - - return ret; -} - -static void umc_bus_rescan(struct device *parent) -{ - int err; - - /* - * We can't use bus_rescan_devices() here as it deadlocks when - * it tries to retake the dev->parent semaphore. - */ - err = device_for_each_child(parent, NULL, umc_bus_rescan_helper); - if (err < 0) - printk(KERN_WARNING "%s: rescan of bus failed: %d\n", - KBUILD_MODNAME, err); -} - -static int umc_bus_match(struct device *dev, struct device_driver *drv) -{ - struct umc_dev *umc = to_umc_dev(dev); - struct umc_driver *umc_driver = to_umc_driver(drv); - - if (umc->cap_id == umc_driver->cap_id) { - if (umc_driver->match) - return umc_driver->match(umc_driver, umc); - else - return 1; - } - return 0; -} - -static int umc_device_probe(struct device *dev) -{ - struct umc_dev *umc; - struct umc_driver *umc_driver; - int err; - - umc_driver = to_umc_driver(dev->driver); - umc = to_umc_dev(dev); - - get_device(dev); - err = umc_driver->probe(umc); - if (err) - put_device(dev); - else - umc_bus_rescan(dev->parent); - - return err; -} - -static int umc_device_remove(struct device *dev) -{ - struct umc_dev *umc; - struct umc_driver *umc_driver; - - umc_driver = to_umc_driver(dev->driver); - umc = to_umc_dev(dev); - - umc_driver->remove(umc); - put_device(dev); - return 0; -} - -static ssize_t capability_id_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct umc_dev *umc = to_umc_dev(dev); - - return sprintf(buf, "0x%02x\n", umc->cap_id); -} -static DEVICE_ATTR_RO(capability_id); - -static ssize_t version_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct umc_dev *umc = to_umc_dev(dev); - - return sprintf(buf, "0x%04x\n", umc->version); -} -static DEVICE_ATTR_RO(version); - -static struct attribute *umc_dev_attrs[] = { - &dev_attr_capability_id.attr, - &dev_attr_version.attr, - NULL, -}; -ATTRIBUTE_GROUPS(umc_dev); - -struct bus_type umc_bus_type = { - .name = "umc", - .match = umc_bus_match, - .probe = umc_device_probe, - .remove = umc_device_remove, - .dev_groups = umc_dev_groups, -}; -EXPORT_SYMBOL_GPL(umc_bus_type); - -static int __init umc_bus_init(void) -{ - return bus_register(&umc_bus_type); -} -module_init(umc_bus_init); - -static void __exit umc_bus_exit(void) -{ - bus_unregister(&umc_bus_type); -} -module_exit(umc_bus_exit); - -MODULE_DESCRIPTION("UWB Multi-interface Controller capability bus"); -MODULE_AUTHOR("Cambridge Silicon Radio Ltd."); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/uwb/umc-dev.c b/drivers/staging/uwb/umc-dev.c deleted file mode 100644 index 0c71caae00be..000000000000 --- a/drivers/staging/uwb/umc-dev.c +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB Multi-interface Controller device management. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/export.h> -#include <linux/slab.h> -#include "include/umc.h" - -static void umc_device_release(struct device *dev) -{ - struct umc_dev *umc = to_umc_dev(dev); - - kfree(umc); -} - -/** - * umc_device_create - allocate a child UMC device - * @parent: parent of the new UMC device. - * @n: index of the new device. - * - * The new UMC device will have a bus ID of the parent with '-n' - * appended. - */ -struct umc_dev *umc_device_create(struct device *parent, int n) -{ - struct umc_dev *umc; - - umc = kzalloc(sizeof(struct umc_dev), GFP_KERNEL); - if (umc) { - dev_set_name(&umc->dev, "%s-%d", dev_name(parent), n); - umc->dev.parent = parent; - umc->dev.bus = &umc_bus_type; - umc->dev.release = umc_device_release; - - umc->dev.dma_mask = parent->dma_mask; - } - return umc; -} -EXPORT_SYMBOL_GPL(umc_device_create); - -/** - * umc_device_register - register a UMC device - * @umc: pointer to the UMC device - * - * The memory resource for the UMC device is acquired and the device - * registered with the system. - */ -int umc_device_register(struct umc_dev *umc) -{ - int err; - - err = request_resource(umc->resource.parent, &umc->resource); - if (err < 0) { - dev_err(&umc->dev, "can't allocate resource range %pR: %d\n", - &umc->resource, err); - goto error_request_resource; - } - - err = device_register(&umc->dev); - if (err < 0) - goto error_device_register; - return 0; - -error_device_register: - put_device(&umc->dev); - release_resource(&umc->resource); -error_request_resource: - return err; -} -EXPORT_SYMBOL_GPL(umc_device_register); - -/** - * umc_device_unregister - unregister a UMC device - * @umc: pointer to the UMC device - * - * First we unregister the device, make sure the driver can do it's - * resource release thing and then we try to release any left over - * resources. We take a ref to the device, to make sure it doesn't - * disappear under our feet. - */ -void umc_device_unregister(struct umc_dev *umc) -{ - struct device *dev; - if (!umc) - return; - dev = get_device(&umc->dev); - device_unregister(&umc->dev); - release_resource(&umc->resource); - put_device(dev); -} -EXPORT_SYMBOL_GPL(umc_device_unregister); diff --git a/drivers/staging/uwb/umc-drv.c b/drivers/staging/uwb/umc-drv.c deleted file mode 100644 index ed3bd220e8c2..000000000000 --- a/drivers/staging/uwb/umc-drv.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * UWB Multi-interface Controller driver management. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/export.h> -#include "include/umc.h" - -int __umc_driver_register(struct umc_driver *umc_drv, struct module *module, - const char *mod_name) -{ - umc_drv->driver.name = umc_drv->name; - umc_drv->driver.owner = module; - umc_drv->driver.mod_name = mod_name; - umc_drv->driver.bus = &umc_bus_type; - - return driver_register(&umc_drv->driver); -} -EXPORT_SYMBOL_GPL(__umc_driver_register); - -/** - * umc_driver_register - unregister a UMC capabiltity driver. - * @umc_drv: pointer to the driver. - */ -void umc_driver_unregister(struct umc_driver *umc_drv) -{ - driver_unregister(&umc_drv->driver); -} -EXPORT_SYMBOL_GPL(umc_driver_unregister); diff --git a/drivers/staging/uwb/uwb-debug.c b/drivers/staging/uwb/uwb-debug.c deleted file mode 100644 index dd14df219ef8..000000000000 --- a/drivers/staging/uwb/uwb-debug.c +++ /dev/null @@ -1,354 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Debug support - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - * - * FIXME: doc - */ - -#include <linux/spinlock.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/notifier.h> -#include <linux/device.h> -#include <linux/debugfs.h> -#include <linux/uaccess.h> -#include <linux/seq_file.h> - -#include "include/debug-cmd.h" -#include "uwb-internal.h" - -/* - * Debug interface - * - * Per radio controller debugfs files (in uwb/uwbN/): - * - * command: Flexible command interface (see <linux/uwb/debug-cmd.h>). - * - * reservations: information on reservations. - * - * accept: Set to true (Y or 1) to accept reservation requests from - * peers. - * - * drp_avail: DRP availability information. - */ - -struct uwb_dbg { - struct uwb_pal pal; - - bool accept; - struct list_head rsvs; - - struct dentry *root_d; - struct dentry *command_f; - struct dentry *reservations_f; - struct dentry *accept_f; - struct dentry *drp_avail_f; - spinlock_t list_lock; -}; - -static struct dentry *root_dir; - -static void uwb_dbg_rsv_cb(struct uwb_rsv *rsv) -{ - struct uwb_dbg *dbg = rsv->pal_priv; - - uwb_rsv_dump("debug", rsv); - - if (rsv->state == UWB_RSV_STATE_NONE) { - spin_lock(&dbg->list_lock); - list_del(&rsv->pal_node); - spin_unlock(&dbg->list_lock); - uwb_rsv_destroy(rsv); - } -} - -static int cmd_rsv_establish(struct uwb_rc *rc, - struct uwb_dbg_cmd_rsv_establish *cmd) -{ - struct uwb_mac_addr macaddr; - struct uwb_rsv *rsv; - struct uwb_dev *target; - int ret; - - memcpy(&macaddr, cmd->target, sizeof(macaddr)); - target = uwb_dev_get_by_macaddr(rc, &macaddr); - if (target == NULL) - return -ENODEV; - - rsv = uwb_rsv_create(rc, uwb_dbg_rsv_cb, rc->dbg); - if (rsv == NULL) { - uwb_dev_put(target); - return -ENOMEM; - } - - rsv->target.type = UWB_RSV_TARGET_DEV; - rsv->target.dev = target; - rsv->type = cmd->type; - rsv->max_mas = cmd->max_mas; - rsv->min_mas = cmd->min_mas; - rsv->max_interval = cmd->max_interval; - - ret = uwb_rsv_establish(rsv); - if (ret) - uwb_rsv_destroy(rsv); - else { - spin_lock(&(rc->dbg)->list_lock); - list_add_tail(&rsv->pal_node, &rc->dbg->rsvs); - spin_unlock(&(rc->dbg)->list_lock); - } - return ret; -} - -static int cmd_rsv_terminate(struct uwb_rc *rc, - struct uwb_dbg_cmd_rsv_terminate *cmd) -{ - struct uwb_rsv *rsv, *found = NULL; - int i = 0; - - spin_lock(&(rc->dbg)->list_lock); - - list_for_each_entry(rsv, &rc->dbg->rsvs, pal_node) { - if (i == cmd->index) { - found = rsv; - uwb_rsv_get(found); - break; - } - i++; - } - - spin_unlock(&(rc->dbg)->list_lock); - - if (!found) - return -EINVAL; - - uwb_rsv_terminate(found); - uwb_rsv_put(found); - - return 0; -} - -static int cmd_ie_add(struct uwb_rc *rc, struct uwb_dbg_cmd_ie *ie_to_add) -{ - return uwb_rc_ie_add(rc, - (const struct uwb_ie_hdr *) ie_to_add->data, - ie_to_add->len); -} - -static int cmd_ie_rm(struct uwb_rc *rc, struct uwb_dbg_cmd_ie *ie_to_rm) -{ - return uwb_rc_ie_rm(rc, ie_to_rm->data[0]); -} - -static ssize_t command_write(struct file *file, const char __user *buf, - size_t len, loff_t *off) -{ - struct uwb_rc *rc = file->private_data; - struct uwb_dbg_cmd cmd; - int ret = 0; - - if (len != sizeof(struct uwb_dbg_cmd)) - return -EINVAL; - - if (copy_from_user(&cmd, buf, len) != 0) - return -EFAULT; - - switch (cmd.type) { - case UWB_DBG_CMD_RSV_ESTABLISH: - ret = cmd_rsv_establish(rc, &cmd.rsv_establish); - break; - case UWB_DBG_CMD_RSV_TERMINATE: - ret = cmd_rsv_terminate(rc, &cmd.rsv_terminate); - break; - case UWB_DBG_CMD_IE_ADD: - ret = cmd_ie_add(rc, &cmd.ie_add); - break; - case UWB_DBG_CMD_IE_RM: - ret = cmd_ie_rm(rc, &cmd.ie_rm); - break; - case UWB_DBG_CMD_RADIO_START: - ret = uwb_radio_start(&rc->dbg->pal); - break; - case UWB_DBG_CMD_RADIO_STOP: - uwb_radio_stop(&rc->dbg->pal); - break; - default: - return -EINVAL; - } - - return ret < 0 ? ret : len; -} - -static const struct file_operations command_fops = { - .open = simple_open, - .write = command_write, - .read = NULL, - .llseek = no_llseek, - .owner = THIS_MODULE, -}; - -static int reservations_show(struct seq_file *s, void *p) -{ - struct uwb_rc *rc = s->private; - struct uwb_rsv *rsv; - - mutex_lock(&rc->rsvs_mutex); - - list_for_each_entry(rsv, &rc->reservations, rc_node) { - struct uwb_dev_addr devaddr; - char owner[UWB_ADDR_STRSIZE], target[UWB_ADDR_STRSIZE]; - bool is_owner; - - uwb_dev_addr_print(owner, sizeof(owner), &rsv->owner->dev_addr); - if (rsv->target.type == UWB_RSV_TARGET_DEV) { - devaddr = rsv->target.dev->dev_addr; - is_owner = &rc->uwb_dev == rsv->owner; - } else { - devaddr = rsv->target.devaddr; - is_owner = true; - } - uwb_dev_addr_print(target, sizeof(target), &devaddr); - - seq_printf(s, "%c %s -> %s: %s\n", - is_owner ? 'O' : 'T', - owner, target, uwb_rsv_state_str(rsv->state)); - seq_printf(s, " stream: %d type: %s\n", - rsv->stream, uwb_rsv_type_str(rsv->type)); - seq_printf(s, " %*pb\n", UWB_NUM_MAS, rsv->mas.bm); - } - - mutex_unlock(&rc->rsvs_mutex); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(reservations); - -static int drp_avail_show(struct seq_file *s, void *p) -{ - struct uwb_rc *rc = s->private; - - seq_printf(s, "global: %*pb\n", UWB_NUM_MAS, rc->drp_avail.global); - seq_printf(s, "local: %*pb\n", UWB_NUM_MAS, rc->drp_avail.local); - seq_printf(s, "pending: %*pb\n", UWB_NUM_MAS, rc->drp_avail.pending); - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(drp_avail); - -static void uwb_dbg_channel_changed(struct uwb_pal *pal, int channel) -{ - struct device *dev = &pal->rc->uwb_dev.dev; - - if (channel > 0) - dev_info(dev, "debug: channel %d started\n", channel); - else - dev_info(dev, "debug: channel stopped\n"); -} - -static void uwb_dbg_new_rsv(struct uwb_pal *pal, struct uwb_rsv *rsv) -{ - struct uwb_dbg *dbg = container_of(pal, struct uwb_dbg, pal); - - if (dbg->accept) { - spin_lock(&dbg->list_lock); - list_add_tail(&rsv->pal_node, &dbg->rsvs); - spin_unlock(&dbg->list_lock); - uwb_rsv_accept(rsv, uwb_dbg_rsv_cb, dbg); - } -} - -/** - * uwb_dbg_add_rc - add a debug interface for a radio controller - * @rc: the radio controller - */ -void uwb_dbg_add_rc(struct uwb_rc *rc) -{ - rc->dbg = kzalloc(sizeof(struct uwb_dbg), GFP_KERNEL); - if (rc->dbg == NULL) - return; - - INIT_LIST_HEAD(&rc->dbg->rsvs); - spin_lock_init(&(rc->dbg)->list_lock); - - uwb_pal_init(&rc->dbg->pal); - rc->dbg->pal.rc = rc; - rc->dbg->pal.channel_changed = uwb_dbg_channel_changed; - rc->dbg->pal.new_rsv = uwb_dbg_new_rsv; - uwb_pal_register(&rc->dbg->pal); - - if (root_dir) { - rc->dbg->root_d = debugfs_create_dir(dev_name(&rc->uwb_dev.dev), - root_dir); - rc->dbg->command_f = debugfs_create_file("command", 0200, - rc->dbg->root_d, rc, - &command_fops); - rc->dbg->reservations_f = debugfs_create_file("reservations", 0444, - rc->dbg->root_d, rc, - &reservations_fops); - rc->dbg->accept_f = debugfs_create_bool("accept", 0644, - rc->dbg->root_d, - &rc->dbg->accept); - rc->dbg->drp_avail_f = debugfs_create_file("drp_avail", 0444, - rc->dbg->root_d, rc, - &drp_avail_fops); - } -} - -/** - * uwb_dbg_del_rc - remove a radio controller's debug interface - * @rc: the radio controller - */ -void uwb_dbg_del_rc(struct uwb_rc *rc) -{ - struct uwb_rsv *rsv, *t; - - if (rc->dbg == NULL) - return; - - list_for_each_entry_safe(rsv, t, &rc->dbg->rsvs, pal_node) { - uwb_rsv_terminate(rsv); - } - - uwb_pal_unregister(&rc->dbg->pal); - - if (root_dir) { - debugfs_remove(rc->dbg->drp_avail_f); - debugfs_remove(rc->dbg->accept_f); - debugfs_remove(rc->dbg->reservations_f); - debugfs_remove(rc->dbg->command_f); - debugfs_remove(rc->dbg->root_d); - } -} - -/** - * uwb_dbg_exit - initialize the debug interface sub-module - */ -void uwb_dbg_init(void) -{ - root_dir = debugfs_create_dir("uwb", NULL); -} - -/** - * uwb_dbg_exit - clean-up the debug interface sub-module - */ -void uwb_dbg_exit(void) -{ - debugfs_remove(root_dir); -} - -/** - * uwb_dbg_create_pal_dir - create a debugfs directory for a PAL - * @pal: The PAL. - */ -struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal) -{ - struct uwb_rc *rc = pal->rc; - - if (root_dir && rc->dbg && rc->dbg->root_d && pal->name) - return debugfs_create_dir(pal->name, rc->dbg->root_d); - return NULL; -} diff --git a/drivers/staging/uwb/uwb-internal.h b/drivers/staging/uwb/uwb-internal.h deleted file mode 100644 index 4c2fdac7f610..000000000000 --- a/drivers/staging/uwb/uwb-internal.h +++ /dev/null @@ -1,366 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Ultra Wide Band - * UWB internal API - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This contains most of the internal API for UWB. This is stuff used - * across the stack that of course, is of no interest to the rest. - * - * Some parts might end up going public (like uwb_rc_*())... - */ - -#ifndef __UWB_INTERNAL_H__ -#define __UWB_INTERNAL_H__ - -#include <linux/kernel.h> -#include <linux/device.h> -#include <linux/mutex.h> -#include "uwb.h" - -struct uwb_beca_e; - -/* General device API */ -extern void uwb_dev_init(struct uwb_dev *uwb_dev); -extern int __uwb_dev_offair(struct uwb_dev *, struct uwb_rc *); -extern int uwb_dev_add(struct uwb_dev *uwb_dev, struct device *parent_dev, - struct uwb_rc *parent_rc); -extern void uwb_dev_rm(struct uwb_dev *uwb_dev); -extern void uwbd_dev_onair(struct uwb_rc *, struct uwb_beca_e *); -extern void uwbd_dev_offair(struct uwb_beca_e *); -void uwb_notify(struct uwb_rc *rc, struct uwb_dev *uwb_dev, enum uwb_notifs event); - -/* General UWB Radio Controller Internal API */ -extern struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *); -static inline struct uwb_rc *__uwb_rc_get(struct uwb_rc *rc) -{ - uwb_dev_get(&rc->uwb_dev); - return rc; -} - -static inline void __uwb_rc_put(struct uwb_rc *rc) -{ - if (rc) - uwb_dev_put(&rc->uwb_dev); -} - -extern int uwb_rc_reset(struct uwb_rc *rc); -extern int uwb_rc_beacon(struct uwb_rc *rc, - int channel, unsigned bpst_offset); -extern int uwb_rc_scan(struct uwb_rc *rc, - unsigned channel, enum uwb_scan_type type, - unsigned bpst_offset); -extern int uwb_rc_send_all_drp_ie(struct uwb_rc *rc); - -void uwb_rc_ie_init(struct uwb_rc *); -int uwb_rc_ie_setup(struct uwb_rc *); -void uwb_rc_ie_release(struct uwb_rc *); -int uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len, - char *buf, size_t size); -int uwb_rc_set_ie(struct uwb_rc *, struct uwb_rc_cmd_set_ie *); - - -extern const char *uwb_rc_strerror(unsigned code); - -/* - * Time to wait for a response to an RC command. - * - * Some commands can take a long time to response. e.g., START_BEACON - * may scan for several superframes before joining an existing beacon - * group and this can take around 600 ms. - */ -#define UWB_RC_CMD_TIMEOUT_MS 1000 /* ms */ - -/* - * Notification/Event Handlers - */ - -struct uwb_rc_neh; - -extern int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - u8 expected_type, u16 expected_event, - uwb_rc_cmd_cb_f cb, void *arg); - - -void uwb_rc_neh_create(struct uwb_rc *rc); -void uwb_rc_neh_destroy(struct uwb_rc *rc); - -struct uwb_rc_neh *uwb_rc_neh_add(struct uwb_rc *rc, struct uwb_rccb *cmd, - u8 expected_type, u16 expected_event, - uwb_rc_cmd_cb_f cb, void *arg); -void uwb_rc_neh_rm(struct uwb_rc *rc, struct uwb_rc_neh *neh); -void uwb_rc_neh_arm(struct uwb_rc *rc, struct uwb_rc_neh *neh); -void uwb_rc_neh_put(struct uwb_rc_neh *neh); - -/* Event size tables */ -extern int uwb_est_create(void); -extern void uwb_est_destroy(void); - -/* - * UWB conflicting alien reservations - */ -struct uwb_cnflt_alien { - struct uwb_rc *rc; - struct list_head rc_node; - struct uwb_mas_bm mas; - struct timer_list timer; - struct work_struct cnflt_update_work; -}; - -enum uwb_uwb_rsv_alloc_result { - UWB_RSV_ALLOC_FOUND = 0, - UWB_RSV_ALLOC_NOT_FOUND, -}; - -enum uwb_rsv_mas_status { - UWB_RSV_MAS_NOT_AVAIL = 1, - UWB_RSV_MAS_SAFE, - UWB_RSV_MAS_UNSAFE, -}; - -struct uwb_rsv_col_set_info { - unsigned char start_col; - unsigned char interval; - unsigned char safe_mas_per_col; - unsigned char unsafe_mas_per_col; -}; - -struct uwb_rsv_col_info { - unsigned char max_avail_safe; - unsigned char max_avail_unsafe; - unsigned char highest_mas[UWB_MAS_PER_ZONE]; - struct uwb_rsv_col_set_info csi; -}; - -struct uwb_rsv_row_info { - unsigned char avail[UWB_MAS_PER_ZONE]; - unsigned char free_rows; - unsigned char used_rows; -}; - -/* - * UWB find allocation - */ -struct uwb_rsv_alloc_info { - unsigned char bm[UWB_MAS_PER_ZONE * UWB_NUM_ZONES]; - struct uwb_rsv_col_info ci[UWB_NUM_ZONES]; - struct uwb_rsv_row_info ri; - struct uwb_mas_bm *not_available; - struct uwb_mas_bm *result; - int min_mas; - int max_mas; - int max_interval; - int total_allocated_mases; - int safe_allocated_mases; - int unsafe_allocated_mases; - int interval; -}; - -int uwb_rsv_find_best_allocation(struct uwb_rsv *rsv, - struct uwb_mas_bm *available, - struct uwb_mas_bm *result); -void uwb_rsv_handle_drp_avail_change(struct uwb_rc *rc); -/* - * UWB Events & management daemon - */ - -/** - * enum uwb_event_type - types of UWB management daemon events - * - * The UWB management daemon (uwbd) can receive two types of events: - * UWB_EVT_TYPE_NOTIF - notification from the radio controller. - * UWB_EVT_TYPE_MSG - a simple message. - */ -enum uwb_event_type { - UWB_EVT_TYPE_NOTIF, - UWB_EVT_TYPE_MSG, -}; - -/** - * struct uwb_event_notif - an event for a radio controller notification - * @size: Size of the buffer (ie: Guaranteed to contain at least - * a full 'struct uwb_rceb') - * @rceb: Pointer to a kmalloced() event payload - */ -struct uwb_event_notif { - size_t size; - struct uwb_rceb *rceb; -}; - -/** - * enum uwb_event_message - an event for a message for asynchronous processing - * - * UWB_EVT_MSG_RESET - reset the radio controller and all PAL hardware. - */ -enum uwb_event_message { - UWB_EVT_MSG_RESET, -}; - -/** - * UWB Event - * @rc: Radio controller that emitted the event (referenced) - * @ts_jiffies: Timestamp, when was it received - * @type: This event's type. - */ -struct uwb_event { - struct list_head list_node; - struct uwb_rc *rc; - unsigned long ts_jiffies; - enum uwb_event_type type; - union { - struct uwb_event_notif notif; - enum uwb_event_message message; - }; -}; - -extern void uwbd_start(struct uwb_rc *rc); -extern void uwbd_stop(struct uwb_rc *rc); -extern struct uwb_event *uwb_event_alloc(size_t, gfp_t gfp_mask); -extern void uwbd_event_queue(struct uwb_event *); -void uwbd_flush(struct uwb_rc *rc); - -/* UWB event handlers */ -extern int uwbd_evt_handle_rc_ie_rcv(struct uwb_event *); -extern int uwbd_evt_handle_rc_beacon(struct uwb_event *); -extern int uwbd_evt_handle_rc_beacon_size(struct uwb_event *); -extern int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *); -extern int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *); -extern int uwbd_evt_handle_rc_drp(struct uwb_event *); -extern int uwbd_evt_handle_rc_drp_avail(struct uwb_event *); - -int uwbd_msg_handle_reset(struct uwb_event *evt); - - -/* - * Address management - */ -int uwb_rc_dev_addr_assign(struct uwb_rc *rc); -int uwbd_evt_handle_rc_dev_addr_conflict(struct uwb_event *evt); - -/* - * UWB Beacon Cache - * - * Each beacon we received is kept in a cache--when we receive that - * beacon consistently, that means there is a new device that we have - * to add to the system. - */ - -extern unsigned long beacon_timeout_ms; - -/** - * Beacon cache entry - * - * @jiffies_refresh: last time a beacon was received that refreshed - * this cache entry. - * @uwb_dev: device connected to this beacon. This pointer is not - * safe, you need to get it with uwb_dev_try_get() - * - * @hits: how many time we have seen this beacon since last time we - * cleared it - */ -struct uwb_beca_e { - struct mutex mutex; - struct kref refcnt; - struct list_head node; - struct uwb_mac_addr *mac_addr; - struct uwb_dev_addr dev_addr; - u8 hits; - unsigned long ts_jiffies; - struct uwb_dev *uwb_dev; - struct uwb_rc_evt_beacon *be; - struct stats lqe_stats, rssi_stats; /* radio statistics */ -}; -struct uwb_beacon_frame; -extern ssize_t uwb_bce_print_IEs(struct uwb_dev *, struct uwb_beca_e *, - char *, size_t); - -extern void uwb_bce_kfree(struct kref *_bce); -static inline void uwb_bce_get(struct uwb_beca_e *bce) -{ - kref_get(&bce->refcnt); -} -static inline void uwb_bce_put(struct uwb_beca_e *bce) -{ - kref_put(&bce->refcnt, uwb_bce_kfree); -} -extern void uwb_beca_purge(struct uwb_rc *rc); -extern void uwb_beca_release(struct uwb_rc *rc); - -struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc, - const struct uwb_dev_addr *devaddr); -struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc, - const struct uwb_mac_addr *macaddr); - -int uwb_radio_setup(struct uwb_rc *rc); -void uwb_radio_reset_state(struct uwb_rc *rc); -void uwb_radio_shutdown(struct uwb_rc *rc); -int uwb_radio_force_channel(struct uwb_rc *rc, int channel); - -/* -- UWB Sysfs representation */ -extern struct class uwb_rc_class; -extern struct bus_type uwb_bus_type; -extern struct device_attribute dev_attr_mac_address; -extern struct device_attribute dev_attr_beacon; -extern struct device_attribute dev_attr_scan; - -/* -- DRP Bandwidth allocator: bandwidth allocations, reservations, DRP */ -void uwb_rsv_init(struct uwb_rc *rc); -int uwb_rsv_setup(struct uwb_rc *rc); -void uwb_rsv_cleanup(struct uwb_rc *rc); -void uwb_rsv_remove_all(struct uwb_rc *rc); -void uwb_rsv_get(struct uwb_rsv *rsv); -void uwb_rsv_put(struct uwb_rsv *rsv); -bool uwb_rsv_has_two_drp_ies(struct uwb_rsv *rsv); -void uwb_rsv_dump(char *text, struct uwb_rsv *rsv); -int uwb_rsv_try_move(struct uwb_rsv *rsv, struct uwb_mas_bm *available); -void uwb_rsv_backoff_win_timer(struct timer_list *t); -void uwb_rsv_backoff_win_increment(struct uwb_rc *rc); -int uwb_rsv_status(struct uwb_rsv *rsv); -int uwb_rsv_companion_status(struct uwb_rsv *rsv); - -void uwb_rsv_set_state(struct uwb_rsv *rsv, enum uwb_rsv_state new_state); -void uwb_rsv_remove(struct uwb_rsv *rsv); -struct uwb_rsv *uwb_rsv_find(struct uwb_rc *rc, struct uwb_dev *src, - struct uwb_ie_drp *drp_ie); -void uwb_rsv_sched_update(struct uwb_rc *rc); -void uwb_rsv_queue_update(struct uwb_rc *rc); - -int uwb_drp_ie_update(struct uwb_rsv *rsv); -void uwb_drp_ie_to_bm(struct uwb_mas_bm *bm, const struct uwb_ie_drp *drp_ie); - -void uwb_drp_avail_init(struct uwb_rc *rc); -void uwb_drp_available(struct uwb_rc *rc, struct uwb_mas_bm *avail); -int uwb_drp_avail_reserve_pending(struct uwb_rc *rc, struct uwb_mas_bm *mas); -void uwb_drp_avail_reserve(struct uwb_rc *rc, struct uwb_mas_bm *mas); -void uwb_drp_avail_release(struct uwb_rc *rc, struct uwb_mas_bm *mas); -void uwb_drp_avail_ie_update(struct uwb_rc *rc); - -/* -- PAL support */ -void uwb_rc_pal_init(struct uwb_rc *rc); - -/* -- Misc */ - -extern ssize_t uwb_mac_frame_hdr_print(char *, size_t, - const struct uwb_mac_frame_hdr *); - -/* -- Debug interface */ -void uwb_dbg_init(void); -void uwb_dbg_exit(void); -void uwb_dbg_add_rc(struct uwb_rc *rc); -void uwb_dbg_del_rc(struct uwb_rc *rc); -struct dentry *uwb_dbg_create_pal_dir(struct uwb_pal *pal); - -static inline void uwb_dev_lock(struct uwb_dev *uwb_dev) -{ - device_lock(&uwb_dev->dev); -} - -static inline void uwb_dev_unlock(struct uwb_dev *uwb_dev) -{ - device_unlock(&uwb_dev->dev); -} - -#endif /* #ifndef __UWB_INTERNAL_H__ */ diff --git a/drivers/staging/uwb/uwb.h b/drivers/staging/uwb/uwb.h deleted file mode 100644 index 6a59706ba3a0..000000000000 --- a/drivers/staging/uwb/uwb.h +++ /dev/null @@ -1,817 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Ultra Wide Band - * UWB API - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: doc: overview of the API, different parts and pointers - */ - -#ifndef __LINUX__UWB_H__ -#define __LINUX__UWB_H__ - -#include <linux/limits.h> -#include <linux/device.h> -#include <linux/mutex.h> -#include <linux/timer.h> -#include <linux/wait.h> -#include <linux/workqueue.h> -#include <asm/page.h> -#include "include/spec.h" - -struct uwb_dev; -struct uwb_beca_e; -struct uwb_rc; -struct uwb_rsv; -struct uwb_dbg; - -/** - * struct uwb_dev - a UWB Device - * @rc: UWB Radio Controller that discovered the device (kind of its - * parent). - * @bce: a beacon cache entry for this device; or NULL if the device - * is a local radio controller. - * @mac_addr: the EUI-48 address of this device. - * @dev_addr: the current DevAddr used by this device. - * @beacon_slot: the slot number the beacon is using. - * @streams: bitmap of streams allocated to reservations targeted at - * this device. For an RC, this is the streams allocated for - * reservations targeted at DevAddrs. - * - * A UWB device may either by a neighbor or part of a local radio - * controller. - */ -struct uwb_dev { - struct mutex mutex; - struct list_head list_node; - struct device dev; - struct uwb_rc *rc; /* radio controller */ - struct uwb_beca_e *bce; /* Beacon Cache Entry */ - - struct uwb_mac_addr mac_addr; - struct uwb_dev_addr dev_addr; - int beacon_slot; - DECLARE_BITMAP(streams, UWB_NUM_STREAMS); - DECLARE_BITMAP(last_availability_bm, UWB_NUM_MAS); -}; -#define to_uwb_dev(d) container_of(d, struct uwb_dev, dev) - -/** - * UWB HWA/WHCI Radio Control {Command|Event} Block context IDs - * - * RC[CE]Bs have a 'context ID' field that matches the command with - * the event received to confirm it. - * - * Maximum number of context IDs - */ -enum { UWB_RC_CTX_MAX = 256 }; - - -/** Notification chain head for UWB generated events to listeners */ -struct uwb_notifs_chain { - struct list_head list; - struct mutex mutex; -}; - -/* Beacon cache list */ -struct uwb_beca { - struct list_head list; - size_t entries; - struct mutex mutex; -}; - -/* Event handling thread. */ -struct uwbd { - int pid; - struct task_struct *task; - wait_queue_head_t wq; - struct list_head event_list; - spinlock_t event_list_lock; -}; - -/** - * struct uwb_mas_bm - a bitmap of all MAS in a superframe - * @bm: a bitmap of length #UWB_NUM_MAS - */ -struct uwb_mas_bm { - DECLARE_BITMAP(bm, UWB_NUM_MAS); - DECLARE_BITMAP(unsafe_bm, UWB_NUM_MAS); - int safe; - int unsafe; -}; - -/** - * uwb_rsv_state - UWB Reservation state. - * - * NONE - reservation is not active (no DRP IE being transmitted). - * - * Owner reservation states: - * - * INITIATED - owner has sent an initial DRP request. - * PENDING - target responded with pending Reason Code. - * MODIFIED - reservation manager is modifying an established - * reservation with a different MAS allocation. - * ESTABLISHED - the reservation has been successfully negotiated. - * - * Target reservation states: - * - * DENIED - request is denied. - * ACCEPTED - request is accepted. - * PENDING - PAL has yet to make a decision to whether to accept or - * deny. - * - * FIXME: further target states TBD. - */ -enum uwb_rsv_state { - UWB_RSV_STATE_NONE = 0, - UWB_RSV_STATE_O_INITIATED, - UWB_RSV_STATE_O_PENDING, - UWB_RSV_STATE_O_MODIFIED, - UWB_RSV_STATE_O_ESTABLISHED, - UWB_RSV_STATE_O_TO_BE_MOVED, - UWB_RSV_STATE_O_MOVE_EXPANDING, - UWB_RSV_STATE_O_MOVE_COMBINING, - UWB_RSV_STATE_O_MOVE_REDUCING, - UWB_RSV_STATE_T_ACCEPTED, - UWB_RSV_STATE_T_DENIED, - UWB_RSV_STATE_T_CONFLICT, - UWB_RSV_STATE_T_PENDING, - UWB_RSV_STATE_T_EXPANDING_ACCEPTED, - UWB_RSV_STATE_T_EXPANDING_CONFLICT, - UWB_RSV_STATE_T_EXPANDING_PENDING, - UWB_RSV_STATE_T_EXPANDING_DENIED, - UWB_RSV_STATE_T_RESIZED, - - UWB_RSV_STATE_LAST, -}; - -enum uwb_rsv_target_type { - UWB_RSV_TARGET_DEV, - UWB_RSV_TARGET_DEVADDR, -}; - -/** - * struct uwb_rsv_target - the target of a reservation. - * - * Reservations unicast and targeted at a single device - * (UWB_RSV_TARGET_DEV); or (e.g., in the case of WUSB) targeted at a - * specific (private) DevAddr (UWB_RSV_TARGET_DEVADDR). - */ -struct uwb_rsv_target { - enum uwb_rsv_target_type type; - union { - struct uwb_dev *dev; - struct uwb_dev_addr devaddr; - }; -}; - -struct uwb_rsv_move { - struct uwb_mas_bm final_mas; - struct uwb_ie_drp *companion_drp_ie; - struct uwb_mas_bm companion_mas; -}; - -/* - * Number of streams reserved for reservations targeted at DevAddrs. - */ -#define UWB_NUM_GLOBAL_STREAMS 1 - -typedef void (*uwb_rsv_cb_f)(struct uwb_rsv *rsv); - -/** - * struct uwb_rsv - a DRP reservation - * - * Data structure management: - * - * @rc: the radio controller this reservation is for - * (as target or owner) - * @rc_node: a list node for the RC - * @pal_node: a list node for the PAL - * - * Owner and target parameters: - * - * @owner: the UWB device owning this reservation - * @target: the target UWB device - * @type: reservation type - * - * Owner parameters: - * - * @max_mas: maxiumum number of MAS - * @min_mas: minimum number of MAS - * @sparsity: owner selected sparsity - * @is_multicast: true iff multicast - * - * @callback: callback function when the reservation completes - * @pal_priv: private data for the PAL making the reservation - * - * Reservation status: - * - * @status: negotiation status - * @stream: stream index allocated for this reservation - * @tiebreaker: conflict tiebreaker for this reservation - * @mas: reserved MAS - * @drp_ie: the DRP IE - * @ie_valid: true iff the DRP IE matches the reservation parameters - * - * DRP reservations are uniquely identified by the owner, target and - * stream index. However, when using a DevAddr as a target (e.g., for - * a WUSB cluster reservation) the responses may be received from - * devices with different DevAddrs. In this case, reservations are - * uniquely identified by just the stream index. A number of stream - * indexes (UWB_NUM_GLOBAL_STREAMS) are reserved for this. - */ -struct uwb_rsv { - struct uwb_rc *rc; - struct list_head rc_node; - struct list_head pal_node; - struct kref kref; - - struct uwb_dev *owner; - struct uwb_rsv_target target; - enum uwb_drp_type type; - int max_mas; - int min_mas; - int max_interval; - bool is_multicast; - - uwb_rsv_cb_f callback; - void *pal_priv; - - enum uwb_rsv_state state; - bool needs_release_companion_mas; - u8 stream; - u8 tiebreaker; - struct uwb_mas_bm mas; - struct uwb_ie_drp *drp_ie; - struct uwb_rsv_move mv; - bool ie_valid; - struct timer_list timer; - struct work_struct handle_timeout_work; -}; - -static const -struct uwb_mas_bm uwb_mas_bm_zero = { .bm = { 0 } }; - -static inline void uwb_mas_bm_copy_le(void *dst, const struct uwb_mas_bm *mas) -{ - bitmap_copy_le(dst, mas->bm, UWB_NUM_MAS); -} - -/** - * struct uwb_drp_avail - a radio controller's view of MAS usage - * @global: MAS unused by neighbors (excluding reservations targeted - * or owned by the local radio controller) or the beaon period - * @local: MAS unused by local established reservations - * @pending: MAS unused by local pending reservations - * @ie: DRP Availability IE to be included in the beacon - * @ie_valid: true iff @ie is valid and does not need to regenerated from - * @global and @local - * - * Each radio controller maintains a view of MAS usage or - * availability. MAS available for a new reservation are determined - * from the intersection of @global, @local, and @pending. - * - * The radio controller must transmit a DRP Availability IE that's the - * intersection of @global and @local. - * - * A set bit indicates the MAS is unused and available. - * - * rc->rsvs_mutex should be held before accessing this data structure. - * - * [ECMA-368] section 17.4.3. - */ -struct uwb_drp_avail { - DECLARE_BITMAP(global, UWB_NUM_MAS); - DECLARE_BITMAP(local, UWB_NUM_MAS); - DECLARE_BITMAP(pending, UWB_NUM_MAS); - struct uwb_ie_drp_avail ie; - bool ie_valid; -}; - -struct uwb_drp_backoff_win { - u8 window; - u8 n; - int total_expired; - struct timer_list timer; - bool can_reserve_extra_mases; -}; - -const char *uwb_rsv_state_str(enum uwb_rsv_state state); -const char *uwb_rsv_type_str(enum uwb_drp_type type); - -struct uwb_rsv *uwb_rsv_create(struct uwb_rc *rc, uwb_rsv_cb_f cb, - void *pal_priv); -void uwb_rsv_destroy(struct uwb_rsv *rsv); - -int uwb_rsv_establish(struct uwb_rsv *rsv); -int uwb_rsv_modify(struct uwb_rsv *rsv, - int max_mas, int min_mas, int sparsity); -void uwb_rsv_terminate(struct uwb_rsv *rsv); - -void uwb_rsv_accept(struct uwb_rsv *rsv, uwb_rsv_cb_f cb, void *pal_priv); - -void uwb_rsv_get_usable_mas(struct uwb_rsv *orig_rsv, struct uwb_mas_bm *mas); - -/** - * Radio Control Interface instance - * - * - * Life cycle rules: those of the UWB Device. - * - * @index: an index number for this radio controller, as used in the - * device name. - * @version: version of protocol supported by this device - * @priv: Backend implementation; rw with uwb_dev.dev.sem taken. - * @cmd: Backend implementation to execute commands; rw and call - * only with uwb_dev.dev.sem taken. - * @reset: Hardware reset of radio controller and any PAL controllers. - * @filter: Backend implementation to manipulate data to and from device - * to be compliant to specification assumed by driver (WHCI - * 0.95). - * - * uwb_dev.dev.mutex is used to execute commands and update - * the corresponding structures; can't use a spinlock - * because rc->cmd() can sleep. - * @ies: This is a dynamically allocated array cacheing the - * IEs (settable by the host) that the beacon of this - * radio controller is currently sending. - * - * In reality, we store here the full command we set to - * the radio controller (which is basically a command - * prefix followed by all the IEs the beacon currently - * contains). This way we don't have to realloc and - * memcpy when setting it. - * - * We set this up in uwb_rc_ie_setup(), where we alloc - * this struct, call get_ie() [so we know which IEs are - * currently being sent, if any]. - * - * @ies_capacity:Amount of space (in bytes) allocated in @ies. The - * amount used is given by sizeof(*ies) plus ies->wIELength - * (which is a little endian quantity all the time). - * @ies_mutex: protect the IE cache - * @dbg: information for the debug interface - */ -struct uwb_rc { - struct uwb_dev uwb_dev; - int index; - u16 version; - - struct module *owner; - void *priv; - int (*start)(struct uwb_rc *rc); - void (*stop)(struct uwb_rc *rc); - int (*cmd)(struct uwb_rc *, const struct uwb_rccb *, size_t); - int (*reset)(struct uwb_rc *rc); - int (*filter_cmd)(struct uwb_rc *, struct uwb_rccb **, size_t *); - int (*filter_event)(struct uwb_rc *, struct uwb_rceb **, const size_t, - size_t *, size_t *); - - spinlock_t neh_lock; /* protects neh_* and ctx_* */ - struct list_head neh_list; /* Open NE handles */ - unsigned long ctx_bm[UWB_RC_CTX_MAX / 8 / sizeof(unsigned long)]; - u8 ctx_roll; - - int beaconing; /* Beaconing state [channel number] */ - int beaconing_forced; - int scanning; - enum uwb_scan_type scan_type:3; - unsigned ready:1; - struct uwb_notifs_chain notifs_chain; - struct uwb_beca uwb_beca; - - struct uwbd uwbd; - - struct uwb_drp_backoff_win bow; - struct uwb_drp_avail drp_avail; - struct list_head reservations; - struct list_head cnflt_alien_list; - struct uwb_mas_bm cnflt_alien_bitmap; - struct mutex rsvs_mutex; - spinlock_t rsvs_lock; - struct workqueue_struct *rsv_workq; - - struct delayed_work rsv_update_work; - struct delayed_work rsv_alien_bp_work; - int set_drp_ie_pending; - struct mutex ies_mutex; - struct uwb_rc_cmd_set_ie *ies; - size_t ies_capacity; - - struct list_head pals; - int active_pals; - - struct uwb_dbg *dbg; -}; - - -/** - * struct uwb_pal - a UWB PAL - * @name: descriptive name for this PAL (wusbhc, wlp, etc.). - * @device: a device for the PAL. Used to link the PAL and the radio - * controller in sysfs. - * @rc: the radio controller the PAL uses. - * @channel_changed: called when the channel used by the radio changes. - * A channel of -1 means the channel has been stopped. - * @new_rsv: called when a peer requests a reservation (may be NULL if - * the PAL cannot accept reservation requests). - * @channel: channel being used by the PAL; 0 if the PAL isn't using - * the radio; -1 if the PAL wishes to use the radio but - * cannot. - * @debugfs_dir: a debugfs directory which the PAL can use for its own - * debugfs files. - * - * A Protocol Adaptation Layer (PAL) is a user of the WiMedia UWB - * radio platform (e.g., WUSB, WLP or Bluetooth UWB AMP). - * - * The PALs using a radio controller must register themselves to - * permit the UWB stack to coordinate usage of the radio between the - * various PALs or to allow PALs to response to certain requests from - * peers. - * - * A struct uwb_pal should be embedded in a containing structure - * belonging to the PAL and initialized with uwb_pal_init()). Fields - * should be set appropriately by the PAL before registering the PAL - * with uwb_pal_register(). - */ -struct uwb_pal { - struct list_head node; - const char *name; - struct device *device; - struct uwb_rc *rc; - - void (*channel_changed)(struct uwb_pal *pal, int channel); - void (*new_rsv)(struct uwb_pal *pal, struct uwb_rsv *rsv); - - int channel; - struct dentry *debugfs_dir; -}; - -void uwb_pal_init(struct uwb_pal *pal); -int uwb_pal_register(struct uwb_pal *pal); -void uwb_pal_unregister(struct uwb_pal *pal); - -int uwb_radio_start(struct uwb_pal *pal); -void uwb_radio_stop(struct uwb_pal *pal); - -/* - * General public API - * - * This API can be used by UWB device drivers or by those implementing - * UWB Radio Controllers - */ -struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc, - const struct uwb_dev_addr *devaddr); -struct uwb_dev *uwb_dev_get_by_rc(struct uwb_dev *, struct uwb_rc *); -static inline void uwb_dev_get(struct uwb_dev *uwb_dev) -{ - get_device(&uwb_dev->dev); -} -static inline void uwb_dev_put(struct uwb_dev *uwb_dev) -{ - put_device(&uwb_dev->dev); -} -struct uwb_dev *uwb_dev_try_get(struct uwb_rc *rc, struct uwb_dev *uwb_dev); - -/** - * Callback function for 'uwb_{dev,rc}_foreach()'. - * - * @dev: Linux device instance - * 'uwb_dev = container_of(dev, struct uwb_dev, dev)' - * @priv: Data passed by the caller to 'uwb_{dev,rc}_foreach()'. - * - * @returns: 0 to continue the iterations, any other val to stop - * iterating and return the value to the caller of - * _foreach(). - */ -typedef int (*uwb_dev_for_each_f)(struct device *dev, void *priv); -int uwb_dev_for_each(struct uwb_rc *rc, uwb_dev_for_each_f func, void *priv); - -struct uwb_rc *uwb_rc_alloc(void); -struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr *); -struct uwb_rc *uwb_rc_get_by_grandpa(const struct device *); -void uwb_rc_put(struct uwb_rc *rc); - -typedef void (*uwb_rc_cmd_cb_f)(struct uwb_rc *rc, void *arg, - struct uwb_rceb *reply, ssize_t reply_size); - -int uwb_rc_cmd_async(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - u8 expected_type, u16 expected_event, - uwb_rc_cmd_cb_f cb, void *arg); -ssize_t uwb_rc_cmd(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - struct uwb_rceb *reply, size_t reply_size); -ssize_t uwb_rc_vcmd(struct uwb_rc *rc, const char *cmd_name, - struct uwb_rccb *cmd, size_t cmd_size, - u8 expected_type, u16 expected_event, - struct uwb_rceb **preply); - -size_t __uwb_addr_print(char *, size_t, const unsigned char *, int); - -int uwb_rc_dev_addr_set(struct uwb_rc *, const struct uwb_dev_addr *); -int uwb_rc_dev_addr_get(struct uwb_rc *, struct uwb_dev_addr *); -int uwb_rc_mac_addr_set(struct uwb_rc *, const struct uwb_mac_addr *); -int uwb_rc_mac_addr_get(struct uwb_rc *, struct uwb_mac_addr *); -int __uwb_mac_addr_assigned_check(struct device *, void *); -int __uwb_dev_addr_assigned_check(struct device *, void *); - -/* Print in @buf a pretty repr of @addr */ -static inline size_t uwb_dev_addr_print(char *buf, size_t buf_size, - const struct uwb_dev_addr *addr) -{ - return __uwb_addr_print(buf, buf_size, addr->data, 0); -} - -/* Print in @buf a pretty repr of @addr */ -static inline size_t uwb_mac_addr_print(char *buf, size_t buf_size, - const struct uwb_mac_addr *addr) -{ - return __uwb_addr_print(buf, buf_size, addr->data, 1); -} - -/* @returns 0 if device addresses @addr2 and @addr1 are equal */ -static inline int uwb_dev_addr_cmp(const struct uwb_dev_addr *addr1, - const struct uwb_dev_addr *addr2) -{ - return memcmp(addr1, addr2, sizeof(*addr1)); -} - -/* @returns 0 if MAC addresses @addr2 and @addr1 are equal */ -static inline int uwb_mac_addr_cmp(const struct uwb_mac_addr *addr1, - const struct uwb_mac_addr *addr2) -{ - return memcmp(addr1, addr2, sizeof(*addr1)); -} - -/* @returns !0 if a MAC @addr is a broadcast address */ -static inline int uwb_mac_addr_bcast(const struct uwb_mac_addr *addr) -{ - struct uwb_mac_addr bcast = { - .data = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } - }; - return !uwb_mac_addr_cmp(addr, &bcast); -} - -/* @returns !0 if a MAC @addr is all zeroes*/ -static inline int uwb_mac_addr_unset(const struct uwb_mac_addr *addr) -{ - struct uwb_mac_addr unset = { - .data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } - }; - return !uwb_mac_addr_cmp(addr, &unset); -} - -/* @returns !0 if the address is in use. */ -static inline unsigned __uwb_dev_addr_assigned(struct uwb_rc *rc, - struct uwb_dev_addr *addr) -{ - return uwb_dev_for_each(rc, __uwb_dev_addr_assigned_check, addr); -} - -/* - * UWB Radio Controller API - * - * This API is used (in addition to the general API) to implement UWB - * Radio Controllers. - */ -void uwb_rc_init(struct uwb_rc *); -int uwb_rc_add(struct uwb_rc *, struct device *dev, void *rc_priv); -void uwb_rc_rm(struct uwb_rc *); -void uwb_rc_neh_grok(struct uwb_rc *, void *, size_t); -void uwb_rc_neh_error(struct uwb_rc *, int); -void uwb_rc_reset_all(struct uwb_rc *rc); -void uwb_rc_pre_reset(struct uwb_rc *rc); -int uwb_rc_post_reset(struct uwb_rc *rc); - -/** - * uwb_rsv_is_owner - is the owner of this reservation the RC? - * @rsv: the reservation - */ -static inline bool uwb_rsv_is_owner(struct uwb_rsv *rsv) -{ - return rsv->owner == &rsv->rc->uwb_dev; -} - -/** - * enum uwb_notifs - UWB events that can be passed to any listeners - * @UWB_NOTIF_ONAIR: a new neighbour has joined the beacon group. - * @UWB_NOTIF_OFFAIR: a neighbour has left the beacon group. - * - * Higher layers can register callback functions with the radio - * controller using uwb_notifs_register(). The radio controller - * maintains a list of all registered handlers and will notify all - * nodes when an event occurs. - */ -enum uwb_notifs { - UWB_NOTIF_ONAIR, - UWB_NOTIF_OFFAIR, -}; - -/* Callback function registered with UWB */ -struct uwb_notifs_handler { - struct list_head list_node; - void (*cb)(void *, struct uwb_dev *, enum uwb_notifs); - void *data; -}; - -int uwb_notifs_register(struct uwb_rc *, struct uwb_notifs_handler *); -int uwb_notifs_deregister(struct uwb_rc *, struct uwb_notifs_handler *); - - -/** - * UWB radio controller Event Size Entry (for creating entry tables) - * - * WUSB and WHCI define events and notifications, and they might have - * fixed or variable size. - * - * Each event/notification has a size which is not necessarily known - * in advance based on the event code. As well, vendor specific - * events/notifications will have a size impossible to determine - * unless we know about the device's specific details. - * - * It was way too smart of the spec writers not to think that it would - * be impossible for a generic driver to skip over vendor specific - * events/notifications if there are no LENGTH fields in the HEADER of - * each message...the transaction size cannot be counted on as the - * spec does not forbid to pack more than one event in a single - * transaction. - * - * Thus, we guess sizes with tables (or for events, when you know the - * size ahead of time you can use uwb_rc_neh_extra_size*()). We - * register tables with the known events and their sizes, and then we - * traverse those tables. For those with variable length, we provide a - * way to lookup the size inside the event/notification's - * payload. This allows device-specific event size tables to be - * registered. - * - * @size: Size of the payload - * - * @offset: if != 0, at offset @offset-1 starts a field with a length - * that has to be added to @size. The format of the field is - * given by @type. - * - * @type: Type and length of the offset field. Most common is LE 16 - * bits (that's why that is zero); others are there mostly to - * cover for bugs and weirdos. - */ -struct uwb_est_entry { - size_t size; - unsigned offset; - enum { UWB_EST_16 = 0, UWB_EST_8 = 1 } type; -}; - -int uwb_est_register(u8 type, u8 code_high, u16 vendor, u16 product, - const struct uwb_est_entry *, size_t entries); -int uwb_est_unregister(u8 type, u8 code_high, u16 vendor, u16 product, - const struct uwb_est_entry *, size_t entries); -ssize_t uwb_est_find_size(struct uwb_rc *rc, const struct uwb_rceb *rceb, - size_t len); - -/* -- Misc */ - -enum { - EDC_MAX_ERRORS = 10, - EDC_ERROR_TIMEFRAME = HZ, -}; - -/* error density counter */ -struct edc { - unsigned long timestart; - u16 errorcount; -}; - -static inline -void edc_init(struct edc *edc) -{ - edc->timestart = jiffies; -} - -/* Called when an error occurred. - * This is way to determine if the number of acceptable errors per time - * period has been exceeded. It is not accurate as there are cases in which - * this scheme will not work, for example if there are periodic occurrences - * of errors that straddle updates to the start time. This scheme is - * sufficient for our usage. - * - * @returns 1 if maximum acceptable errors per timeframe has been exceeded. - */ -static inline int edc_inc(struct edc *err_hist, u16 max_err, u16 timeframe) -{ - unsigned long now; - - now = jiffies; - if (now - err_hist->timestart > timeframe) { - err_hist->errorcount = 1; - err_hist->timestart = now; - } else if (++err_hist->errorcount > max_err) { - err_hist->errorcount = 0; - err_hist->timestart = now; - return 1; - } - return 0; -} - - -/* Information Element handling */ - -struct uwb_ie_hdr *uwb_ie_next(void **ptr, size_t *len); -int uwb_rc_ie_add(struct uwb_rc *uwb_rc, const struct uwb_ie_hdr *ies, size_t size); -int uwb_rc_ie_rm(struct uwb_rc *uwb_rc, enum uwb_ie element_id); - -/* - * Transmission statistics - * - * UWB uses LQI and RSSI (one byte values) for reporting radio signal - * strength and line quality indication. We do quick and dirty - * averages of those. They are signed values, btw. - * - * For 8 bit quantities, we keep the min, the max, an accumulator - * (@sigma) and a # of samples. When @samples gets to 255, we compute - * the average (@sigma / @samples), place it in @sigma and reset - * @samples to 1 (so we use it as the first sample). - * - * Now, statistically speaking, probably I am kicking the kidneys of - * some books I have in my shelves collecting dust, but I just want to - * get an approx, not the Nobel. - * - * LOCKING: there is no locking per se, but we try to keep a lockless - * schema. Only _add_samples() modifies the values--as long as you - * have other locking on top that makes sure that no two calls of - * _add_sample() happen at the same time, then we are fine. Now, for - * resetting the values we just set @samples to 0 and that makes the - * next _add_sample() to start with defaults. Reading the values in - * _show() currently can race, so you need to make sure the calls are - * under the same lock that protects calls to _add_sample(). FIXME: - * currently unlocked (It is not ultraprecise but does the trick. Bite - * me). - */ -struct stats { - s8 min, max; - s16 sigma; - atomic_t samples; -}; - -static inline -void stats_init(struct stats *stats) -{ - atomic_set(&stats->samples, 0); - wmb(); -} - -static inline -void stats_add_sample(struct stats *stats, s8 sample) -{ - s8 min, max; - s16 sigma; - unsigned samples = atomic_read(&stats->samples); - if (samples == 0) { /* it was zero before, so we initialize */ - min = 127; - max = -128; - sigma = 0; - } else { - min = stats->min; - max = stats->max; - sigma = stats->sigma; - } - - if (sample < min) /* compute new values */ - min = sample; - else if (sample > max) - max = sample; - sigma += sample; - - stats->min = min; /* commit */ - stats->max = max; - stats->sigma = sigma; - if (atomic_add_return(1, &stats->samples) > 255) { - /* wrapped around! reset */ - stats->sigma = sigma / 256; - atomic_set(&stats->samples, 1); - } -} - -static inline ssize_t stats_show(struct stats *stats, char *buf) -{ - int min, max, avg; - int samples = atomic_read(&stats->samples); - if (samples == 0) - min = max = avg = 0; - else { - min = stats->min; - max = stats->max; - avg = stats->sigma / samples; - } - return scnprintf(buf, PAGE_SIZE, "%d %d %d\n", min, max, avg); -} - -static inline ssize_t stats_store(struct stats *stats, const char *buf, - size_t size) -{ - stats_init(stats); - return size; -} - -#endif /* #ifndef __LINUX__UWB_H__ */ diff --git a/drivers/staging/uwb/uwbd.c b/drivers/staging/uwb/uwbd.c deleted file mode 100644 index dc5c743d4f5f..000000000000 --- a/drivers/staging/uwb/uwbd.c +++ /dev/null @@ -1,356 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Ultra Wide Band - * Neighborhood Management Daemon - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This daemon takes care of maintaing information that describes the - * UWB neighborhood that the radios in this machine can see. It also - * keeps a tab of which devices are visible, makes sure each HC sits - * on a different channel to avoid interfering, etc. - * - * Different drivers (radio controller, device, any API in general) - * communicate with this daemon through an event queue. Daemon wakes - * up, takes a list of events and handles them one by one; handling - * function is extracted from a table based on the event's type and - * subtype. Events are freed only if the handling function says so. - * - * . Lock protecting the event list has to be an spinlock and locked - * with IRQSAVE because it might be called from an interrupt - * context (ie: when events arrive and the notification drops - * down from the ISR). - * - * . UWB radio controller drivers queue events to the daemon using - * uwbd_event_queue(). They just get the event, chew it to make it - * look like UWBD likes it and pass it in a buffer allocated with - * uwb_event_alloc(). - * - * EVENTS - * - * Events have a type, a subtype, a length, some other stuff and the - * data blob, which depends on the event. The header is 'struct - * uwb_event'; for payloads, see 'struct uwbd_evt_*'. - * - * EVENT HANDLER TABLES - * - * To find a handling function for an event, the type is used to index - * a subtype-table in the type-table. The subtype-table is indexed - * with the subtype to get the function that handles the event. Start - * with the main type-table 'uwbd_evt_type_handler'. - * - * DEVICES - * - * Devices are created when a bunch of beacons have been received and - * it is stablished that the device has stable radio presence. CREATED - * only, not configured. Devices are ONLY configured when an - * Application-Specific IE Probe is receieved, in which the device - * declares which Protocol ID it groks. Then the device is CONFIGURED - * (and the driver->probe() stuff of the device model is invoked). - * - * Devices are considered disconnected when a certain number of - * beacons are not received in an amount of time. - * - * Handler functions are called normally uwbd_evt_handle_*(). - */ -#include <linux/kthread.h> -#include <linux/slab.h> -#include <linux/module.h> -#include <linux/freezer.h> - -#include "uwb-internal.h" - -/* - * UWBD Event handler function signature - * - * Return !0 if the event needs not to be freed (ie the handler - * takes/took care of it). 0 means the daemon code will free the - * event. - * - * @evt->rc is already referenced and guaranteed to exist. See - * uwb_evt_handle(). - */ -typedef int (*uwbd_evt_handler_f)(struct uwb_event *); - -/** - * Properties of a UWBD event - * - * @handler: the function that will handle this event - * @name: text name of event - */ -struct uwbd_event { - uwbd_evt_handler_f handler; - const char *name; -}; - -/* Table of handlers for and properties of the UWBD Radio Control Events */ -static struct uwbd_event uwbd_urc_events[] = { - [UWB_RC_EVT_IE_RCV] = { - .handler = uwbd_evt_handle_rc_ie_rcv, - .name = "IE_RECEIVED" - }, - [UWB_RC_EVT_BEACON] = { - .handler = uwbd_evt_handle_rc_beacon, - .name = "BEACON_RECEIVED" - }, - [UWB_RC_EVT_BEACON_SIZE] = { - .handler = uwbd_evt_handle_rc_beacon_size, - .name = "BEACON_SIZE_CHANGE" - }, - [UWB_RC_EVT_BPOIE_CHANGE] = { - .handler = uwbd_evt_handle_rc_bpoie_change, - .name = "BPOIE_CHANGE" - }, - [UWB_RC_EVT_BP_SLOT_CHANGE] = { - .handler = uwbd_evt_handle_rc_bp_slot_change, - .name = "BP_SLOT_CHANGE" - }, - [UWB_RC_EVT_DRP_AVAIL] = { - .handler = uwbd_evt_handle_rc_drp_avail, - .name = "DRP_AVAILABILITY_CHANGE" - }, - [UWB_RC_EVT_DRP] = { - .handler = uwbd_evt_handle_rc_drp, - .name = "DRP" - }, - [UWB_RC_EVT_DEV_ADDR_CONFLICT] = { - .handler = uwbd_evt_handle_rc_dev_addr_conflict, - .name = "DEV_ADDR_CONFLICT", - }, -}; - - - -struct uwbd_evt_type_handler { - const char *name; - struct uwbd_event *uwbd_events; - size_t size; -}; - -/* Table of handlers for each UWBD Event type. */ -static struct uwbd_evt_type_handler uwbd_urc_evt_type_handlers[] = { - [UWB_RC_CET_GENERAL] = { - .name = "URC", - .uwbd_events = uwbd_urc_events, - .size = ARRAY_SIZE(uwbd_urc_events), - }, -}; - -static const struct uwbd_event uwbd_message_handlers[] = { - [UWB_EVT_MSG_RESET] = { - .handler = uwbd_msg_handle_reset, - .name = "reset", - }, -}; - -/* - * Handle an URC event passed to the UWB Daemon - * - * @evt: the event to handle - * @returns: 0 if the event can be kfreed, !0 on the contrary - * (somebody else took ownership) [coincidentally, returning - * a <0 errno code will free it :)]. - * - * Looks up the two indirection tables (one for the type, one for the - * subtype) to decide which function handles it and then calls the - * handler. - * - * The event structure passed to the event handler has the radio - * controller in @evt->rc referenced. The reference will be dropped - * once the handler returns, so if it needs it for longer (async), - * it'll need to take another one. - */ -static -int uwbd_event_handle_urc(struct uwb_event *evt) -{ - int result = -EINVAL; - struct uwbd_evt_type_handler *type_table; - uwbd_evt_handler_f handler; - u8 type, context; - u16 event; - - type = evt->notif.rceb->bEventType; - event = le16_to_cpu(evt->notif.rceb->wEvent); - context = evt->notif.rceb->bEventContext; - - if (type >= ARRAY_SIZE(uwbd_urc_evt_type_handlers)) - goto out; - type_table = &uwbd_urc_evt_type_handlers[type]; - if (type_table->uwbd_events == NULL) - goto out; - if (event >= type_table->size) - goto out; - handler = type_table->uwbd_events[event].handler; - if (handler == NULL) - goto out; - - result = (*handler)(evt); -out: - if (result < 0) - dev_err(&evt->rc->uwb_dev.dev, - "UWBD: event 0x%02x/%04x/%02x, handling failed: %d\n", - type, event, context, result); - return result; -} - -static void uwbd_event_handle_message(struct uwb_event *evt) -{ - struct uwb_rc *rc; - int result; - - rc = evt->rc; - - if (evt->message < 0 || evt->message >= ARRAY_SIZE(uwbd_message_handlers)) { - dev_err(&rc->uwb_dev.dev, "UWBD: invalid message type %d\n", evt->message); - return; - } - - result = uwbd_message_handlers[evt->message].handler(evt); - if (result < 0) - dev_err(&rc->uwb_dev.dev, "UWBD: '%s' message failed: %d\n", - uwbd_message_handlers[evt->message].name, result); -} - -static void uwbd_event_handle(struct uwb_event *evt) -{ - struct uwb_rc *rc; - int should_keep; - - rc = evt->rc; - - if (rc->ready) { - switch (evt->type) { - case UWB_EVT_TYPE_NOTIF: - should_keep = uwbd_event_handle_urc(evt); - if (should_keep <= 0) - kfree(evt->notif.rceb); - break; - case UWB_EVT_TYPE_MSG: - uwbd_event_handle_message(evt); - break; - default: - dev_err(&rc->uwb_dev.dev, "UWBD: invalid event type %d\n", evt->type); - break; - } - } - - __uwb_rc_put(rc); /* for the __uwb_rc_get() in uwb_rc_notif_cb() */ -} - -/** - * UWB Daemon - * - * Listens to all UWB notifications and takes care to track the state - * of the UWB neighbourhood for the kernel. When we do a run, we - * spinlock, move the list to a private copy and release the - * lock. Hold it as little as possible. Not a conflict: it is - * guaranteed we own the events in the private list. - * - * FIXME: should change so we don't have a 1HZ timer all the time, but - * only if there are devices. - */ -static int uwbd(void *param) -{ - struct uwb_rc *rc = param; - unsigned long flags; - struct uwb_event *evt; - int should_stop = 0; - - while (1) { - wait_event_interruptible_timeout( - rc->uwbd.wq, - !list_empty(&rc->uwbd.event_list) - || (should_stop = kthread_should_stop()), - HZ); - if (should_stop) - break; - - spin_lock_irqsave(&rc->uwbd.event_list_lock, flags); - if (!list_empty(&rc->uwbd.event_list)) { - evt = list_first_entry(&rc->uwbd.event_list, struct uwb_event, list_node); - list_del(&evt->list_node); - } else - evt = NULL; - spin_unlock_irqrestore(&rc->uwbd.event_list_lock, flags); - - if (evt) { - uwbd_event_handle(evt); - kfree(evt); - } - - uwb_beca_purge(rc); /* Purge devices that left */ - } - return 0; -} - - -/** Start the UWB daemon */ -void uwbd_start(struct uwb_rc *rc) -{ - struct task_struct *task = kthread_run(uwbd, rc, "uwbd"); - if (IS_ERR(task)) { - rc->uwbd.task = NULL; - printk(KERN_ERR "UWB: Cannot start management daemon; " - "UWB won't work\n"); - } else { - rc->uwbd.task = task; - rc->uwbd.pid = rc->uwbd.task->pid; - } -} - -/* Stop the UWB daemon and free any unprocessed events */ -void uwbd_stop(struct uwb_rc *rc) -{ - if (rc->uwbd.task) - kthread_stop(rc->uwbd.task); - uwbd_flush(rc); -} - -/* - * Queue an event for the management daemon - * - * When some lower layer receives an event, it uses this function to - * push it forward to the UWB daemon. - * - * Once you pass the event, you don't own it any more, but the daemon - * does. It will uwb_event_free() it when done, so make sure you - * uwb_event_alloc()ed it or bad things will happen. - * - * If the daemon is not running, we just free the event. - */ -void uwbd_event_queue(struct uwb_event *evt) -{ - struct uwb_rc *rc = evt->rc; - unsigned long flags; - - spin_lock_irqsave(&rc->uwbd.event_list_lock, flags); - if (rc->uwbd.pid != 0) { - list_add(&evt->list_node, &rc->uwbd.event_list); - wake_up_all(&rc->uwbd.wq); - } else { - __uwb_rc_put(evt->rc); - if (evt->type == UWB_EVT_TYPE_NOTIF) - kfree(evt->notif.rceb); - kfree(evt); - } - spin_unlock_irqrestore(&rc->uwbd.event_list_lock, flags); - return; -} - -void uwbd_flush(struct uwb_rc *rc) -{ - struct uwb_event *evt, *nxt; - - spin_lock_irq(&rc->uwbd.event_list_lock); - list_for_each_entry_safe(evt, nxt, &rc->uwbd.event_list, list_node) { - if (evt->rc == rc) { - __uwb_rc_put(rc); - list_del(&evt->list_node); - if (evt->type == UWB_EVT_TYPE_NOTIF) - kfree(evt->notif.rceb); - kfree(evt); - } - } - spin_unlock_irq(&rc->uwbd.event_list_lock); -} diff --git a/drivers/staging/uwb/whc-rc.c b/drivers/staging/uwb/whc-rc.c deleted file mode 100644 index a5ab255d7d36..000000000000 --- a/drivers/staging/uwb/whc-rc.c +++ /dev/null @@ -1,467 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Wireless Host Controller: Radio Control Interface (WHCI v0.95[2.3]) - * Radio Control command/event transport to the UWB stack - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Initialize and hook up the Radio Control interface. - * - * For each device probed, creates an 'struct whcrc' which contains - * just the representation of the UWB Radio Controller, and the logic - * for reading notifications and passing them to the UWB Core. - * - * So we initialize all of those, register the UWB Radio Controller - * and setup the notification/event handle to pipe the notifications - * to the UWB management Daemon. - * - * Once uwb_rc_add() is called, the UWB stack takes control, resets - * the radio and readies the device to take commands the UWB - * API/user-space. - * - * Note this driver is just a transport driver; the commands are - * formed at the UWB stack and given to this driver who will deliver - * them to the hw and transfer the replies/notifications back to the - * UWB stack through the UWB daemon (UWBD). - */ -#include <linux/init.h> -#include <linux/module.h> -#include <linux/pci.h> -#include <linux/sched.h> -#include <linux/dma-mapping.h> -#include <linux/interrupt.h> -#include <linux/slab.h> -#include <linux/workqueue.h> -#include "uwb.h" -#include "include/whci.h" -#include "include/umc.h" - -#include "uwb-internal.h" - -/** - * Descriptor for an instance of the UWB Radio Control Driver that - * attaches to the URC interface of the WHCI PCI card. - * - * Unless there is a lock specific to the 'data members', all access - * is protected by uwb_rc->mutex. - */ -struct whcrc { - struct umc_dev *umc_dev; - struct uwb_rc *uwb_rc; /* UWB host controller */ - - unsigned long area; - void __iomem *rc_base; - size_t rc_len; - spinlock_t irq_lock; - - void *evt_buf, *cmd_buf; - dma_addr_t evt_dma_buf, cmd_dma_buf; - wait_queue_head_t cmd_wq; - struct work_struct event_work; -}; - -/** - * Execute an UWB RC command on WHCI/RC - * - * @rc: Instance of a Radio Controller that is a whcrc - * @cmd: Buffer containing the RCCB and payload to execute - * @cmd_size: Size of the command buffer. - * - * We copy the command into whcrc->cmd_buf (as it is pretty and - * aligned`and physically contiguous) and then press the right keys in - * the controller's URCCMD register to get it to read it. We might - * have to wait for the cmd_sem to be open to us. - * - * NOTE: rc's mutex has to be locked - */ -static int whcrc_cmd(struct uwb_rc *uwb_rc, - const struct uwb_rccb *cmd, size_t cmd_size) -{ - int result = 0; - struct whcrc *whcrc = uwb_rc->priv; - struct device *dev = &whcrc->umc_dev->dev; - u32 urccmd; - - if (cmd_size >= 4096) - return -EINVAL; - - /* - * If the URC is halted, then the hardware has reset itself. - * Attempt to recover by restarting the device and then return - * an error as it's likely that the current command isn't - * valid for a newly started RC. - */ - if (le_readl(whcrc->rc_base + URCSTS) & URCSTS_HALTED) { - dev_err(dev, "requesting reset of halted radio controller\n"); - uwb_rc_reset_all(uwb_rc); - return -EIO; - } - - result = wait_event_timeout(whcrc->cmd_wq, - !(le_readl(whcrc->rc_base + URCCMD) & URCCMD_ACTIVE), HZ/2); - if (result == 0) { - dev_err(dev, "device is not ready to execute commands\n"); - return -ETIMEDOUT; - } - - memmove(whcrc->cmd_buf, cmd, cmd_size); - le_writeq(whcrc->cmd_dma_buf, whcrc->rc_base + URCCMDADDR); - - spin_lock(&whcrc->irq_lock); - urccmd = le_readl(whcrc->rc_base + URCCMD); - urccmd &= ~(URCCMD_EARV | URCCMD_SIZE_MASK); - le_writel(urccmd | URCCMD_ACTIVE | URCCMD_IWR | cmd_size, - whcrc->rc_base + URCCMD); - spin_unlock(&whcrc->irq_lock); - - return 0; -} - -static int whcrc_reset(struct uwb_rc *rc) -{ - struct whcrc *whcrc = rc->priv; - - return umc_controller_reset(whcrc->umc_dev); -} - -/** - * Reset event reception mechanism and tell hw we are ready to get more - * - * We have read all the events in the event buffer, so we are ready to - * reset it to the beginning. - * - * This is only called during initialization or after an event buffer - * has been retired. This means we can be sure that event processing - * is disabled and it's safe to update the URCEVTADDR register. - * - * There's no need to wait for the event processing to start as the - * URC will not clear URCCMD_ACTIVE until (internal) event buffer - * space is available. - */ -static -void whcrc_enable_events(struct whcrc *whcrc) -{ - u32 urccmd; - - le_writeq(whcrc->evt_dma_buf, whcrc->rc_base + URCEVTADDR); - - spin_lock(&whcrc->irq_lock); - urccmd = le_readl(whcrc->rc_base + URCCMD) & ~URCCMD_ACTIVE; - le_writel(urccmd | URCCMD_EARV, whcrc->rc_base + URCCMD); - spin_unlock(&whcrc->irq_lock); -} - -static void whcrc_event_work(struct work_struct *work) -{ - struct whcrc *whcrc = container_of(work, struct whcrc, event_work); - size_t size; - u64 urcevtaddr; - - urcevtaddr = le_readq(whcrc->rc_base + URCEVTADDR); - size = urcevtaddr & URCEVTADDR_OFFSET_MASK; - - uwb_rc_neh_grok(whcrc->uwb_rc, whcrc->evt_buf, size); - whcrc_enable_events(whcrc); -} - -/** - * Catch interrupts? - * - * We ack inmediately (and expect the hw to do the right thing and - * raise another IRQ if things have changed :) - */ -static -irqreturn_t whcrc_irq_cb(int irq, void *_whcrc) -{ - struct whcrc *whcrc = _whcrc; - struct device *dev = &whcrc->umc_dev->dev; - u32 urcsts; - - urcsts = le_readl(whcrc->rc_base + URCSTS); - if (!(urcsts & URCSTS_INT_MASK)) - return IRQ_NONE; - le_writel(urcsts & URCSTS_INT_MASK, whcrc->rc_base + URCSTS); - - if (urcsts & URCSTS_HSE) { - dev_err(dev, "host system error -- hardware halted\n"); - /* FIXME: do something sensible here */ - goto out; - } - if (urcsts & URCSTS_ER) - schedule_work(&whcrc->event_work); - if (urcsts & URCSTS_RCI) - wake_up_all(&whcrc->cmd_wq); -out: - return IRQ_HANDLED; -} - - -/** - * Initialize a UMC RC interface: map regions, get (shared) IRQ - */ -static -int whcrc_setup_rc_umc(struct whcrc *whcrc) -{ - int result = 0; - struct device *dev = &whcrc->umc_dev->dev; - struct umc_dev *umc_dev = whcrc->umc_dev; - - whcrc->area = umc_dev->resource.start; - whcrc->rc_len = resource_size(&umc_dev->resource); - result = -EBUSY; - if (request_mem_region(whcrc->area, whcrc->rc_len, KBUILD_MODNAME) == NULL) { - dev_err(dev, "can't request URC region (%zu bytes @ 0x%lx): %d\n", - whcrc->rc_len, whcrc->area, result); - goto error_request_region; - } - - whcrc->rc_base = ioremap(whcrc->area, whcrc->rc_len); - if (whcrc->rc_base == NULL) { - dev_err(dev, "can't ioremap registers (%zu bytes @ 0x%lx): %d\n", - whcrc->rc_len, whcrc->area, result); - goto error_ioremap; - } - - result = request_irq(umc_dev->irq, whcrc_irq_cb, IRQF_SHARED, - KBUILD_MODNAME, whcrc); - if (result < 0) { - dev_err(dev, "can't allocate IRQ %d: %d\n", - umc_dev->irq, result); - goto error_request_irq; - } - - result = -ENOMEM; - whcrc->cmd_buf = dma_alloc_coherent(&umc_dev->dev, PAGE_SIZE, - &whcrc->cmd_dma_buf, GFP_KERNEL); - if (whcrc->cmd_buf == NULL) { - dev_err(dev, "Can't allocate cmd transfer buffer\n"); - goto error_cmd_buffer; - } - - whcrc->evt_buf = dma_alloc_coherent(&umc_dev->dev, PAGE_SIZE, - &whcrc->evt_dma_buf, GFP_KERNEL); - if (whcrc->evt_buf == NULL) { - dev_err(dev, "Can't allocate evt transfer buffer\n"); - goto error_evt_buffer; - } - return 0; - -error_evt_buffer: - dma_free_coherent(&umc_dev->dev, PAGE_SIZE, whcrc->cmd_buf, - whcrc->cmd_dma_buf); -error_cmd_buffer: - free_irq(umc_dev->irq, whcrc); -error_request_irq: - iounmap(whcrc->rc_base); -error_ioremap: - release_mem_region(whcrc->area, whcrc->rc_len); -error_request_region: - return result; -} - - -/** - * Release RC's UMC resources - */ -static -void whcrc_release_rc_umc(struct whcrc *whcrc) -{ - struct umc_dev *umc_dev = whcrc->umc_dev; - - dma_free_coherent(&umc_dev->dev, PAGE_SIZE, whcrc->evt_buf, - whcrc->evt_dma_buf); - dma_free_coherent(&umc_dev->dev, PAGE_SIZE, whcrc->cmd_buf, - whcrc->cmd_dma_buf); - free_irq(umc_dev->irq, whcrc); - iounmap(whcrc->rc_base); - release_mem_region(whcrc->area, whcrc->rc_len); -} - - -/** - * whcrc_start_rc - start a WHCI radio controller - * @whcrc: the radio controller to start - * - * Reset the UMC device, start the radio controller, enable events and - * finally enable interrupts. - */ -static int whcrc_start_rc(struct uwb_rc *rc) -{ - struct whcrc *whcrc = rc->priv; - struct device *dev = &whcrc->umc_dev->dev; - - /* Reset the thing */ - le_writel(URCCMD_RESET, whcrc->rc_base + URCCMD); - if (whci_wait_for(dev, whcrc->rc_base + URCCMD, URCCMD_RESET, 0, - 5000, "hardware reset") < 0) - return -EBUSY; - - /* Set the event buffer, start the controller (enable IRQs later) */ - le_writel(0, whcrc->rc_base + URCINTR); - le_writel(URCCMD_RS, whcrc->rc_base + URCCMD); - if (whci_wait_for(dev, whcrc->rc_base + URCSTS, URCSTS_HALTED, 0, - 5000, "radio controller start") < 0) - return -ETIMEDOUT; - whcrc_enable_events(whcrc); - le_writel(URCINTR_EN_ALL, whcrc->rc_base + URCINTR); - return 0; -} - - -/** - * whcrc_stop_rc - stop a WHCI radio controller - * @whcrc: the radio controller to stop - * - * Disable interrupts and cancel any pending event processing work - * before clearing the Run/Stop bit. - */ -static -void whcrc_stop_rc(struct uwb_rc *rc) -{ - struct whcrc *whcrc = rc->priv; - struct umc_dev *umc_dev = whcrc->umc_dev; - - le_writel(0, whcrc->rc_base + URCINTR); - cancel_work_sync(&whcrc->event_work); - - le_writel(0, whcrc->rc_base + URCCMD); - whci_wait_for(&umc_dev->dev, whcrc->rc_base + URCSTS, - URCSTS_HALTED, URCSTS_HALTED, 100, "radio controller stop"); -} - -static void whcrc_init(struct whcrc *whcrc) -{ - spin_lock_init(&whcrc->irq_lock); - init_waitqueue_head(&whcrc->cmd_wq); - INIT_WORK(&whcrc->event_work, whcrc_event_work); -} - -/** - * Initialize the radio controller. - * - * NOTE: we setup whcrc->uwb_rc before calling uwb_rc_add(); in the - * IRQ handler we use that to determine if the hw is ready to - * handle events. Looks like a race condition, but it really is - * not. - */ -static -int whcrc_probe(struct umc_dev *umc_dev) -{ - int result; - struct uwb_rc *uwb_rc; - struct whcrc *whcrc; - struct device *dev = &umc_dev->dev; - - result = -ENOMEM; - uwb_rc = uwb_rc_alloc(); - if (uwb_rc == NULL) { - dev_err(dev, "unable to allocate RC instance\n"); - goto error_rc_alloc; - } - whcrc = kzalloc(sizeof(*whcrc), GFP_KERNEL); - if (whcrc == NULL) { - dev_err(dev, "unable to allocate WHC-RC instance\n"); - goto error_alloc; - } - whcrc_init(whcrc); - whcrc->umc_dev = umc_dev; - - result = whcrc_setup_rc_umc(whcrc); - if (result < 0) { - dev_err(dev, "Can't setup RC UMC interface: %d\n", result); - goto error_setup_rc_umc; - } - whcrc->uwb_rc = uwb_rc; - - uwb_rc->owner = THIS_MODULE; - uwb_rc->cmd = whcrc_cmd; - uwb_rc->reset = whcrc_reset; - uwb_rc->start = whcrc_start_rc; - uwb_rc->stop = whcrc_stop_rc; - - result = uwb_rc_add(uwb_rc, dev, whcrc); - if (result < 0) - goto error_rc_add; - umc_set_drvdata(umc_dev, whcrc); - return 0; - -error_rc_add: - whcrc_release_rc_umc(whcrc); -error_setup_rc_umc: - kfree(whcrc); -error_alloc: - uwb_rc_put(uwb_rc); -error_rc_alloc: - return result; -} - -/** - * Clean up the radio control resources - * - * When we up the command semaphore, everybody possibly held trying to - * execute a command should be granted entry and then they'll see the - * host is quiescing and up it (so it will chain to the next waiter). - * This should not happen (in any case), as we can only remove when - * there are no handles open... - */ -static void whcrc_remove(struct umc_dev *umc_dev) -{ - struct whcrc *whcrc = umc_get_drvdata(umc_dev); - struct uwb_rc *uwb_rc = whcrc->uwb_rc; - - umc_set_drvdata(umc_dev, NULL); - uwb_rc_rm(uwb_rc); - whcrc_release_rc_umc(whcrc); - kfree(whcrc); - uwb_rc_put(uwb_rc); -} - -static int whcrc_pre_reset(struct umc_dev *umc) -{ - struct whcrc *whcrc = umc_get_drvdata(umc); - struct uwb_rc *uwb_rc = whcrc->uwb_rc; - - uwb_rc_pre_reset(uwb_rc); - return 0; -} - -static int whcrc_post_reset(struct umc_dev *umc) -{ - struct whcrc *whcrc = umc_get_drvdata(umc); - struct uwb_rc *uwb_rc = whcrc->uwb_rc; - - return uwb_rc_post_reset(uwb_rc); -} - -/* PCI device ID's that we handle [so it gets loaded] */ -static struct pci_device_id __used whcrc_id_table[] = { - { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, - { /* empty last entry */ } -}; -MODULE_DEVICE_TABLE(pci, whcrc_id_table); - -static struct umc_driver whcrc_driver = { - .name = "whc-rc", - .cap_id = UMC_CAP_ID_WHCI_RC, - .probe = whcrc_probe, - .remove = whcrc_remove, - .pre_reset = whcrc_pre_reset, - .post_reset = whcrc_post_reset, -}; - -static int __init whcrc_driver_init(void) -{ - return umc_driver_register(&whcrc_driver); -} -module_init(whcrc_driver_init); - -static void __exit whcrc_driver_exit(void) -{ - umc_driver_unregister(&whcrc_driver); -} -module_exit(whcrc_driver_exit); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Wireless Host Controller Radio Control Driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/uwb/whci.c b/drivers/staging/uwb/whci.c deleted file mode 100644 index a8832f64d708..000000000000 --- a/drivers/staging/uwb/whci.c +++ /dev/null @@ -1,257 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * WHCI UWB Multi-interface Controller enumerator. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/delay.h> -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/pci.h> -#include <linux/dma-mapping.h> -#include <linux/slab.h> -#include "include/whci.h" -#include "include/umc.h" - -struct whci_card { - struct pci_dev *pci; - void __iomem *uwbbase; - u8 n_caps; - struct umc_dev *devs[0]; -}; - - -/* Fix faulty HW :( */ -static -u64 whci_capdata_quirks(struct whci_card *card, u64 capdata) -{ - u64 capdata_orig = capdata; - struct pci_dev *pci_dev = card->pci; - if (pci_dev->vendor == PCI_VENDOR_ID_INTEL - && (pci_dev->device == 0x0c3b || pci_dev->device == 0004) - && pci_dev->class == 0x0d1010) { - switch (UWBCAPDATA_TO_CAP_ID(capdata)) { - /* WLP capability has 0x100 bytes of aperture */ - case 0x80: - capdata |= 0x40 << 8; break; - /* WUSB capability has 0x80 bytes of aperture - * and ID is 1 */ - case 0x02: - capdata &= ~0xffff; - capdata |= 0x2001; - break; - } - } - if (capdata_orig != capdata) - dev_warn(&pci_dev->dev, - "PCI v%04x d%04x c%06x#%02x: " - "corrected capdata from %016Lx to %016Lx\n", - pci_dev->vendor, pci_dev->device, pci_dev->class, - (unsigned)UWBCAPDATA_TO_CAP_ID(capdata), - (unsigned long long)capdata_orig, - (unsigned long long)capdata); - return capdata; -} - - -/** - * whci_wait_for - wait for a WHCI register to be set - * - * Polls (for at most @max_ms ms) until '*@reg & @mask == @result'. - */ -int whci_wait_for(struct device *dev, u32 __iomem *reg, u32 mask, u32 result, - unsigned long max_ms, const char *tag) -{ - unsigned t = 0; - u32 val; - for (;;) { - val = le_readl(reg); - if ((val & mask) == result) - break; - if (t >= max_ms) { - dev_err(dev, "%s timed out\n", tag); - return -ETIMEDOUT; - } - msleep(10); - t += 10; - } - return 0; -} -EXPORT_SYMBOL_GPL(whci_wait_for); - - -/* - * NOTE: the capinfo and capdata registers are slightly different - * (size and cap-id fields). So for cap #0, we need to fill - * in. Size comes from the size of the register block - * (statically calculated); cap_id comes from nowhere, we use - * zero, that is reserved, for the radio controller, because - * none was defined at the spec level. - */ -static int whci_add_cap(struct whci_card *card, int n) -{ - struct umc_dev *umc; - u64 capdata; - int bar, err; - - umc = umc_device_create(&card->pci->dev, n); - if (umc == NULL) - return -ENOMEM; - - capdata = le_readq(card->uwbbase + UWBCAPDATA(n)); - - bar = UWBCAPDATA_TO_BAR(capdata) << 1; - - capdata = whci_capdata_quirks(card, capdata); - /* Capability 0 is the radio controller. It's size is 32 - * bytes (WHCI0.95[2.3, T2-9]). */ - umc->version = UWBCAPDATA_TO_VERSION(capdata); - umc->cap_id = n == 0 ? 0 : UWBCAPDATA_TO_CAP_ID(capdata); - umc->bar = bar; - umc->resource.start = pci_resource_start(card->pci, bar) - + UWBCAPDATA_TO_OFFSET(capdata); - umc->resource.end = umc->resource.start - + (n == 0 ? 0x20 : UWBCAPDATA_TO_SIZE(capdata)) - 1; - umc->resource.name = dev_name(&umc->dev); - umc->resource.flags = card->pci->resource[bar].flags; - umc->resource.parent = &card->pci->resource[bar]; - umc->irq = card->pci->irq; - - err = umc_device_register(umc); - if (err < 0) - goto error; - card->devs[n] = umc; - return 0; - -error: - kfree(umc); - return err; -} - -static void whci_del_cap(struct whci_card *card, int n) -{ - struct umc_dev *umc = card->devs[n]; - - umc_device_unregister(umc); -} - -static int whci_n_caps(struct pci_dev *pci) -{ - void __iomem *uwbbase; - u64 capinfo; - - uwbbase = pci_iomap(pci, 0, 8); - if (!uwbbase) - return -ENOMEM; - capinfo = le_readq(uwbbase + UWBCAPINFO); - pci_iounmap(pci, uwbbase); - - return UWBCAPINFO_TO_N_CAPS(capinfo); -} - -static int whci_probe(struct pci_dev *pci, const struct pci_device_id *id) -{ - struct whci_card *card; - int err, n_caps, n; - - err = pci_enable_device(pci); - if (err < 0) - goto error; - pci_enable_msi(pci); - pci_set_master(pci); - err = -ENXIO; - if (!pci_set_dma_mask(pci, DMA_BIT_MASK(64))) - pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); - else if (!pci_set_dma_mask(pci, DMA_BIT_MASK(32))) - pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); - else - goto error_dma; - - err = n_caps = whci_n_caps(pci); - if (n_caps < 0) - goto error_ncaps; - - err = -ENOMEM; - card = kzalloc(sizeof(struct whci_card) - + sizeof(struct umc_dev *) * (n_caps + 1), - GFP_KERNEL); - if (card == NULL) - goto error_kzalloc; - card->pci = pci; - card->n_caps = n_caps; - - err = -EBUSY; - if (!request_mem_region(pci_resource_start(pci, 0), - UWBCAPDATA_SIZE(card->n_caps), - "whci (capability data)")) - goto error_request_memregion; - err = -ENOMEM; - card->uwbbase = pci_iomap(pci, 0, UWBCAPDATA_SIZE(card->n_caps)); - if (!card->uwbbase) - goto error_iomap; - - /* Add each capability. */ - for (n = 0; n <= card->n_caps; n++) { - err = whci_add_cap(card, n); - if (err < 0 && n == 0) { - dev_err(&pci->dev, "cannot bind UWB radio controller:" - " %d\n", err); - goto error_bind; - } - if (err < 0) - dev_warn(&pci->dev, "warning: cannot bind capability " - "#%u: %d\n", n, err); - } - pci_set_drvdata(pci, card); - return 0; - -error_bind: - pci_iounmap(pci, card->uwbbase); -error_iomap: - release_mem_region(pci_resource_start(pci, 0), UWBCAPDATA_SIZE(card->n_caps)); -error_request_memregion: - kfree(card); -error_kzalloc: -error_ncaps: -error_dma: - pci_disable_msi(pci); - pci_disable_device(pci); -error: - return err; -} - -static void whci_remove(struct pci_dev *pci) -{ - struct whci_card *card = pci_get_drvdata(pci); - int n; - - pci_set_drvdata(pci, NULL); - /* Unregister each capability in reverse (so the master device - * is unregistered last). */ - for (n = card->n_caps; n >= 0 ; n--) - whci_del_cap(card, n); - pci_iounmap(pci, card->uwbbase); - release_mem_region(pci_resource_start(pci, 0), UWBCAPDATA_SIZE(card->n_caps)); - kfree(card); - pci_disable_msi(pci); - pci_disable_device(pci); -} - -static struct pci_device_id whci_id_table[] = { - { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, - { 0 }, -}; -MODULE_DEVICE_TABLE(pci, whci_id_table); - - -static struct pci_driver whci_driver = { - .name = "whci", - .id_table = whci_id_table, - .probe = whci_probe, - .remove = whci_remove, -}; - -module_pci_driver(whci_driver); -MODULE_DESCRIPTION("WHCI UWB Multi-interface Controller enumerator"); -MODULE_AUTHOR("Cambridge Silicon Radio Ltd."); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/vc04_services/bcm2835-camera/controls.c b/drivers/staging/vc04_services/bcm2835-camera/controls.c index 89786c264867..5137fcf203d6 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/controls.c +++ b/drivers/staging/vc04_services/bcm2835-camera/controls.c @@ -85,7 +85,6 @@ struct bm2835_mmal_v4l2_ctrl { const s64 *imenu; /* integer menu array */ u32 mmal_id; /* mmal parameter id */ bm2835_mmal_v4l2_ctrl_cb *setter; - bool ignore_errors; }; struct v4l2_to_mmal_effects_setting { @@ -912,8 +911,6 @@ static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl) if (ret) pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n", ctrl->id, mmal_ctrl->mmal_id, ret); - if (mmal_ctrl->ignore_errors) - ret = 0; return ret; } @@ -923,239 +920,340 @@ static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = { static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = { { - V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD, - -100, 100, 0, 1, NULL, - MMAL_PARAMETER_SATURATION, - ctrl_set_rational, - false + .id = V4L2_CID_SATURATION, + .type = MMAL_CONTROL_TYPE_STD, + .min = -100, + .max = 100, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_SATURATION, + .setter = ctrl_set_rational, }, { - V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD, - -100, 100, 0, 1, NULL, - MMAL_PARAMETER_SHARPNESS, - ctrl_set_rational, - false + .id = V4L2_CID_SHARPNESS, + .type = MMAL_CONTROL_TYPE_STD, + .min = -100, + .max = 100, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_SHARPNESS, + .setter = ctrl_set_rational, }, { - V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD, - -100, 100, 0, 1, NULL, - MMAL_PARAMETER_CONTRAST, - ctrl_set_rational, - false + .id = V4L2_CID_CONTRAST, + .type = MMAL_CONTROL_TYPE_STD, + .min = -100, + .max = 100, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_CONTRAST, + .setter = ctrl_set_rational, }, { - V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD, - 0, 100, 50, 1, NULL, - MMAL_PARAMETER_BRIGHTNESS, - ctrl_set_rational, - false + .id = V4L2_CID_BRIGHTNESS, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 100, + .def = 50, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_BRIGHTNESS, + .setter = ctrl_set_rational, }, { - V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU, - 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu, - MMAL_PARAMETER_ISO, - ctrl_set_iso, - false + .id = V4L2_CID_ISO_SENSITIVITY, + .type = MMAL_CONTROL_TYPE_INT_MENU, + .min = 0, + .max = ARRAY_SIZE(iso_qmenu) - 1, + .def = 0, + .step = 1, + .imenu = iso_qmenu, + .mmal_id = MMAL_PARAMETER_ISO, + .setter = ctrl_set_iso, }, { - V4L2_CID_ISO_SENSITIVITY_AUTO, MMAL_CONTROL_TYPE_STD_MENU, - 0, V4L2_ISO_SENSITIVITY_AUTO, V4L2_ISO_SENSITIVITY_AUTO, 1, - NULL, MMAL_PARAMETER_ISO, - ctrl_set_iso, - false + .id = V4L2_CID_ISO_SENSITIVITY_AUTO, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = 0, + .max = V4L2_ISO_SENSITIVITY_AUTO, + .def = V4L2_ISO_SENSITIVITY_AUTO, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_ISO, + .setter = ctrl_set_iso, }, { - V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD, - 0, 1, 0, 1, NULL, - MMAL_PARAMETER_VIDEO_STABILISATION, - ctrl_set_value, - false + .id = V4L2_CID_IMAGE_STABILIZATION, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 1, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_VIDEO_STABILISATION, + .setter = ctrl_set_value, }, { - V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU, - ~0x03, V4L2_EXPOSURE_APERTURE_PRIORITY, V4L2_EXPOSURE_AUTO, 0, - NULL, MMAL_PARAMETER_EXPOSURE_MODE, - ctrl_set_exposure, - false + .id = V4L2_CID_EXPOSURE_AUTO, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = ~0x03, + .max = V4L2_EXPOSURE_APERTURE_PRIORITY, + .def = V4L2_EXPOSURE_AUTO, + .step = 0, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_EXPOSURE_MODE, + .setter = ctrl_set_exposure, }, { - V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD, + .id = V4L2_CID_EXPOSURE_ABSOLUTE, + .type = MMAL_CONTROL_TYPE_STD, /* Units of 100usecs */ - 1, 1 * 1000 * 10, 100 * 10, 1, NULL, - MMAL_PARAMETER_SHUTTER_SPEED, - ctrl_set_exposure, - false + .min = 1, + .max = 1 * 1000 * 10, + .def = 100 * 10, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_SHUTTER_SPEED, + .setter = ctrl_set_exposure, }, { - V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU, - 0, ARRAY_SIZE(ev_bias_qmenu) - 1, - (ARRAY_SIZE(ev_bias_qmenu) + 1) / 2 - 1, 0, ev_bias_qmenu, - MMAL_PARAMETER_EXPOSURE_COMP, - ctrl_set_value_ev, - false + .id = V4L2_CID_AUTO_EXPOSURE_BIAS, + .type = MMAL_CONTROL_TYPE_INT_MENU, + .min = 0, + .max = ARRAY_SIZE(ev_bias_qmenu) - 1, + .def = (ARRAY_SIZE(ev_bias_qmenu) + 1) / 2 - 1, + .step = 0, + .imenu = ev_bias_qmenu, + .mmal_id = MMAL_PARAMETER_EXPOSURE_COMP, + .setter = ctrl_set_value_ev, }, { - V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD, - 0, 1, - 0, 1, NULL, - 0, /* Dummy MMAL ID as it gets mapped into FPS range*/ - ctrl_set_exposure, - false + .id = V4L2_CID_EXPOSURE_AUTO_PRIORITY, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 1, + .def = 0, + .step = 1, + .imenu = NULL, + /* Dummy MMAL ID as it gets mapped into FPS range */ + .mmal_id = 0, + .setter = ctrl_set_exposure, }, { - V4L2_CID_EXPOSURE_METERING, - MMAL_CONTROL_TYPE_STD_MENU, - ~0x7, V4L2_EXPOSURE_METERING_SPOT, - V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL, - MMAL_PARAMETER_EXP_METERING_MODE, - ctrl_set_metering_mode, - false + .id = V4L2_CID_EXPOSURE_METERING, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = ~0x7, + .max = V4L2_EXPOSURE_METERING_SPOT, + .def = V4L2_EXPOSURE_METERING_AVERAGE, + .step = 0, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_EXP_METERING_MODE, + .setter = ctrl_set_metering_mode, }, { - V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, - MMAL_CONTROL_TYPE_STD_MENU, - ~0x3ff, V4L2_WHITE_BALANCE_SHADE, V4L2_WHITE_BALANCE_AUTO, 0, - NULL, - MMAL_PARAMETER_AWB_MODE, - ctrl_set_awb_mode, - false + .id = V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = ~0x3ff, + .max = V4L2_WHITE_BALANCE_SHADE, + .def = V4L2_WHITE_BALANCE_AUTO, + .step = 0, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_AWB_MODE, + .setter = ctrl_set_awb_mode, }, { - V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD, - 1, 7999, 1000, 1, NULL, - MMAL_PARAMETER_CUSTOM_AWB_GAINS, - ctrl_set_awb_gains, - false + .id = V4L2_CID_RED_BALANCE, + .type = MMAL_CONTROL_TYPE_STD, + .min = 1, + .max = 7999, + .def = 1000, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_CUSTOM_AWB_GAINS, + .setter = ctrl_set_awb_gains, }, { - V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD, - 1, 7999, 1000, 1, NULL, - MMAL_PARAMETER_CUSTOM_AWB_GAINS, - ctrl_set_awb_gains, - false + .id = V4L2_CID_BLUE_BALANCE, + .type = MMAL_CONTROL_TYPE_STD, + .min = 1, + .max = 7999, + .def = 1000, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_CUSTOM_AWB_GAINS, + .setter = ctrl_set_awb_gains, }, { - V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU, - 0, V4L2_COLORFX_SET_CBCR, V4L2_COLORFX_NONE, 0, NULL, - MMAL_PARAMETER_IMAGE_EFFECT, - ctrl_set_image_effect, - false + .id = V4L2_CID_COLORFX, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = 0, + .max = V4L2_COLORFX_SET_CBCR, + .def = V4L2_COLORFX_NONE, + .step = 0, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_IMAGE_EFFECT, + .setter = ctrl_set_image_effect, }, { - V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD, - 0, 0xffff, 0x8080, 1, NULL, - MMAL_PARAMETER_COLOUR_EFFECT, - ctrl_set_colfx, - false + .id = V4L2_CID_COLORFX_CBCR, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 0xffff, + .def = 0x8080, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_COLOUR_EFFECT, + .setter = ctrl_set_colfx, }, { - V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD, - 0, 360, 0, 90, NULL, - MMAL_PARAMETER_ROTATION, - ctrl_set_rotate, - false + .id = V4L2_CID_ROTATE, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 360, + .def = 0, + .step = 90, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_ROTATION, + .setter = ctrl_set_rotate, }, { - V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD, - 0, 1, 0, 1, NULL, - MMAL_PARAMETER_MIRROR, - ctrl_set_flip, - false + .id = V4L2_CID_HFLIP, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 1, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_MIRROR, + .setter = ctrl_set_flip, }, { - V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD, - 0, 1, 0, 1, NULL, - MMAL_PARAMETER_MIRROR, - ctrl_set_flip, - false + .id = V4L2_CID_VFLIP, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 1, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_MIRROR, + .setter = ctrl_set_flip, }, { - V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU, - 0, V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, - 0, 0, NULL, - MMAL_PARAMETER_RATECONTROL, - ctrl_set_bitrate_mode, - false + .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = 0, + .max = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, + .def = 0, + .step = 0, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_RATECONTROL, + .setter = ctrl_set_bitrate_mode, }, { - V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD, - 25 * 1000, 25 * 1000 * 1000, 10 * 1000 * 1000, 25 * 1000, NULL, - MMAL_PARAMETER_VIDEO_BIT_RATE, - ctrl_set_bitrate, - false + .id = V4L2_CID_MPEG_VIDEO_BITRATE, + .type = MMAL_CONTROL_TYPE_STD, + .min = 25 * 1000, + .max = 25 * 1000 * 1000, + .def = 10 * 1000 * 1000, + .step = 25 * 1000, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_VIDEO_BIT_RATE, + .setter = ctrl_set_bitrate, }, { - V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD, - 1, 100, - 30, 1, NULL, - MMAL_PARAMETER_JPEG_Q_FACTOR, - ctrl_set_image_encode_output, - false + .id = V4L2_CID_JPEG_COMPRESSION_QUALITY, + .type = MMAL_CONTROL_TYPE_STD, + .min = 1, + .max = 100, + .def = 30, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_JPEG_Q_FACTOR, + .setter = ctrl_set_image_encode_output, }, { - V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU, - 0, V4L2_CID_POWER_LINE_FREQUENCY_AUTO, - 1, 1, NULL, - MMAL_PARAMETER_FLICKER_AVOID, - ctrl_set_flicker_avoidance, - false + .id = V4L2_CID_POWER_LINE_FREQUENCY, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = 0, + .max = V4L2_CID_POWER_LINE_FREQUENCY_AUTO, + .def = 1, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_FLICKER_AVOID, + .setter = ctrl_set_flicker_avoidance, }, { - V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD, - 0, 1, - 0, 1, NULL, - MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, - ctrl_set_video_encode_param_output, - false + .id = V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 1, + .def = 0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, + .setter = ctrl_set_video_encode_param_output, }, { - V4L2_CID_MPEG_VIDEO_H264_PROFILE, - MMAL_CONTROL_TYPE_STD_MENU, - ~(BIT(V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) | - BIT(V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) | - BIT(V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) | - BIT(V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)), - V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, - V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL, - MMAL_PARAMETER_PROFILE, - ctrl_set_video_encode_profile_level, - false + .id = V4L2_CID_MPEG_VIDEO_H264_PROFILE, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = ~(BIT(V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) | + BIT(V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) | + BIT(V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) | + BIT(V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)), + .max = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, + .def = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_PROFILE, + .setter = ctrl_set_video_encode_profile_level, }, { - V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU, - ~(BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_0) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1B) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_1) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_2) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_3) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_1) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_2) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_0) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_1) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_2) | - BIT(V4L2_MPEG_VIDEO_H264_LEVEL_4_0)), - V4L2_MPEG_VIDEO_H264_LEVEL_4_0, - V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL, - MMAL_PARAMETER_PROFILE, - ctrl_set_video_encode_profile_level, - false + .id = V4L2_CID_MPEG_VIDEO_H264_LEVEL, + .type = MMAL_CONTROL_TYPE_STD_MENU, + .min = ~(BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_0) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1B) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_1) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_2) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_1_3) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_0) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_1) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_2_2) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_0) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_1) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_3_2) | + BIT(V4L2_MPEG_VIDEO_H264_LEVEL_4_0)), + .max = V4L2_MPEG_VIDEO_H264_LEVEL_4_0, + .def = V4L2_MPEG_VIDEO_H264_LEVEL_4_0, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_PROFILE, + .setter = ctrl_set_video_encode_profile_level, }, { - V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU, - -1, /* Min (mask) is computed at runtime */ - V4L2_SCENE_MODE_TEXT, - V4L2_SCENE_MODE_NONE, 1, NULL, - MMAL_PARAMETER_PROFILE, - ctrl_set_scene_mode, - false + .id = V4L2_CID_SCENE_MODE, + .type = MMAL_CONTROL_TYPE_STD_MENU, + /* mask is computed at runtime */ + .min = -1, + .max = V4L2_SCENE_MODE_TEXT, + .def = V4L2_SCENE_MODE_NONE, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_PROFILE, + .setter = ctrl_set_scene_mode, }, { - V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD, - 0, 0x7FFFFFFF, 60, 1, NULL, - MMAL_PARAMETER_INTRAPERIOD, - ctrl_set_video_encode_param_output, - false + .id = V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, + .type = MMAL_CONTROL_TYPE_STD, + .min = 0, + .max = 0x7FFFFFFF, + .def = 60, + .step = 1, + .imenu = NULL, + .mmal_id = MMAL_PARAMETER_INTRAPERIOD, + .setter = ctrl_set_video_encode_param_output, }, }; @@ -1168,7 +1266,7 @@ int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev) if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) { ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c], &v4l2_ctrls[c]); - if (!v4l2_ctrls[c].ignore_errors && ret) { + if (ret) { v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "Failed when setting default values for ctrl %d\n", c); diff --git a/drivers/staging/vc04_services/interface/vchi/vchi_common.h b/drivers/staging/vc04_services/interface/vchi/vchi_common.h index 141af16ce031..7fc04e38936d 100644 --- a/drivers/staging/vc04_services/interface/vchi/vchi_common.h +++ b/drivers/staging/vc04_services/interface/vchi/vchi_common.h @@ -33,10 +33,14 @@ enum vchi_crc_control { enum vchi_callback_reason { VCHI_CALLBACK_REASON_MIN, - //This indicates that there is data available - //handle is the msg id that was transmitted with the data - // When a message is received and there was no FULL message available previously, send callback - // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails + /* + * This indicates that there is data available handle is the msg id that + * was transmitted with the data + * When a message is received and there was no FULL message available + * previously, send callback + * Tasks get kicked by the callback, reset their event and try and read + * from the fifo until it fails + */ VCHI_CALLBACK_MSG_AVAILABLE, VCHI_CALLBACK_MSG_SENT, VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented @@ -51,9 +55,11 @@ enum vchi_callback_reason { VCHI_CALLBACK_SERVICE_CLOSED, - // this side has sent XOFF to peer due to lack of data consumption by service - // (suggests the service may need to take some recovery action if it has - // been deliberately holding off consuming data) + /* + * this side has sent XOFF to peer due to lack of data consumption by + * service (suggests the service may need to take some recovery action + * if it has been deliberately holding off consuming data) + */ VCHI_CALLBACK_SENT_XOFF, VCHI_CALLBACK_SENT_XON, @@ -112,12 +118,16 @@ struct vchi_msg_vector { int32_t vec_len; }; -// Iterator structure for reading ahead through received message queue. Allocated by client, -// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only. -// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead - -// will not proceed to messages received since. Behaviour is undefined if an iterator -// is used again after messages for that service are removed/dequeued by any -// means other than vchi_msg_iter_... calls on the iterator itself. +/* + * Iterator structure for reading ahead through received message queue. + * Allocated by client, initialised by vchi_msg_look_ahead. Fields are for + * internal VCHI use only. + * Iterates over messages in queue at the instant of the call to + * vchi_msg_lookahead - will not proceed to messages received since. + * Behaviour is undefined if an iterator is used again after messages for that + * service are removed/dequeued by any means other than vchi_msg_iter_... + * calls on the iterator itself. + */ struct vchi_msg_iter { struct opaque_vchi_service_t *service; void *last; diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c index ca30bfd52919..c18c6ca0b6c0 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c @@ -257,49 +257,6 @@ int vchiq_dump_platform_state(void *dump_context) return vchiq_dump(dump_context, buf, len + 1); } -enum vchiq_status -vchiq_platform_suspend(struct vchiq_state *state) -{ - return VCHIQ_ERROR; -} - -enum vchiq_status -vchiq_platform_resume(struct vchiq_state *state) -{ - return VCHIQ_SUCCESS; -} - -void -vchiq_platform_paused(struct vchiq_state *state) -{ -} - -void -vchiq_platform_resumed(struct vchiq_state *state) -{ -} - -int -vchiq_platform_videocore_wanted(struct vchiq_state *state) -{ - return 1; // autosuspend not supported - videocore always wanted -} - -int -vchiq_platform_use_suspend_timer(void) -{ - return 0; -} -void -vchiq_dump_platform_use_state(struct vchiq_state *state) -{ - vchiq_log_info(vchiq_arm_log_level, "Suspend timer not in use"); -} -void -vchiq_platform_handle_timeout(struct vchiq_state *state) -{ - (void)state; -} /* * Local functions */ diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 4458c1e60fa3..a1ea9777a444 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -22,6 +22,7 @@ #include <linux/platform_device.h> #include <linux/compat.h> #include <linux/dma-mapping.h> +#include <linux/rcupdate.h> #include <soc/bcm2835/raspberrypi-firmware.h> #include "vchiq_core.h" @@ -48,39 +49,6 @@ int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT; int vchiq_susp_log_level = VCHIQ_LOG_ERROR; -#define SUSPEND_TIMER_TIMEOUT_MS 100 -#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000 - -#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */ -static const char *const suspend_state_names[] = { - "VC_SUSPEND_FORCE_CANCELED", - "VC_SUSPEND_REJECTED", - "VC_SUSPEND_FAILED", - "VC_SUSPEND_IDLE", - "VC_SUSPEND_REQUESTED", - "VC_SUSPEND_IN_PROGRESS", - "VC_SUSPEND_SUSPENDED" -}; -#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */ -static const char *const resume_state_names[] = { - "VC_RESUME_FAILED", - "VC_RESUME_IDLE", - "VC_RESUME_REQUESTED", - "VC_RESUME_IN_PROGRESS", - "VC_RESUME_RESUMED" -}; -/* The number of times we allow force suspend to timeout before actually -** _forcing_ suspend. This is to cater for SW which fails to release vchiq -** correctly - we don't want to prevent ARM suspend indefinitely in this case. -*/ -#define FORCE_SUSPEND_FAIL_MAX 8 - -/* The time in ms allowed for videocore to go idle when force suspend has been - * requested */ -#define FORCE_SUSPEND_TIMEOUT_MS 200 - -static void suspend_timer_callback(struct timer_list *t); - struct user_service { struct vchiq_service *service; void *userdata; @@ -2129,10 +2097,12 @@ int vchiq_dump_platform_instances(void *dump_context) /* There is no list of instances, so instead scan all services, marking those that have been dumped. */ + rcu_read_lock(); for (i = 0; i < state->unused_service; i++) { - struct vchiq_service *service = state->services[i]; + struct vchiq_service *service; struct vchiq_instance *instance; + service = rcu_dereference(state->services[i]); if (!service || service->base.callback != service_callback) continue; @@ -2140,18 +2110,26 @@ int vchiq_dump_platform_instances(void *dump_context) if (instance) instance->mark = 0; } + rcu_read_unlock(); for (i = 0; i < state->unused_service; i++) { - struct vchiq_service *service = state->services[i]; + struct vchiq_service *service; struct vchiq_instance *instance; int err; - if (!service || service->base.callback != service_callback) + rcu_read_lock(); + service = rcu_dereference(state->services[i]); + if (!service || service->base.callback != service_callback) { + rcu_read_unlock(); continue; + } instance = service->instance; - if (!instance || instance->mark) + if (!instance || instance->mark) { + rcu_read_unlock(); continue; + } + rcu_read_unlock(); len = snprintf(buf, sizeof(buf), "Instance %pK: pid %d,%s completions %d/%d", @@ -2161,7 +2139,6 @@ int vchiq_dump_platform_instances(void *dump_context) instance->completion_insert - instance->completion_remove, MAX_COMPLETIONS); - err = vchiq_dump(dump_context, buf, len + 1); if (err) return err; @@ -2184,17 +2161,17 @@ int vchiq_dump_platform_service_state(void *dump_context, char buf[80]; int len; - len = snprintf(buf, sizeof(buf), " instance %pK", service->instance); + len = scnprintf(buf, sizeof(buf), " instance %pK", service->instance); if ((service->base.callback == service_callback) && user_service->is_vchi) { - len += snprintf(buf + len, sizeof(buf) - len, + len += scnprintf(buf + len, sizeof(buf) - len, ", %d/%d messages", user_service->msg_insert - user_service->msg_remove, MSG_QUEUE_SIZE); if (user_service->dequeue_pending) - len += snprintf(buf + len, sizeof(buf) - len, + len += scnprintf(buf + len, sizeof(buf) - len, " (dequeue pending)"); } @@ -2258,27 +2235,6 @@ vchiq_fops = { * Autosuspend related functionality */ -int -vchiq_videocore_wanted(struct vchiq_state *state) -{ - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - - if (!arm_state) - /* autosuspend not supported - always return wanted */ - return 1; - else if (arm_state->blocked_count) - return 1; - else if (!arm_state->videocore_use_count) - /* usage count zero - check for override unless we're forcing */ - if (arm_state->resume_blocked) - return 0; - else - return vchiq_platform_videocore_wanted(state); - else - /* non-zero usage count - videocore still required */ - return 1; -} - static enum vchiq_status vchiq_keepalive_vchiq_callback(enum vchiq_reason reason, struct vchiq_header *header, @@ -2382,317 +2338,13 @@ vchiq_arm_init_state(struct vchiq_state *state, atomic_set(&arm_state->ka_use_ack_count, 0); atomic_set(&arm_state->ka_release_count, 0); - init_completion(&arm_state->vc_suspend_complete); - - init_completion(&arm_state->vc_resume_complete); - /* Initialise to 'done' state. We only want to block on resume - * completion while videocore is suspended. */ - set_resume_state(arm_state, VC_RESUME_RESUMED); - - init_completion(&arm_state->resume_blocker); - /* Initialise to 'done' state. We only want to block on this - * completion while resume is blocked */ - complete_all(&arm_state->resume_blocker); - - init_completion(&arm_state->blocked_blocker); - /* Initialise to 'done' state. We only want to block on this - * completion while things are waiting on the resume blocker */ - complete_all(&arm_state->blocked_blocker); - - arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS; - arm_state->suspend_timer_running = 0; arm_state->state = state; - timer_setup(&arm_state->suspend_timer, suspend_timer_callback, - 0); - arm_state->first_connect = 0; } return VCHIQ_SUCCESS; } -/* -** Functions to modify the state variables; -** set_suspend_state -** set_resume_state -** -** There are more state variables than we might like, so ensure they remain in -** step. Suspend and resume state are maintained separately, since most of -** these state machines can operate independently. However, there are a few -** states where state transitions in one state machine cause a reset to the -** other state machine. In addition, there are some completion events which -** need to occur on state machine reset and end-state(s), so these are also -** dealt with in these functions. -** -** In all states we set the state variable according to the input, but in some -** cases we perform additional steps outlined below; -** -** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time. -** The suspend completion is completed after any suspend -** attempt. When we reset the state machine we also reset -** the completion. This reset occurs when videocore is -** resumed, and also if we initiate suspend after a suspend -** failure. -** -** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for -** suspend - ie from this point on we must try to suspend -** before resuming can occur. We therefore also reset the -** resume state machine to VC_RESUME_IDLE in this state. -** -** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call -** complete_all on the suspend completion to notify -** anything waiting for suspend to happen. -** -** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also -** initiate resume, so no need to alter resume state. -** We call complete_all on the suspend completion to notify -** of suspend rejection. -** -** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the -** suspend completion and reset the resume state machine. -** -** VC_RESUME_IDLE - Initialise the resume completion at the same time. The -** resume completion is in it's 'done' state whenever -** videcore is running. Therefore, the VC_RESUME_IDLE -** state implies that videocore is suspended. -** Hence, any thread which needs to wait until videocore is -** running can wait on this completion - it will only block -** if videocore is suspended. -** -** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running. -** Call complete_all on the resume completion to unblock -** any threads waiting for resume. Also reset the suspend -** state machine to it's idle state. -** -** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists. -*/ - -void -set_suspend_state(struct vchiq_arm_state *arm_state, - enum vc_suspend_status new_state) -{ - /* set the state in all cases */ - arm_state->vc_suspend_state = new_state; - - /* state specific additional actions */ - switch (new_state) { - case VC_SUSPEND_FORCE_CANCELED: - complete_all(&arm_state->vc_suspend_complete); - break; - case VC_SUSPEND_REJECTED: - complete_all(&arm_state->vc_suspend_complete); - break; - case VC_SUSPEND_FAILED: - complete_all(&arm_state->vc_suspend_complete); - arm_state->vc_resume_state = VC_RESUME_RESUMED; - complete_all(&arm_state->vc_resume_complete); - break; - case VC_SUSPEND_IDLE: - reinit_completion(&arm_state->vc_suspend_complete); - break; - case VC_SUSPEND_REQUESTED: - break; - case VC_SUSPEND_IN_PROGRESS: - set_resume_state(arm_state, VC_RESUME_IDLE); - break; - case VC_SUSPEND_SUSPENDED: - complete_all(&arm_state->vc_suspend_complete); - break; - default: - BUG(); - break; - } -} - -void -set_resume_state(struct vchiq_arm_state *arm_state, - enum vc_resume_status new_state) -{ - /* set the state in all cases */ - arm_state->vc_resume_state = new_state; - - /* state specific additional actions */ - switch (new_state) { - case VC_RESUME_FAILED: - break; - case VC_RESUME_IDLE: - reinit_completion(&arm_state->vc_resume_complete); - break; - case VC_RESUME_REQUESTED: - break; - case VC_RESUME_IN_PROGRESS: - break; - case VC_RESUME_RESUMED: - complete_all(&arm_state->vc_resume_complete); - set_suspend_state(arm_state, VC_SUSPEND_IDLE); - break; - default: - BUG(); - break; - } -} - -/* should be called with the write lock held */ -inline void -start_suspend_timer(struct vchiq_arm_state *arm_state) -{ - del_timer(&arm_state->suspend_timer); - arm_state->suspend_timer.expires = jiffies + - msecs_to_jiffies(arm_state->suspend_timer_timeout); - add_timer(&arm_state->suspend_timer); - arm_state->suspend_timer_running = 1; -} - -/* should be called with the write lock held */ -static inline void -stop_suspend_timer(struct vchiq_arm_state *arm_state) -{ - if (arm_state->suspend_timer_running) { - del_timer(&arm_state->suspend_timer); - arm_state->suspend_timer_running = 0; - } -} - -static inline int -need_resume(struct vchiq_state *state) -{ - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - - return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) && - (arm_state->vc_resume_state < VC_RESUME_REQUESTED) && - vchiq_videocore_wanted(state); -} - -static inline void -unblock_resume(struct vchiq_arm_state *arm_state) -{ - complete_all(&arm_state->resume_blocker); - arm_state->resume_blocked = 0; -} - -/* Initiate suspend via slot handler. Should be called with the write lock - * held */ -enum vchiq_status -vchiq_arm_vcsuspend(struct vchiq_state *state) -{ - enum vchiq_status status = VCHIQ_ERROR; - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - - if (!arm_state) - goto out; - - vchiq_log_trace(vchiq_susp_log_level, "%s", __func__); - status = VCHIQ_SUCCESS; - - switch (arm_state->vc_suspend_state) { - case VC_SUSPEND_REQUESTED: - vchiq_log_info(vchiq_susp_log_level, "%s: suspend already " - "requested", __func__); - break; - case VC_SUSPEND_IN_PROGRESS: - vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in " - "progress", __func__); - break; - - default: - /* We don't expect to be in other states, so log but continue - * anyway */ - vchiq_log_error(vchiq_susp_log_level, - "%s unexpected suspend state %s", __func__, - suspend_state_names[arm_state->vc_suspend_state + - VC_SUSPEND_NUM_OFFSET]); - /* fall through */ - case VC_SUSPEND_REJECTED: - case VC_SUSPEND_FAILED: - /* Ensure any idle state actions have been run */ - set_suspend_state(arm_state, VC_SUSPEND_IDLE); - /* fall through */ - case VC_SUSPEND_IDLE: - vchiq_log_info(vchiq_susp_log_level, - "%s: suspending", __func__); - set_suspend_state(arm_state, VC_SUSPEND_REQUESTED); - /* kick the slot handler thread to initiate suspend */ - request_poll(state, NULL, 0); - break; - } - -out: - vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status); - return status; -} - -void -vchiq_platform_check_suspend(struct vchiq_state *state) -{ - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - int susp = 0; - - if (!arm_state) - goto out; - - vchiq_log_trace(vchiq_susp_log_level, "%s", __func__); - - write_lock_bh(&arm_state->susp_res_lock); - if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED && - arm_state->vc_resume_state == VC_RESUME_RESUMED) { - set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS); - susp = 1; - } - write_unlock_bh(&arm_state->susp_res_lock); - - if (susp) - vchiq_platform_suspend(state); - -out: - vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__); - return; -} - -void -vchiq_check_suspend(struct vchiq_state *state) -{ - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - - if (!arm_state) - goto out; - - vchiq_log_trace(vchiq_susp_log_level, "%s", __func__); - - write_lock_bh(&arm_state->susp_res_lock); - if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED && - arm_state->first_connect && - !vchiq_videocore_wanted(state)) { - vchiq_arm_vcsuspend(state); - } - write_unlock_bh(&arm_state->susp_res_lock); - -out: - vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__); -} - -/* This function should be called with the write lock held */ -int -vchiq_check_resume(struct vchiq_state *state) -{ - struct vchiq_arm_state *arm_state = vchiq_platform_get_arm_state(state); - int resume = 0; - - if (!arm_state) - goto out; - - vchiq_log_trace(vchiq_susp_log_level, "%s", __func__); - - if (need_resume(state)) { - set_resume_state(arm_state, VC_RESUME_REQUESTED); - request_poll(state, NULL, 0); - resume = 1; - } - -out: - vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__); - return resume; -} - enum vchiq_status vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service, enum USE_TYPE_E use_type) @@ -2724,88 +2376,15 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service, } write_lock_bh(&arm_state->susp_res_lock); - while (arm_state->resume_blocked) { - /* If we call 'use' while force suspend is waiting for suspend, - * then we're about to block the thread which the force is - * waiting to complete, so we're bound to just time out. In this - * case, set the suspend state such that the wait will be - * canceled, so we can complete as quickly as possible. */ - if (arm_state->resume_blocked && arm_state->vc_suspend_state == - VC_SUSPEND_IDLE) { - set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED); - break; - } - /* If suspend is already in progress then we need to block */ - if (!try_wait_for_completion(&arm_state->resume_blocker)) { - /* Indicate that there are threads waiting on the resume - * blocker. These need to be allowed to complete before - * a _second_ call to force suspend can complete, - * otherwise low priority threads might never actually - * continue */ - arm_state->blocked_count++; - write_unlock_bh(&arm_state->susp_res_lock); - vchiq_log_info(vchiq_susp_log_level, "%s %s resume " - "blocked - waiting...", __func__, entity); - if (wait_for_completion_killable( - &arm_state->resume_blocker)) { - vchiq_log_error(vchiq_susp_log_level, "%s %s " - "wait for resume blocker interrupted", - __func__, entity); - ret = VCHIQ_ERROR; - write_lock_bh(&arm_state->susp_res_lock); - arm_state->blocked_count--; - write_unlock_bh(&arm_state->susp_res_lock); - goto out; - } - vchiq_log_info(vchiq_susp_log_level, "%s %s resume " - "unblocked", __func__, entity); - write_lock_bh(&arm_state->susp_res_lock); - if (--arm_state->blocked_count == 0) - complete_all(&arm_state->blocked_blocker); - } - } - - stop_suspend_timer(arm_state); - local_uc = ++arm_state->videocore_use_count; local_entity_uc = ++(*entity_uc); - /* If there's a pending request which hasn't yet been serviced then - * just clear it. If we're past VC_SUSPEND_REQUESTED state then - * vc_resume_complete will block until we either resume or fail to - * suspend */ - if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED) - set_suspend_state(arm_state, VC_SUSPEND_IDLE); - - if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) { - set_resume_state(arm_state, VC_RESUME_REQUESTED); - vchiq_log_info(vchiq_susp_log_level, - "%s %s count %d, state count %d", - __func__, entity, local_entity_uc, local_uc); - request_poll(state, NULL, 0); - } else - vchiq_log_trace(vchiq_susp_log_level, - "%s %s count %d, state count %d", - __func__, entity, *entity_uc, local_uc); + vchiq_log_trace(vchiq_susp_log_level, + "%s %s count %d, state count %d", + __func__, entity, *entity_uc, local_uc); write_unlock_bh(&arm_state->susp_res_lock); - /* Completion is in a done state when we're not suspended, so this won't - * block for the non-suspended case. */ - if (!try_wait_for_completion(&arm_state->vc_resume_complete)) { - vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume", - __func__, entity); - if (wait_for_completion_killable( - &arm_state->vc_resume_complete)) { - vchiq_log_error(vchiq_susp_log_level, "%s %s wait for " - "resume interrupted", __func__, entity); - ret = VCHIQ_ERROR; - goto out; - } - vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__, - entity); - } - if (ret == VCHIQ_SUCCESS) { enum vchiq_status status = VCHIQ_SUCCESS; long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0); @@ -2860,24 +2439,10 @@ vchiq_release_internal(struct vchiq_state *state, struct vchiq_service *service) --arm_state->videocore_use_count; --(*entity_uc); - if (!vchiq_videocore_wanted(state)) { - if (vchiq_platform_use_suspend_timer() && - !arm_state->resume_blocked) { - /* Only use the timer if we're not trying to force - * suspend (=> resume_blocked) */ - start_suspend_timer(arm_state); - } else { - vchiq_log_info(vchiq_susp_log_level, - "%s %s count %d, state count %d - suspending", - __func__, entity, *entity_uc, - arm_state->videocore_use_count); - vchiq_arm_vcsuspend(state); - } - } else - vchiq_log_trace(vchiq_susp_log_level, - "%s %s count %d, state count %d", - __func__, entity, *entity_uc, - arm_state->videocore_use_count); + vchiq_log_trace(vchiq_susp_log_level, + "%s %s count %d, state count %d", + __func__, entity, *entity_uc, + arm_state->videocore_use_count); unlock: write_unlock_bh(&arm_state->susp_res_lock); @@ -2932,11 +2497,11 @@ vchiq_instance_get_use_count(struct vchiq_instance *instance) int use_count = 0, i; i = 0; - while ((service = next_service_by_instance(instance->state, - instance, &i))) { + rcu_read_lock(); + while ((service = __next_service_by_instance(instance->state, + instance, &i))) use_count += service->service_use_count; - unlock_service(service); - } + rcu_read_unlock(); return use_count; } @@ -2959,25 +2524,14 @@ vchiq_instance_set_trace(struct vchiq_instance *instance, int trace) int i; i = 0; - while ((service = next_service_by_instance(instance->state, - instance, &i))) { + rcu_read_lock(); + while ((service = __next_service_by_instance(instance->state, + instance, &i))) service->trace = trace; - unlock_service(service); - } + rcu_read_unlock(); instance->trace = (trace != 0); } -static void suspend_timer_callback(struct timer_list *t) -{ - struct vchiq_arm_state *arm_state = - from_timer(arm_state, t, suspend_timer); - struct vchiq_state *state = arm_state->state; - - vchiq_log_info(vchiq_susp_log_level, - "%s - suspend timer expired - check suspend", __func__); - vchiq_check_suspend(state); -} - enum vchiq_status vchiq_use_service(unsigned int handle) { @@ -3022,8 +2576,6 @@ vchiq_dump_service_use_state(struct vchiq_state *state) int only_nonzero = 0; static const char *nz = "<-- preventing suspend"; - enum vc_suspend_status vc_suspend_state; - enum vc_resume_status vc_resume_state; int peer_count; int vc_use_count; int active_services; @@ -3037,16 +2589,16 @@ vchiq_dump_service_use_state(struct vchiq_state *state) return; read_lock_bh(&arm_state->susp_res_lock); - vc_suspend_state = arm_state->vc_suspend_state; - vc_resume_state = arm_state->vc_resume_state; peer_count = arm_state->peer_use_count; vc_use_count = arm_state->videocore_use_count; active_services = state->unused_service; if (active_services > MAX_SERVICES) only_nonzero = 1; + rcu_read_lock(); for (i = 0; i < active_services; i++) { - struct vchiq_service *service_ptr = state->services[i]; + struct vchiq_service *service_ptr = + rcu_dereference(state->services[i]); if (!service_ptr) continue; @@ -3064,16 +2616,10 @@ vchiq_dump_service_use_state(struct vchiq_state *state) if (found >= MAX_SERVICES) break; } + rcu_read_unlock(); read_unlock_bh(&arm_state->susp_res_lock); - vchiq_log_warning(vchiq_susp_log_level, - "-- Videcore suspend state: %s --", - suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]); - vchiq_log_warning(vchiq_susp_log_level, - "-- Videcore resume state: %s --", - resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]); - if (only_nonzero) vchiq_log_warning(vchiq_susp_log_level, "Too many active " "services (%d). Only dumping up to first %d services " @@ -3093,8 +2639,6 @@ vchiq_dump_service_use_state(struct vchiq_state *state) "--- Overall vchiq instance use count %d", vc_use_count); kfree(service_data); - - vchiq_dump_platform_use_state(state); } enum vchiq_status @@ -3118,24 +2662,16 @@ vchiq_check_service(struct vchiq_service *service) if (ret == VCHIQ_ERROR) { vchiq_log_error(vchiq_susp_log_level, "%s ERROR - %c%c%c%c:%d service count %d, " - "state count %d, videocore suspend state %s", __func__, + "state count %d", __func__, VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc), service->client_id, service->service_use_count, - arm_state->videocore_use_count, - suspend_state_names[arm_state->vc_suspend_state + - VC_SUSPEND_NUM_OFFSET]); + arm_state->videocore_use_count); vchiq_dump_service_use_state(service->state); } out: return ret; } -/* stub functions */ -void vchiq_on_remote_use_active(struct vchiq_state *state) -{ - (void)state; -} - void vchiq_platform_conn_state_changed(struct vchiq_state *state, enum vchiq_connstate oldstate, enum vchiq_connstate newstate) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h index 19d2a2eefb6a..0784c5002417 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h @@ -14,27 +14,8 @@ #include "vchiq_core.h" #include "vchiq_debugfs.h" -enum vc_suspend_status { - VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */ - VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */ - VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */ - VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */ - VC_SUSPEND_REQUESTED, /* User has requested suspend */ - VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */ - VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */ -}; - -enum vc_resume_status { - VC_RESUME_FAILED = -1, /* Videocore resume failed */ - VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */ - VC_RESUME_REQUESTED, /* User has requested resume */ - VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */ - VC_RESUME_RESUMED /* Videocore resumed successfully (active) */ -}; - enum USE_TYPE_E { USE_TYPE_SERVICE, - USE_TYPE_SERVICE_NO_RESUME, USE_TYPE_VCHIQ }; @@ -46,19 +27,9 @@ struct vchiq_arm_state { atomic_t ka_use_ack_count; atomic_t ka_release_count; - struct completion vc_suspend_complete; - struct completion vc_resume_complete; - rwlock_t susp_res_lock; - enum vc_suspend_status vc_suspend_state; - enum vc_resume_status vc_resume_state; - - unsigned int wake_address; struct vchiq_state *state; - struct timer_list suspend_timer; - int suspend_timer_timeout; - int suspend_timer_running; /* Global use count for videocore. ** This is equal to the sum of the use counts for all services. When @@ -72,27 +43,11 @@ struct vchiq_arm_state { */ int peer_use_count; - /* Flag to indicate whether resume is blocked. This happens when the - ** ARM is suspending - */ - struct completion resume_blocker; - int resume_blocked; - struct completion blocked_blocker; - int blocked_count; - - int autosuspend_override; - /* Flag to indicate that the first vchiq connect has made it through. ** This means that both sides should be fully ready, and we should ** be able to suspend after this point. */ int first_connect; - - unsigned long long suspend_start_time; - unsigned long long sleep_start_time; - unsigned long long resume_start_time; - unsigned long long last_wake_time; - }; struct vchiq_drvdata { @@ -110,18 +65,9 @@ extern struct vchiq_state * vchiq_get_state(void); extern enum vchiq_status -vchiq_arm_vcsuspend(struct vchiq_state *state); - -extern enum vchiq_status -vchiq_arm_vcresume(struct vchiq_state *state); - -extern enum vchiq_status vchiq_arm_init_state(struct vchiq_state *state, struct vchiq_arm_state *arm_state); -extern int -vchiq_check_resume(struct vchiq_state *state); - extern void vchiq_check_suspend(struct vchiq_state *state); enum vchiq_status @@ -133,15 +79,6 @@ vchiq_release_service(unsigned int handle); extern enum vchiq_status vchiq_check_service(struct vchiq_service *service); -extern enum vchiq_status -vchiq_platform_suspend(struct vchiq_state *state); - -extern int -vchiq_platform_videocore_wanted(struct vchiq_state *state); - -extern int -vchiq_platform_use_suspend_timer(void); - extern void vchiq_dump_platform_use_state(struct vchiq_state *state); @@ -151,8 +88,6 @@ vchiq_dump_service_use_state(struct vchiq_state *state); extern struct vchiq_arm_state* vchiq_platform_get_arm_state(struct vchiq_state *state); -extern int -vchiq_videocore_wanted(struct vchiq_state *state); extern enum vchiq_status vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service, @@ -176,15 +111,4 @@ vchiq_instance_get_trace(struct vchiq_instance *instance); extern void vchiq_instance_set_trace(struct vchiq_instance *instance, int trace); -extern void -set_suspend_state(struct vchiq_arm_state *arm_state, - enum vc_suspend_status new_state); - -extern void -set_resume_state(struct vchiq_arm_state *arm_state, - enum vc_resume_status new_state); - -extern void -start_suspend_timer(struct vchiq_arm_state *arm_state); - #endif /* VCHIQ_ARM_H */ diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c index 76351078affb..edcd97373809 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */ +#include <linux/kref.h> +#include <linux/rcupdate.h> + #include "vchiq_core.h" #define VCHIQ_SLOT_HANDLER_STACK 8192 @@ -54,7 +57,6 @@ int vchiq_core_log_level = VCHIQ_LOG_DEFAULT; int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT; int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT; -static DEFINE_SPINLOCK(service_spinlock); DEFINE_SPINLOCK(bulk_waiter_spinlock); static DEFINE_SPINLOCK(quota_spinlock); @@ -136,44 +138,41 @@ find_service_by_handle(unsigned int handle) { struct vchiq_service *service; - spin_lock(&service_spinlock); + rcu_read_lock(); service = handle_to_service(handle); - if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) && - (service->handle == handle)) { - WARN_ON(service->ref_count == 0); - service->ref_count++; - } else - service = NULL; - spin_unlock(&service_spinlock); - - if (!service) - vchiq_log_info(vchiq_core_log_level, - "Invalid service handle 0x%x", handle); - - return service; + if (service && service->srvstate != VCHIQ_SRVSTATE_FREE && + service->handle == handle && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); + return service; + } + rcu_read_unlock(); + vchiq_log_info(vchiq_core_log_level, + "Invalid service handle 0x%x", handle); + return NULL; } struct vchiq_service * find_service_by_port(struct vchiq_state *state, int localport) { - struct vchiq_service *service = NULL; if ((unsigned int)localport <= VCHIQ_PORT_MAX) { - spin_lock(&service_spinlock); - service = state->services[localport]; - if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) { - WARN_ON(service->ref_count == 0); - service->ref_count++; - } else - service = NULL; - spin_unlock(&service_spinlock); - } - - if (!service) - vchiq_log_info(vchiq_core_log_level, - "Invalid port %d", localport); + struct vchiq_service *service; - return service; + rcu_read_lock(); + service = rcu_dereference(state->services[localport]); + if (service && service->srvstate != VCHIQ_SRVSTATE_FREE && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); + return service; + } + rcu_read_unlock(); + } + vchiq_log_info(vchiq_core_log_level, + "Invalid port %d", localport); + return NULL; } struct vchiq_service * @@ -182,22 +181,20 @@ find_service_for_instance(struct vchiq_instance *instance, { struct vchiq_service *service; - spin_lock(&service_spinlock); + rcu_read_lock(); service = handle_to_service(handle); - if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) && - (service->handle == handle) && - (service->instance == instance)) { - WARN_ON(service->ref_count == 0); - service->ref_count++; - } else - service = NULL; - spin_unlock(&service_spinlock); - - if (!service) - vchiq_log_info(vchiq_core_log_level, - "Invalid service handle 0x%x", handle); - - return service; + if (service && service->srvstate != VCHIQ_SRVSTATE_FREE && + service->handle == handle && + service->instance == instance && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); + return service; + } + rcu_read_unlock(); + vchiq_log_info(vchiq_core_log_level, + "Invalid service handle 0x%x", handle); + return NULL; } struct vchiq_service * @@ -206,121 +203,125 @@ find_closed_service_for_instance(struct vchiq_instance *instance, { struct vchiq_service *service; - spin_lock(&service_spinlock); + rcu_read_lock(); service = handle_to_service(handle); if (service && - ((service->srvstate == VCHIQ_SRVSTATE_FREE) || - (service->srvstate == VCHIQ_SRVSTATE_CLOSED)) && - (service->handle == handle) && - (service->instance == instance)) { - WARN_ON(service->ref_count == 0); - service->ref_count++; - } else - service = NULL; - spin_unlock(&service_spinlock); - - if (!service) - vchiq_log_info(vchiq_core_log_level, - "Invalid service handle 0x%x", handle); - + (service->srvstate == VCHIQ_SRVSTATE_FREE || + service->srvstate == VCHIQ_SRVSTATE_CLOSED) && + service->handle == handle && + service->instance == instance && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); + return service; + } + rcu_read_unlock(); + vchiq_log_info(vchiq_core_log_level, + "Invalid service handle 0x%x", handle); return service; } struct vchiq_service * -next_service_by_instance(struct vchiq_state *state, struct vchiq_instance *instance, - int *pidx) +__next_service_by_instance(struct vchiq_state *state, + struct vchiq_instance *instance, + int *pidx) { struct vchiq_service *service = NULL; int idx = *pidx; - spin_lock(&service_spinlock); while (idx < state->unused_service) { - struct vchiq_service *srv = state->services[idx++]; + struct vchiq_service *srv; - if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) && - (srv->instance == instance)) { + srv = rcu_dereference(state->services[idx++]); + if (srv && srv->srvstate != VCHIQ_SRVSTATE_FREE && + srv->instance == instance) { service = srv; - WARN_ON(service->ref_count == 0); - service->ref_count++; break; } } - spin_unlock(&service_spinlock); *pidx = idx; + return service; +} + +struct vchiq_service * +next_service_by_instance(struct vchiq_state *state, + struct vchiq_instance *instance, + int *pidx) +{ + struct vchiq_service *service; + rcu_read_lock(); + while (1) { + service = __next_service_by_instance(state, instance, pidx); + if (!service) + break; + if (kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + break; + } + } + rcu_read_unlock(); return service; } void lock_service(struct vchiq_service *service) { - spin_lock(&service_spinlock); - WARN_ON(!service); - if (service) { - WARN_ON(service->ref_count == 0); - service->ref_count++; + if (!service) { + WARN(1, "%s service is NULL\n", __func__); + return; } - spin_unlock(&service_spinlock); + kref_get(&service->ref_count); +} + +static void service_release(struct kref *kref) +{ + struct vchiq_service *service = + container_of(kref, struct vchiq_service, ref_count); + struct vchiq_state *state = service->state; + + WARN_ON(service->srvstate != VCHIQ_SRVSTATE_FREE); + rcu_assign_pointer(state->services[service->localport], NULL); + if (service->userdata_term) + service->userdata_term(service->base.userdata); + kfree_rcu(service, rcu); } void unlock_service(struct vchiq_service *service) { - spin_lock(&service_spinlock); if (!service) { WARN(1, "%s: service is NULL\n", __func__); - goto unlock; - } - if (!service->ref_count) { - WARN(1, "%s: ref_count is zero\n", __func__); - goto unlock; - } - service->ref_count--; - if (!service->ref_count) { - struct vchiq_state *state = service->state; - - WARN_ON(service->srvstate != VCHIQ_SRVSTATE_FREE); - state->services[service->localport] = NULL; - } else { - service = NULL; + return; } -unlock: - spin_unlock(&service_spinlock); - - if (service && service->userdata_term) - service->userdata_term(service->base.userdata); - - kfree(service); + kref_put(&service->ref_count, service_release); } int vchiq_get_client_id(unsigned int handle) { - struct vchiq_service *service = find_service_by_handle(handle); + struct vchiq_service *service; int id; + rcu_read_lock(); + service = handle_to_service(handle); id = service ? service->client_id : 0; - if (service) - unlock_service(service); - + rcu_read_unlock(); return id; } void * vchiq_get_service_userdata(unsigned int handle) { - struct vchiq_service *service = handle_to_service(handle); - - return service ? service->base.userdata : NULL; -} - -int -vchiq_get_service_fourcc(unsigned int handle) -{ - struct vchiq_service *service = handle_to_service(handle); + void *userdata; + struct vchiq_service *service; - return service ? service->base.fourcc : 0; + rcu_read_lock(); + service = handle_to_service(handle); + userdata = service ? service->base.userdata : NULL; + rcu_read_unlock(); + return userdata; } static void @@ -468,19 +469,23 @@ get_listening_service(struct vchiq_state *state, int fourcc) WARN_ON(fourcc == VCHIQ_FOURCC_INVALID); + rcu_read_lock(); for (i = 0; i < state->unused_service; i++) { - struct vchiq_service *service = state->services[i]; + struct vchiq_service *service; + service = rcu_dereference(state->services[i]); if (service && - (service->public_fourcc == fourcc) && - ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) || - ((service->srvstate == VCHIQ_SRVSTATE_OPEN) && - (service->remoteport == VCHIQ_PORT_FREE)))) { - lock_service(service); + service->public_fourcc == fourcc && + (service->srvstate == VCHIQ_SRVSTATE_LISTENING || + (service->srvstate == VCHIQ_SRVSTATE_OPEN && + service->remoteport == VCHIQ_PORT_FREE)) && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); return service; } } - + rcu_read_unlock(); return NULL; } @@ -490,15 +495,20 @@ get_connected_service(struct vchiq_state *state, unsigned int port) { int i; + rcu_read_lock(); for (i = 0; i < state->unused_service; i++) { - struct vchiq_service *service = state->services[i]; - - if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN) - && (service->remoteport == port)) { - lock_service(service); + struct vchiq_service *service = + rcu_dereference(state->services[i]); + + if (service && service->srvstate == VCHIQ_SRVSTATE_OPEN && + service->remoteport == port && + kref_get_unless_zero(&service->ref_count)) { + service = rcu_pointer_handoff(service); + rcu_read_unlock(); return service; } } + rcu_read_unlock(); return NULL; } @@ -1798,7 +1808,6 @@ parse_rx_slots(struct vchiq_state *state) } /* At this point slot_mutex is held */ vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED); - vchiq_platform_paused(state); break; case VCHIQ_MSG_RESUME: vchiq_log_trace(vchiq_core_log_level, @@ -1807,7 +1816,6 @@ parse_rx_slots(struct vchiq_state *state) /* Release the slot mutex */ mutex_unlock(&state->slot_mutex); vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED); - vchiq_platform_resumed(state); break; case VCHIQ_MSG_REMOTE_USE: @@ -1817,7 +1825,6 @@ parse_rx_slots(struct vchiq_state *state) vchiq_on_remote_release(state); break; case VCHIQ_MSG_REMOTE_USE_ACTIVE: - vchiq_on_remote_use_active(state); break; default: @@ -1869,9 +1876,6 @@ slot_handler_func(void *v) DEBUG_TRACE(SLOT_HANDLER_LINE); if (state->poll_needed) { - /* Check if we need to suspend - may change our - * conn_state */ - vchiq_platform_check_suspend(state); state->poll_needed = 0; @@ -1897,10 +1901,6 @@ slot_handler_func(void *v) } break; - case VCHIQ_CONNSTATE_PAUSED: - vchiq_platform_resume(state); - break; - case VCHIQ_CONNSTATE_RESUMING: if (queue_message(state, NULL, VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0), @@ -1908,7 +1908,6 @@ slot_handler_func(void *v) != VCHIQ_RETRY) { vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED); - vchiq_platform_resumed(state); } else { /* This should really be impossible, ** since the PAUSE should have flushed @@ -1918,11 +1917,6 @@ slot_handler_func(void *v) "message"); } break; - - case VCHIQ_CONNSTATE_PAUSE_TIMEOUT: - case VCHIQ_CONNSTATE_RESUME_TIMEOUT: - vchiq_platform_handle_timeout(state); - break; default: break; } @@ -2284,7 +2278,7 @@ vchiq_add_service_internal(struct vchiq_state *state, vchiq_userdata_term userdata_term) { struct vchiq_service *service; - struct vchiq_service **pservice = NULL; + struct vchiq_service __rcu **pservice = NULL; struct vchiq_service_quota *service_quota; int i; @@ -2296,7 +2290,7 @@ vchiq_add_service_internal(struct vchiq_state *state, service->base.callback = params->callback; service->base.userdata = params->userdata; service->handle = VCHIQ_SERVICE_HANDLE_INVALID; - service->ref_count = 1; + kref_init(&service->ref_count); service->srvstate = VCHIQ_SRVSTATE_FREE; service->userdata_term = userdata_term; service->localport = VCHIQ_PORT_FREE; @@ -2322,7 +2316,7 @@ vchiq_add_service_internal(struct vchiq_state *state, mutex_init(&service->bulk_mutex); memset(&service->stats, 0, sizeof(service->stats)); - /* Although it is perfectly possible to use service_spinlock + /* Although it is perfectly possible to use a spinlock ** to protect the creation of services, it is overkill as it ** disables interrupts while the array is searched. ** The only danger is of another thread trying to create a @@ -2340,17 +2334,17 @@ vchiq_add_service_internal(struct vchiq_state *state, if (srvstate == VCHIQ_SRVSTATE_OPENING) { for (i = 0; i < state->unused_service; i++) { - struct vchiq_service *srv = state->services[i]; - - if (!srv) { + if (!rcu_access_pointer(state->services[i])) { pservice = &state->services[i]; break; } } } else { + rcu_read_lock(); for (i = (state->unused_service - 1); i >= 0; i--) { - struct vchiq_service *srv = state->services[i]; + struct vchiq_service *srv; + srv = rcu_dereference(state->services[i]); if (!srv) pservice = &state->services[i]; else if ((srv->public_fourcc == params->fourcc) @@ -2363,6 +2357,7 @@ vchiq_add_service_internal(struct vchiq_state *state, break; } } + rcu_read_unlock(); } if (pservice) { @@ -2374,7 +2369,7 @@ vchiq_add_service_internal(struct vchiq_state *state, (state->id * VCHIQ_MAX_SERVICES) | service->localport; handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES; - *pservice = service; + rcu_assign_pointer(*pservice, service); if (pservice == &state->services[state->unused_service]) state->unused_service++; } @@ -2437,13 +2432,13 @@ vchiq_open_service_internal(struct vchiq_service *service, int client_id) status = VCHIQ_RETRY; vchiq_release_service_internal(service); } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) && - (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) { + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) { if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) vchiq_log_error(vchiq_core_log_level, - "%d: osi - srvstate = %s (ref %d)", - service->state->id, - srvstate_names[service->srvstate], - service->ref_count); + "%d: osi - srvstate = %s (ref %u)", + service->state->id, + srvstate_names[service->srvstate], + kref_read(&service->ref_count)); status = VCHIQ_ERROR; VCHIQ_SERVICE_STATS_INC(service, error_count); vchiq_release_service_internal(service); @@ -3449,10 +3444,13 @@ int vchiq_dump_service_state(void *dump_context, struct vchiq_service *service) char buf[80]; int len; int err; + unsigned int ref_count; + /*Don't include the lock just taken*/ + ref_count = kref_read(&service->ref_count) - 1; len = scnprintf(buf, sizeof(buf), "Service %u: %s (ref %u)", - service->localport, srvstate_names[service->srvstate], - service->ref_count - 1); /*Don't include the lock just taken*/ + service->localport, srvstate_names[service->srvstate], + ref_count); if (service->srvstate != VCHIQ_SRVSTATE_FREE) { char remoteport[30]; diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h index c31f953a9986..cedd8e721aae 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -7,6 +7,8 @@ #include <linux/mutex.h> #include <linux/completion.h> #include <linux/kthread.h> +#include <linux/kref.h> +#include <linux/rcupdate.h> #include <linux/wait.h> #include "vchiq_cfg.h" @@ -251,7 +253,8 @@ struct vchiq_slot_info { struct vchiq_service { struct vchiq_service_base base; unsigned int handle; - unsigned int ref_count; + struct kref ref_count; + struct rcu_head rcu; int srvstate; vchiq_userdata_term userdata_term; unsigned int localport; @@ -464,7 +467,7 @@ struct vchiq_state { int error_count; } stats; - struct vchiq_service *services[VCHIQ_MAX_SERVICES]; + struct vchiq_service __rcu *services[VCHIQ_MAX_SERVICES]; struct vchiq_service_quota service_quotas[VCHIQ_MAX_SERVICES]; struct vchiq_slot_info slot_info[VCHIQ_MAX_SLOTS]; @@ -545,12 +548,13 @@ request_poll(struct vchiq_state *state, struct vchiq_service *service, static inline struct vchiq_service * handle_to_service(unsigned int handle) { + int idx = handle & (VCHIQ_MAX_SERVICES - 1); struct vchiq_state *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) & (VCHIQ_MAX_STATES - 1)]; + if (!state) return NULL; - - return state->services[handle & (VCHIQ_MAX_SERVICES - 1)]; + return rcu_dereference(state->services[idx]); } extern struct vchiq_service * @@ -568,7 +572,13 @@ find_closed_service_for_instance(struct vchiq_instance *instance, unsigned int handle); extern struct vchiq_service * -next_service_by_instance(struct vchiq_state *state, struct vchiq_instance *instance, +__next_service_by_instance(struct vchiq_state *state, + struct vchiq_instance *instance, + int *pidx); + +extern struct vchiq_service * +next_service_by_instance(struct vchiq_state *state, + struct vchiq_instance *instance, int *pidx); extern void @@ -590,18 +600,6 @@ vchiq_complete_bulk(struct vchiq_bulk *bulk); extern void remote_event_signal(struct remote_event *event); -void -vchiq_platform_check_suspend(struct vchiq_state *state); - -extern void -vchiq_platform_paused(struct vchiq_state *state); - -extern enum vchiq_status -vchiq_platform_resume(struct vchiq_state *state); - -extern void -vchiq_platform_resumed(struct vchiq_state *state); - extern int vchiq_dump(void *dump_context, const char *str, int len); @@ -648,9 +646,6 @@ vchiq_platform_conn_state_changed(struct vchiq_state *state, enum vchiq_connstate newstate); extern void -vchiq_platform_handle_timeout(struct vchiq_state *state); - -extern void vchiq_set_conn_state(struct vchiq_state *state, enum vchiq_connstate newstate); extern void diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h index 07c6a3db5ab6..39b77ea19210 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h @@ -13,7 +13,6 @@ #define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \ (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3)) #define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service) -#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service) enum vchiq_reason { VCHIQ_SERVICE_OPENED, /* service, -, - */ @@ -128,7 +127,6 @@ extern enum vchiq_status vchiq_bulk_receive_handle(unsigned int service, enum vchiq_bulk_mode mode); extern int vchiq_get_client_id(unsigned int service); extern void *vchiq_get_service_userdata(unsigned int service); -extern int vchiq_get_service_fourcc(unsigned int service); extern void vchiq_get_config(struct vchiq_config *config); extern enum vchiq_status vchiq_set_service_option(unsigned int service, enum vchiq_service_option option, int value); diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h index 25867cb9d13d..337266add6b2 100644 --- a/drivers/staging/vt6655/card.h +++ b/drivers/staging/vt6655/card.h @@ -63,6 +63,6 @@ bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type); bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate, u64 qwBSSTimestamp); bool CARDbSetBeaconPeriod(struct vnt_private *priv, - unsigned short wBeaconInterval); + unsigned short wBeaconInterval); #endif /* __CARD_H__ */ diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c index f69fc687d4c3..5c86cc60eb5c 100644 --- a/drivers/staging/vt6655/device_main.c +++ b/drivers/staging/vt6655/device_main.c @@ -133,7 +133,8 @@ static int device_init_td1_ring(struct vnt_private *priv); static int device_rx_srv(struct vnt_private *priv, unsigned int idx); static int device_tx_srv(struct vnt_private *priv, unsigned int idx); static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *); -static void device_free_rx_buf(struct vnt_private *priv, struct vnt_rx_desc *rd); +static void device_free_rx_buf(struct vnt_private *priv, + struct vnt_rx_desc *rd); static void device_init_registers(struct vnt_private *priv); static void device_free_tx_buf(struct vnt_private *, struct vnt_tx_desc *); static void device_free_td0_ring(struct vnt_private *priv); @@ -442,7 +443,10 @@ static bool device_init_rings(struct vnt_private *priv) /*allocate all RD/TD rings a single pool*/ vir_pool = dma_alloc_coherent(&priv->pcid->dev, - priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc) + priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc) + priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc) + priv->opts.tx_descs[1] * sizeof(struct vnt_tx_desc), + priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc) + + priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc) + + priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc) + + priv->opts.tx_descs[1] * sizeof(struct vnt_tx_desc), &priv->pool_dma, GFP_ATOMIC); if (!vir_pool) { dev_err(&priv->pcid->dev, "allocate desc dma memory failed\n"); diff --git a/drivers/staging/vt6655/power.c b/drivers/staging/vt6655/power.c index bfd598a93b04..6b0407694e54 100644 --- a/drivers/staging/vt6655/power.c +++ b/drivers/staging/vt6655/power.c @@ -58,14 +58,11 @@ void PSvEnablePowerSaving(struct vnt_private *priv, if (priv->op_mode != NL80211_IFTYPE_ADHOC) { /* set AID */ VNSvOutPortW(priv->PortOffset + MAC_REG_AIDATIM, wAID); - } else { - /* set ATIM Window */ -#if 0 /* TODO atim window */ - MACvWriteATIMW(priv->PortOffset, pMgmt->wCurrATIMWindow); -#endif } + /* Set AutoSleep */ MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); + /* Set HWUTSF */ MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); @@ -101,10 +98,13 @@ void PSvDisablePowerSaving(struct vnt_private *priv) { /* disable power saving hw function */ MACbPSWakeup(priv); + /* clear AutoSleep */ MACvRegBitsOff(priv->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); + /* clear HWUTSF */ MACvRegBitsOff(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF); + /* set always listen beacon */ MACvRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); diff --git a/drivers/staging/vt6656/Makefile b/drivers/staging/vt6656/Makefile index b64c0d87f612..375f54e9f58b 100644 --- a/drivers/staging/vt6656/Makefile +++ b/drivers/staging/vt6656/Makefile @@ -9,13 +9,11 @@ vt6656_stage-y += main_usb.o \ baseband.o \ wcmd.o\ rxtx.o \ - dpc.o \ power.o \ key.o \ rf.o \ usbpipe.o \ channel.o \ - firmware.o \ - int.o + firmware.o obj-$(CONFIG_VT6656) += vt6656_stage.o diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c index f18e059ce66b..a19a563d8bcc 100644 --- a/drivers/staging/vt6656/baseband.c +++ b/drivers/staging/vt6656/baseband.c @@ -22,6 +22,8 @@ * */ +#include <linux/bits.h> +#include <linux/kernel.h> #include "mac.h" #include "baseband.h" #include "rf.h" @@ -132,7 +134,6 @@ unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, { unsigned int frame_time; unsigned int preamble; - unsigned int tmp; unsigned int rate = 0; if (tx_rate > RATE_54M) @@ -146,20 +147,11 @@ unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type, else preamble = 192; - frame_time = (frame_length * 80) / rate; - tmp = (frame_time * rate) / 80; - - if (frame_length != tmp) - frame_time++; - + frame_time = DIV_ROUND_UP(frame_length * 80, rate); return preamble + frame_time; } - frame_time = (frame_length * 8 + 22) / rate; - tmp = ((frame_time * rate) - 22) / 8; - - if (frame_length != tmp) - frame_time++; + frame_time = DIV_ROUND_UP(frame_length * 8 + 22, rate); frame_time = frame_time * 4; if (pkt_type != PK_TYPE_11A) @@ -213,11 +205,7 @@ void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length, break; case RATE_5M: - count = (bit_count * 10) / 55; - tmp = (count * 55) / 10; - - if (tmp != bit_count) - count++; + count = DIV_ROUND_UP(bit_count * 10, 55); if (preamble_type == 1) phy->signal = 0x0a; @@ -367,9 +355,6 @@ int vnt_vt3184_init(struct vnt_private *priv) int ret = 0; u16 length; u8 *addr; - u8 *agc; - u16 length_agc; - u8 array[256]; u8 data; ret = vnt_control_in(priv, MESSAGE_TYPE_READ, 0, MESSAGE_REQUEST_EEPROM, @@ -386,8 +371,6 @@ int vnt_vt3184_init(struct vnt_private *priv) priv->bb_rx_conf = vnt_vt3184_al2230[10]; length = sizeof(vnt_vt3184_al2230); addr = vnt_vt3184_al2230; - agc = vnt_vt3184_agc; - length_agc = sizeof(vnt_vt3184_agc); priv->bb_vga[0] = 0x1C; priv->bb_vga[1] = 0x10; @@ -398,8 +381,6 @@ int vnt_vt3184_init(struct vnt_private *priv) priv->bb_rx_conf = vnt_vt3184_al2230[10]; length = sizeof(vnt_vt3184_al2230); addr = vnt_vt3184_al2230; - agc = vnt_vt3184_agc; - length_agc = sizeof(vnt_vt3184_agc); addr[0xd7] = 0x06; @@ -413,8 +394,6 @@ int vnt_vt3184_init(struct vnt_private *priv) priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; length = sizeof(vnt_vt3184_vt3226d0); addr = vnt_vt3184_vt3226d0; - agc = vnt_vt3184_agc; - length_agc = sizeof(vnt_vt3184_agc); priv->bb_vga[0] = 0x20; priv->bb_vga[1] = 0x10; @@ -430,8 +409,6 @@ int vnt_vt3184_init(struct vnt_private *priv) priv->bb_rx_conf = vnt_vt3184_vt3226d0[10]; length = sizeof(vnt_vt3184_vt3226d0); addr = vnt_vt3184_vt3226d0; - agc = vnt_vt3184_agc; - length_agc = sizeof(vnt_vt3184_agc); priv->bb_vga[0] = 0x20; priv->bb_vga[1] = 0x10; @@ -447,17 +424,14 @@ int vnt_vt3184_init(struct vnt_private *priv) goto end; } - memcpy(array, addr, length); - ret = vnt_control_out_blocks(priv, VNT_REG_BLOCK_SIZE, - MESSAGE_REQUEST_BBREG, length, array); + MESSAGE_REQUEST_BBREG, length, addr); if (ret) goto end; - memcpy(array, agc, length_agc); - ret = vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, - MESSAGE_REQUEST_BBAGC, length_agc, array); + MESSAGE_REQUEST_BBAGC, + sizeof(vnt_vt3184_agc), vnt_vt3184_agc); if (ret) goto end; @@ -468,7 +442,7 @@ int vnt_vt3184_init(struct vnt_private *priv) if (ret) goto end; - ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01); + ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, BIT(0)); if (ret) goto end; } else if (priv->rf_type == RF_VT3226D0) { @@ -477,7 +451,7 @@ int vnt_vt3184_init(struct vnt_private *priv) if (ret) goto end; - ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01); + ret = vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, BIT(0)); if (ret) goto end; } diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c index 7958fc165462..dc3ab10eb630 100644 --- a/drivers/staging/vt6656/card.c +++ b/drivers/staging/vt6656/card.c @@ -26,6 +26,7 @@ * */ +#include <linux/bits.h> #include "device.h" #include "card.h" #include "baseband.h" @@ -63,7 +64,8 @@ void vnt_set_channel(struct vnt_private *priv, u32 connection_channel) vnt_mac_reg_bits_on(priv, MAC_REG_MACCR, MACCR_CLRNAV); /* Set Channel[7] = 0 to tell H/W channel is changing now. */ - vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, 0xb0); + vnt_mac_reg_bits_off(priv, MAC_REG_CHANNEL, + (BIT(7) | BIT(5) | BIT(4))); vnt_control_out(priv, MESSAGE_TYPE_SELECT_CHANNEL, connection_channel, 0, 0, NULL); diff --git a/drivers/staging/vt6656/desc.h b/drivers/staging/vt6656/desc.h index 3a83a9ea9a2a..703597a911f4 100644 --- a/drivers/staging/vt6656/desc.h +++ b/drivers/staging/vt6656/desc.h @@ -18,6 +18,7 @@ #ifndef __DESC_H__ #define __DESC_H__ +#include <linux/bits.h> #include <linux/types.h> #include <linux/mm.h> @@ -36,32 +37,32 @@ /* * bits in the RSR register */ -#define RSR_ADDRBROAD 0x80 -#define RSR_ADDRMULTI 0x40 +#define RSR_ADDRBROAD BIT(7) +#define RSR_ADDRMULTI BIT(6) #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 +#define RSR_IVLDTYP BIT(5) /* invalid packet type */ +#define RSR_IVLDLEN BIT(4) /* invalid len (> 2312 byte) */ +#define RSR_BSSIDOK BIT(3) +#define RSR_CRCOK BIT(2) +#define RSR_BCNSSIDOK BIT(1) +#define RSR_ADDROK BIT(0) /* * 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 +#define NEWRSR_DECRYPTOK BIT(4) +#define NEWRSR_CFPIND BIT(3) +#define NEWRSR_HWUTSF BIT(2) +#define NEWRSR_BCNHITAID BIT(1) +#define NEWRSR_BCNHITAID0 BIT(0) /* * bits in the TSR register */ -#define TSR_RETRYTMO 0x08 -#define TSR_TMO 0x04 -#define TSR_ACKDATA 0x02 -#define TSR_VALID 0x01 +#define TSR_RETRYTMO BIT(3) +#define TSR_TMO BIT(2) +#define TSR_ACKDATA BIT(1) +#define TSR_VALID BIT(0) #define FIFOCTL_AUTO_FB_1 0x1000 #define FIFOCTL_AUTO_FB_0 0x0800 diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h index fe6c11266123..e6ee9411f080 100644 --- a/drivers/staging/vt6656/device.h +++ b/drivers/staging/vt6656/device.h @@ -16,6 +16,7 @@ #ifndef __DEVICE_H__ #define __DEVICE_H__ +#include <linux/bits.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/slab.h> @@ -129,12 +130,12 @@ #define EEP_OFS_OFDMA_PWR_TBL 0x50 /* Bits in EEP_OFS_ANTENNA */ -#define EEP_ANTENNA_MAIN 0x1 -#define EEP_ANTENNA_AUX 0x2 -#define EEP_ANTINV 0x4 +#define EEP_ANTENNA_MAIN BIT(0) +#define EEP_ANTENNA_AUX BIT(1) +#define EEP_ANTINV BIT(2) /* Bits in EEP_OFS_RADIOCTL */ -#define EEP_RADIOCTL_ENABLE 0x80 +#define EEP_RADIOCTL_ENABLE BIT(7) /* control commands */ #define MESSAGE_TYPE_READ 0x1 @@ -227,7 +228,6 @@ struct vnt_rcb { void *priv; struct urb *urb; struct sk_buff *skb; - int in_use; }; /* used to track bulk out irps */ @@ -244,7 +244,6 @@ struct vnt_usb_send_context { u8 pkt_no; u8 pkt_type; u8 need_ack; - u8 fb_option; bool in_use; unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS]; }; @@ -254,16 +253,6 @@ struct vnt_usb_send_context { */ struct vnt_interrupt_buffer { u8 *data_buf; - bool in_use; -}; - -/*++ NDIS related */ - -enum { - STATUS_SUCCESS = 0, - STATUS_FAILURE, - STATUS_RESOURCES, - STATUS_PENDING, }; /* flags for options */ diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c deleted file mode 100644 index a0b60e7d1086..000000000000 --- a/drivers/staging/vt6656/dpc.c +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: dpc.c - * - * Purpose: handle dpc rx functions - * - * Author: Lyndon Chen - * - * Date: May 20, 2003 - * - * Functions: - * - * Revision History: - * - */ - -#include "dpc.h" -#include "device.h" -#include "mac.h" -#include "baseband.h" -#include "rf.h" - -int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb, - unsigned long bytes_received) -{ - struct ieee80211_hw *hw = priv->hw; - struct ieee80211_supported_band *sband; - struct sk_buff *skb; - struct ieee80211_rx_status *rx_status; - struct vnt_rx_header *head; - struct vnt_rx_tail *tail; - u32 frame_size; - int ii; - u16 rx_bitrate, pay_load_with_padding; - u8 rate_idx = 0; - long rx_dbm; - - skb = ptr_rcb->skb; - rx_status = IEEE80211_SKB_RXCB(skb); - - /* [31:16]RcvByteCount ( not include 4-byte Status ) */ - head = (struct vnt_rx_header *)skb->data; - frame_size = head->wbk_status >> 16; - frame_size += 4; - - if (bytes_received != frame_size) { - dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n"); - return false; - } - - if ((bytes_received > 2372) || (bytes_received <= 40)) { - /* Frame Size error drop this packet.*/ - dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n"); - return false; - } - - /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */ - /* -8TSF - 4RSR - 4SQ3 - ?Padding */ - - /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */ - - /*Fix hardware bug => PLCP_Length error */ - if (((bytes_received - head->pay_load_len) > 27) || - ((bytes_received - head->pay_load_len) < 24) || - (bytes_received < head->pay_load_len)) { - dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n", - head->pay_load_len); - return false; - } - - sband = hw->wiphy->bands[hw->conf.chandef.chan->band]; - rx_bitrate = head->rx_rate * 5; /* rx_rate * 5 */ - - for (ii = 0; ii < sband->n_bitrates; ii++) { - if (sband->bitrates[ii].bitrate == rx_bitrate) { - rate_idx = ii; - break; - } - } - - if (ii == sband->n_bitrates) { - dev_dbg(&priv->usb->dev, "Wrong Rx Bit Rate %d\n", rx_bitrate); - return false; - } - - pay_load_with_padding = ((head->pay_load_len / 4) + - ((head->pay_load_len % 4) ? 1 : 0)) * 4; - - tail = (struct vnt_rx_tail *)(skb->data + - sizeof(*head) + pay_load_with_padding); - priv->tsf_time = le64_to_cpu(tail->tsf_time); - - if (tail->rsr & (RSR_IVLDTYP | RSR_IVLDLEN)) - return false; - - vnt_rf_rssi_to_dbm(priv, tail->rssi, &rx_dbm); - - priv->bb_pre_ed_rssi = (u8)-rx_dbm + 1; - priv->current_rssi = priv->bb_pre_ed_rssi; - - skb_pull(skb, sizeof(*head)); - skb_trim(skb, head->pay_load_len); - - rx_status->mactime = priv->tsf_time; - rx_status->band = hw->conf.chandef.chan->band; - rx_status->signal = rx_dbm; - rx_status->flag = 0; - rx_status->freq = hw->conf.chandef.chan->center_freq; - - if (!(tail->rsr & RSR_CRCOK)) - rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; - - rx_status->rate_idx = rate_idx; - - if (tail->new_rsr & NEWRSR_DECRYPTOK) - rx_status->flag |= RX_FLAG_DECRYPTED; - - ieee80211_rx_irqsafe(priv->hw, skb); - - return true; -} diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h deleted file mode 100644 index e080add823cb..000000000000 --- a/drivers/staging/vt6656/dpc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: dpc.h - * - * Purpose: - * - * Author: Jerry Chen - * - * Date: Jun. 27, 2002 - * - */ - -#ifndef __DPC_H__ -#define __DPC_H__ - -#include "device.h" - -int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb, - unsigned long bytes_received); - -#endif /* __RXTX_H__ */ diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c deleted file mode 100644 index af215860be4c..000000000000 --- a/drivers/staging/vt6656/int.c +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: int.c - * - * Purpose: Handle USB interrupt endpoint - * - * Author: Jerry Chen - * - * Date: Apr. 2, 2004 - * - * Functions: - * - * Revision History: - * 04-02-2004 Jerry Chen: Initial release - * - */ - -#include "int.h" -#include "mac.h" -#include "power.h" -#include "usbpipe.h" - -static const u8 fallback_rate0[5][5] = { - {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M}, - {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M}, - {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M}, - {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M}, - {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M} -}; - -static const u8 fallback_rate1[5][5] = { - {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M}, - {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M}, - {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M}, - {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M}, - {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M} -}; - -int vnt_int_start_interrupt(struct vnt_private *priv) -{ - int ret = 0; - unsigned long flags; - - dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n"); - - spin_lock_irqsave(&priv->lock, flags); - - ret = vnt_start_interrupt_urb(priv); - - spin_unlock_irqrestore(&priv->lock, flags); - - return ret; -} - -static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr) -{ - struct vnt_usb_send_context *context; - struct ieee80211_tx_info *info; - struct ieee80211_rate *rate; - u8 tx_retry = (tsr & 0xf0) >> 4; - s8 idx; - - if (pkt_no >= priv->num_tx_context) - return -EINVAL; - - context = priv->tx_context[pkt_no]; - - if (!context->skb) - return -EINVAL; - - info = IEEE80211_SKB_CB(context->skb); - idx = info->control.rates[0].idx; - - if (context->fb_option && !(tsr & (TSR_TMO | TSR_RETRYTMO))) { - u8 tx_rate; - u8 retry = tx_retry; - - rate = ieee80211_get_tx_rate(priv->hw, info); - tx_rate = rate->hw_value - RATE_18M; - - if (retry > 4) - retry = 4; - - if (context->fb_option == AUTO_FB_0) - tx_rate = fallback_rate0[tx_rate][retry]; - else if (context->fb_option == AUTO_FB_1) - tx_rate = fallback_rate1[tx_rate][retry]; - - if (info->band == NL80211_BAND_5GHZ) - idx = tx_rate - RATE_6M; - else - idx = tx_rate; - } - - ieee80211_tx_info_clear_status(info); - - info->status.rates[0].count = tx_retry; - - if (!(tsr & TSR_TMO)) { - info->status.rates[0].idx = idx; - - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) - info->flags |= IEEE80211_TX_STAT_ACK; - } - - ieee80211_tx_status_irqsafe(priv->hw, context->skb); - - context->in_use = false; - - return 0; -} - -void vnt_int_process_data(struct vnt_private *priv) -{ - struct vnt_interrupt_data *int_data; - struct ieee80211_low_level_stats *low_stats = &priv->low_stats; - - dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n"); - - int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf; - - if (int_data->tsr0 & TSR_VALID) - vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0); - - if (int_data->tsr1 & TSR_VALID) - vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1); - - if (int_data->tsr2 & TSR_VALID) - vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2); - - if (int_data->tsr3 & TSR_VALID) - vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3); - - if (int_data->isr0 != 0) { - if (int_data->isr0 & ISR_BNTX && - priv->op_mode == NL80211_IFTYPE_AP) - vnt_schedule_command(priv, WLAN_CMD_BECON_SEND); - - if (int_data->isr0 & ISR_TBTT && - priv->hw->conf.flags & IEEE80211_CONF_PS) { - if (!priv->wake_up_count) - priv->wake_up_count = - priv->hw->conf.listen_interval; - - --priv->wake_up_count; - - /* Turn on wake up to listen next beacon */ - if (priv->wake_up_count == 1) - vnt_schedule_command(priv, - WLAN_CMD_TBTT_WAKEUP); - } - priv->current_tsf = le64_to_cpu(int_data->tsf); - - low_stats->dot11RTSSuccessCount += int_data->rts_success; - low_stats->dot11RTSFailureCount += int_data->rts_fail; - low_stats->dot11ACKFailureCount += int_data->ack_fail; - low_stats->dot11FCSErrorCount += int_data->fcs_err; - } - - priv->int_buf.in_use = false; -} diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h deleted file mode 100644 index 8a6d60569ceb..000000000000 --- a/drivers/staging/vt6656/int.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. - * All rights reserved. - * - * File: int.h - * - * Purpose: - * - * Author: Jerry Chen - * - * Date: Apr. 2, 2004 - * - */ - -#ifndef __INT_H__ -#define __INT_H__ - -#include "device.h" - -struct vnt_interrupt_data { - u8 tsr0; - u8 pkt0; - u16 time0; - u8 tsr1; - u8 pkt1; - u16 time1; - u8 tsr2; - u8 pkt2; - u16 time2; - u8 tsr3; - u8 pkt3; - u16 time3; - __le64 tsf; - u8 isr0; - u8 isr1; - u8 rts_success; - u8 rts_fail; - u8 ack_fail; - u8 fcs_err; - u8 sw[2]; -} __packed; - -int vnt_int_start_interrupt(struct vnt_private *priv); -void vnt_int_process_data(struct vnt_private *priv); - -#endif /* __INT_H__ */ diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c index dcd933a6b66e..41b73f9670e2 100644 --- a/drivers/staging/vt6656/key.c +++ b/drivers/staging/vt6656/key.c @@ -144,11 +144,14 @@ int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, break; case WLAN_CIPHER_SUITE_CCMP: if (priv->local_id <= MAC_REVISION_A1) - return -EINVAL; + return -EOPNOTSUPP; key_dec_mode = KEY_CTL_CCMP; key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; + break; + default: + return -EOPNOTSUPP; } if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h index 0a42308b81e9..c532b27de37f 100644 --- a/drivers/staging/vt6656/mac.h +++ b/drivers/staging/vt6656/mac.h @@ -20,6 +20,7 @@ #ifndef __MAC_H__ #define __MAC_H__ +#include <linux/bits.h> #include "device.h" #define REV_ID_VT3253_A0 0x00 @@ -142,109 +143,109 @@ #define MAC_REG_RSPINF_A_72 0xfc /* Bits in the I2MCFG EEPROM register */ -#define I2MCFG_BOUNDCTL 0x80 -#define I2MCFG_WAITCTL 0x20 -#define I2MCFG_SCLOECTL 0x10 -#define I2MCFG_WBUSYCTL 0x08 -#define I2MCFG_NORETRY 0x04 -#define I2MCFG_I2MLDSEQ 0x02 -#define I2MCFG_I2CMFAST 0x01 +#define I2MCFG_BOUNDCTL BIT(7) +#define I2MCFG_WAITCTL BIT(5) +#define I2MCFG_SCLOECTL BIT(4) +#define I2MCFG_WBUSYCTL BIT(3) +#define I2MCFG_NORETRY BIT(2) +#define I2MCFG_I2MLDSEQ BIT(1) +#define I2MCFG_I2CMFAST BIT(0) /* Bits in the I2MCSR EEPROM register */ -#define I2MCSR_EEMW 0x80 -#define I2MCSR_EEMR 0x40 -#define I2MCSR_AUTOLD 0x08 -#define I2MCSR_NACK 0x02 -#define I2MCSR_DONE 0x01 +#define I2MCSR_EEMW BIT(7) +#define I2MCSR_EEMR BIT(6) +#define I2MCSR_AUTOLD BIT(3) +#define I2MCSR_NACK BIT(1) +#define I2MCSR_DONE BIT(0) /* Bits in the TMCTL register */ -#define TMCTL_TSUSP 0x04 -#define TMCTL_TMD 0x02 -#define TMCTL_TE 0x01 +#define TMCTL_TSUSP BIT(2) +#define TMCTL_TMD BIT(1) +#define TMCTL_TE BIT(0) /* Bits in the TFTCTL register */ -#define TFTCTL_HWUTSF 0x80 -#define TFTCTL_TBTTSYNC 0x40 -#define TFTCTL_HWUTSFEN 0x20 -#define TFTCTL_TSFCNTRRD 0x10 -#define TFTCTL_TBTTSYNCEN 0x08 -#define TFTCTL_TSFSYNCEN 0x04 -#define TFTCTL_TSFCNTRST 0x02 -#define TFTCTL_TSFCNTREN 0x01 +#define TFTCTL_HWUTSF BIT(7) +#define TFTCTL_TBTTSYNC BIT(6) +#define TFTCTL_HWUTSFEN BIT(5) +#define TFTCTL_TSFCNTRRD BIT(4) +#define TFTCTL_TBTTSYNCEN BIT(3) +#define TFTCTL_TSFSYNCEN BIT(2) +#define TFTCTL_TSFCNTRST BIT(1) +#define TFTCTL_TSFCNTREN BIT(0) /* Bits in the EnhanceCFG_0 register */ #define EnCFG_BBType_a 0x00 -#define EnCFG_BBType_b 0x01 -#define EnCFG_BBType_g 0x02 -#define EnCFG_BBType_MASK 0x03 -#define EnCFG_ProtectMd 0x20 +#define EnCFG_BBType_b BIT(0) +#define EnCFG_BBType_g BIT(1) +#define EnCFG_BBType_MASK (BIT(0) | BIT(1)) +#define EnCFG_ProtectMd BIT(5) /* Bits in the EnhanceCFG_1 register */ -#define EnCFG_BcnSusInd 0x01 -#define EnCFG_BcnSusClr 0x02 +#define EnCFG_BcnSusInd BIT(0) +#define EnCFG_BcnSusClr BIT(1) /* Bits in the EnhanceCFG_2 register */ -#define EnCFG_NXTBTTCFPSTR 0x01 -#define EnCFG_BarkerPream 0x02 -#define EnCFG_PktBurstMode 0x04 +#define EnCFG_NXTBTTCFPSTR BIT(0) +#define EnCFG_BarkerPream BIT(1) +#define EnCFG_PktBurstMode BIT(2) /* Bits in the CFG register */ -#define CFG_TKIPOPT 0x80 -#define CFG_RXDMAOPT 0x40 -#define CFG_TMOT_SW 0x20 -#define CFG_TMOT_HWLONG 0x10 +#define CFG_TKIPOPT BIT(7) +#define CFG_RXDMAOPT BIT(6) +#define CFG_TMOT_SW BIT(5) +#define CFG_TMOT_HWLONG BIT(4) #define CFG_TMOT_HW 0x00 -#define CFG_CFPENDOPT 0x08 -#define CFG_BCNSUSEN 0x04 -#define CFG_NOTXTIMEOUT 0x02 -#define CFG_NOBUFOPT 0x01 +#define CFG_CFPENDOPT BIT(3) +#define CFG_BCNSUSEN BIT(2) +#define CFG_NOTXTIMEOUT BIT(1) +#define CFG_NOBUFOPT BIT(0) /* Bits in the TEST register */ -#define TEST_LBEXT 0x80 -#define TEST_LBINT 0x40 +#define TEST_LBEXT BIT(7) +#define TEST_LBINT BIT(6) #define TEST_LBNONE 0x00 -#define TEST_SOFTINT 0x20 -#define TEST_CONTTX 0x10 -#define TEST_TXPE 0x08 -#define TEST_NAVDIS 0x04 -#define TEST_NOCTS 0x02 -#define TEST_NOACK 0x01 +#define TEST_SOFTINT BIT(5) +#define TEST_CONTTX BIT(4) +#define TEST_TXPE BIT(3) +#define TEST_NAVDIS BIT(2) +#define TEST_NOCTS BIT(1) +#define TEST_NOACK BIT(0) /* Bits in the HOSTCR register */ -#define HOSTCR_TXONST 0x80 -#define HOSTCR_RXONST 0x40 -#define HOSTCR_ADHOC 0x20 -#define HOSTCR_AP 0x10 -#define HOSTCR_TXON 0x08 -#define HOSTCR_RXON 0x04 -#define HOSTCR_MACEN 0x02 -#define HOSTCR_SOFTRST 0x01 +#define HOSTCR_TXONST BIT(7) +#define HOSTCR_RXONST BIT(6) +#define HOSTCR_ADHOC BIT(5) +#define HOSTCR_AP BIT(4) +#define HOSTCR_TXON BIT(3) +#define HOSTCR_RXON BIT(2) +#define HOSTCR_MACEN BIT(1) +#define HOSTCR_SOFTRST BIT(0) /* Bits in the MACCR register */ -#define MACCR_SYNCFLUSHOK 0x04 -#define MACCR_SYNCFLUSH 0x02 -#define MACCR_CLRNAV 0x01 +#define MACCR_SYNCFLUSHOK BIT(2) +#define MACCR_SYNCFLUSH BIT(1) +#define MACCR_CLRNAV BIT(0) /* Bits in the RCR register */ -#define RCR_SSID 0x80 -#define RCR_RXALLTYPE 0x40 -#define RCR_UNICAST 0x20 -#define RCR_BROADCAST 0x10 -#define RCR_MULTICAST 0x08 -#define RCR_WPAERR 0x04 -#define RCR_ERRCRC 0x02 -#define RCR_BSSID 0x01 +#define RCR_SSID BIT(7) +#define RCR_RXALLTYPE BIT(6) +#define RCR_UNICAST BIT(5) +#define RCR_BROADCAST BIT(4) +#define RCR_MULTICAST BIT(3) +#define RCR_WPAERR BIT(2) +#define RCR_ERRCRC BIT(1) +#define RCR_BSSID BIT(0) /* Bits in the TCR register */ -#define TCR_SYNCDCFOPT 0x02 -#define TCR_AUTOBCNTX 0x01 +#define TCR_SYNCDCFOPT BIT(1) +#define TCR_AUTOBCNTX BIT(0) /* ISR1 */ -#define ISR_GPIO3 0x40 -#define ISR_RXNOBUF 0x08 -#define ISR_MIBNEARFULL 0x04 -#define ISR_SOFTINT 0x02 -#define ISR_FETALERR 0x01 +#define ISR_GPIO3 BIT(6) +#define ISR_RXNOBUF BIT(3) +#define ISR_MIBNEARFULL BIT(2) +#define ISR_SOFTINT BIT(1) +#define ISR_FETALERR BIT(0) #define LEDSTS_STS 0x06 #define LEDSTS_TMLEN 0x78 @@ -254,85 +255,85 @@ #define LEDSTS_INTER 0x06 /* ISR0 */ -#define ISR_WATCHDOG 0x80 -#define ISR_SOFTTIMER 0x40 -#define ISR_GPIO0 0x20 -#define ISR_TBTT 0x10 -#define ISR_RXDMA0 0x08 -#define ISR_BNTX 0x04 -#define ISR_ACTX 0x01 +#define ISR_WATCHDOG BIT(7) +#define ISR_SOFTTIMER BIT(6) +#define ISR_GPIO0 BIT(5) +#define ISR_TBTT BIT(4) +#define ISR_RXDMA0 BIT(3) +#define ISR_BNTX BIT(2) +#define ISR_ACTX BIT(0) /* Bits in the PSCFG register */ -#define PSCFG_PHILIPMD 0x40 -#define PSCFG_WAKECALEN 0x20 -#define PSCFG_WAKETMREN 0x10 -#define PSCFG_BBPSPROG 0x08 -#define PSCFG_WAKESYN 0x04 -#define PSCFG_SLEEPSYN 0x02 -#define PSCFG_AUTOSLEEP 0x01 +#define PSCFG_PHILIPMD BIT(6) +#define PSCFG_WAKECALEN BIT(5) +#define PSCFG_WAKETMREN BIT(4) +#define PSCFG_BBPSPROG BIT(3) +#define PSCFG_WAKESYN BIT(2) +#define PSCFG_SLEEPSYN BIT(1) +#define PSCFG_AUTOSLEEP BIT(0) /* Bits in the PSCTL register */ -#define PSCTL_WAKEDONE 0x20 -#define PSCTL_PS 0x10 -#define PSCTL_GO2DOZE 0x08 -#define PSCTL_LNBCN 0x04 -#define PSCTL_ALBCN 0x02 -#define PSCTL_PSEN 0x01 +#define PSCTL_WAKEDONE BIT(5) +#define PSCTL_PS BIT(4) +#define PSCTL_GO2DOZE BIT(3) +#define PSCTL_LNBCN BIT(2) +#define PSCTL_ALBCN BIT(1) +#define PSCTL_PSEN BIT(0) /* Bits in the PSPWSIG register */ -#define PSSIG_WPE3 0x80 -#define PSSIG_WPE2 0x40 -#define PSSIG_WPE1 0x20 -#define PSSIG_WRADIOPE 0x10 -#define PSSIG_SPE3 0x08 -#define PSSIG_SPE2 0x04 -#define PSSIG_SPE1 0x02 -#define PSSIG_SRADIOPE 0x01 +#define PSSIG_WPE3 BIT(7) +#define PSSIG_WPE2 BIT(6) +#define PSSIG_WPE1 BIT(5) +#define PSSIG_WRADIOPE BIT(4) +#define PSSIG_SPE3 BIT(3) +#define PSSIG_SPE2 BIT(2) +#define PSSIG_SPE1 BIT(1) +#define PSSIG_SRADIOPE BIT(0) /* Bits in the BBREGCTL register */ -#define BBREGCTL_DONE 0x04 -#define BBREGCTL_REGR 0x02 -#define BBREGCTL_REGW 0x01 +#define BBREGCTL_DONE BIT(2) +#define BBREGCTL_REGR BIT(1) +#define BBREGCTL_REGW BIT(0) /* Bits in the IFREGCTL register */ -#define IFREGCTL_DONE 0x04 -#define IFREGCTL_IFRF 0x02 -#define IFREGCTL_REGW 0x01 +#define IFREGCTL_DONE BIT(2) +#define IFREGCTL_IFRF BIT(1) +#define IFREGCTL_REGW BIT(0) /* Bits in the SOFTPWRCTL register */ -#define SOFTPWRCTL_RFLEOPT 0x08 -#define SOFTPWRCTL_TXPEINV 0x02 -#define SOFTPWRCTL_SWPECTI 0x01 -#define SOFTPWRCTL_SWPAPE 0x20 -#define SOFTPWRCTL_SWCALEN 0x10 -#define SOFTPWRCTL_SWRADIO_PE 0x08 -#define SOFTPWRCTL_SWPE2 0x04 -#define SOFTPWRCTL_SWPE1 0x02 -#define SOFTPWRCTL_SWPE3 0x01 +#define SOFTPWRCTL_RFLEOPT BIT(3) +#define SOFTPWRCTL_TXPEINV BIT(1) +#define SOFTPWRCTL_SWPECTI BIT(0) +#define SOFTPWRCTL_SWPAPE BIT(5) +#define SOFTPWRCTL_SWCALEN BIT(4) +#define SOFTPWRCTL_SWRADIO_PE BIT(3) +#define SOFTPWRCTL_SWPE2 BIT(2) +#define SOFTPWRCTL_SWPE1 BIT(1) +#define SOFTPWRCTL_SWPE3 BIT(0) /* Bits in the GPIOCTL1 register */ -#define GPIO3_MD 0x20 -#define GPIO3_DATA 0x40 -#define GPIO3_INTMD 0x80 +#define GPIO3_MD BIT(5) +#define GPIO3_DATA BIT(6) +#define GPIO3_INTMD BIT(7) /* Bits in the MISCFFCTL register */ -#define MISCFFCTL_WRITE 0x0001 +#define MISCFFCTL_WRITE BIT(0) /* Loopback mode */ -#define MAC_LB_EXT 0x02 -#define MAC_LB_INTERNAL 0x01 +#define MAC_LB_EXT BIT(1) +#define MAC_LB_INTERNAL BIT(0) #define MAC_LB_NONE 0x00 /* Ethernet address filter type */ #define PKT_TYPE_NONE 0x00 /* turn off receiver */ -#define PKT_TYPE_ALL_MULTICAST 0x80 -#define PKT_TYPE_PROMISCUOUS 0x40 -#define PKT_TYPE_DIRECTED 0x20 /* obselete */ -#define PKT_TYPE_BROADCAST 0x10 -#define PKT_TYPE_MULTICAST 0x08 -#define PKT_TYPE_ERROR_WPA 0x04 -#define PKT_TYPE_ERROR_CRC 0x02 -#define PKT_TYPE_BSSID 0x01 +#define PKT_TYPE_ALL_MULTICAST BIT(7) +#define PKT_TYPE_PROMISCUOUS BIT(6) +#define PKT_TYPE_DIRECTED BIT(5) /* obselete */ +#define PKT_TYPE_BROADCAST BIT(4) +#define PKT_TYPE_MULTICAST BIT(3) +#define PKT_TYPE_ERROR_WPA BIT(2) +#define PKT_TYPE_ERROR_CRC BIT(1) +#define PKT_TYPE_BSSID BIT(0) #define Default_BI 0x200 diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c index 5e48b3ddb94c..8e7269c87ea9 100644 --- a/drivers/staging/vt6656/main_usb.c +++ b/drivers/staging/vt6656/main_usb.c @@ -21,8 +21,10 @@ */ #undef __NO_VERSION__ +#include <linux/bits.h> #include <linux/etherdevice.h> #include <linux/file.h> +#include <linux/kernel.h> #include "device.h" #include "card.h" #include "baseband.h" @@ -30,12 +32,10 @@ #include "power.h" #include "wcmd.h" #include "rxtx.h" -#include "dpc.h" #include "rf.h" #include "firmware.h" #include "usbpipe.h" #include "channel.h" -#include "int.h" /* * define module options @@ -99,7 +99,6 @@ static void vnt_set_options(struct vnt_private *priv) priv->op_mode = NL80211_IFTYPE_UNSPECIFIED; priv->bb_type = BBP_TYPE_DEF; priv->packet_type = priv->bb_type; - priv->auto_fb_ctrl = AUTO_FB_0; priv->preamble_type = 0; priv->exist_sw_net_addr = false; } @@ -109,7 +108,7 @@ static void vnt_set_options(struct vnt_private *priv) */ static int vnt_init_registers(struct vnt_private *priv) { - int ret = 0; + int ret; struct vnt_cmd_card_init *init_cmd = &priv->init_command; struct vnt_rsp_card_init *init_rsp = &priv->init_response; u8 antenna; @@ -145,7 +144,7 @@ static int vnt_init_registers(struct vnt_private *priv) init_cmd->init_class = DEVICE_INIT_COLD; init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr; - for (ii = 0; ii < 6; ii++) + for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++) init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii]; init_cmd->short_retry_limit = priv->short_retry_limit; init_cmd->long_retry_limit = priv->long_retry_limit; @@ -184,7 +183,7 @@ static int vnt_init_registers(struct vnt_private *priv) priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK]; priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG]; /* load power table */ - for (ii = 0; ii < 14; ii++) { + for (ii = 0; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) { priv->cck_pwr_tbl[ii] = priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL]; if (priv->cck_pwr_tbl[ii] == 0) @@ -200,7 +199,7 @@ static int vnt_init_registers(struct vnt_private *priv) * original zonetype is USA, but custom zonetype is Europe, * then need to recover 12, 13, 14 channels with 11 channel */ - for (ii = 11; ii < 14; ii++) { + for (ii = 11; ii < ARRAY_SIZE(priv->cck_pwr_tbl); ii++) { priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10]; priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10]; } @@ -261,9 +260,6 @@ static int vnt_init_registers(struct vnt_private *priv) if (ret) goto end; - /* get Auto Fall Back type */ - priv->auto_fb_ctrl = AUTO_FB_0; - /* default Auto Mode */ priv->bb_type = BB_TYPE_11G; @@ -370,7 +366,7 @@ static int vnt_init_registers(struct vnt_private *priv) if (ret) goto end; - ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01); + ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, BIT(0)); if (ret) goto end; @@ -435,7 +431,7 @@ static void vnt_free_int_bufs(struct vnt_private *priv) static int vnt_alloc_bufs(struct vnt_private *priv) { - int ret = 0; + int ret; struct vnt_usb_send_context *tx_context; struct vnt_rcb *rcb; int ii; @@ -484,9 +480,6 @@ static int vnt_alloc_bufs(struct vnt_private *priv) ret = -ENOMEM; goto free_rx_tx; } - - rcb->in_use = false; - /* submit rx urb */ ret = vnt_submit_rx_urb(priv, rcb); if (ret) @@ -528,7 +521,7 @@ static void vnt_tx_80211(struct ieee80211_hw *hw, static int vnt_start(struct ieee80211_hw *hw) { - int ret = 0; + int ret; struct vnt_private *priv = hw->priv; priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; @@ -553,7 +546,7 @@ static int vnt_start(struct ieee80211_hw *hw) priv->int_interval = 1; /* bInterval is set to 1 */ - ret = vnt_int_start_interrupt(priv); + ret = vnt_start_interrupt_urb(priv); if (ret) goto free_all; @@ -798,12 +791,11 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw, struct vnt_private *priv = hw->priv; struct netdev_hw_addr *ha; u64 mc_filter = 0; - u32 bit_nr = 0; + u32 bit_nr; netdev_hw_addr_list_for_each(ha, mc_list) { bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; - - mc_filter |= 1ULL << (bit_nr & 0x3f); + mc_filter |= BIT_ULL(bit_nr); } priv->mc_list_count = mc_list->count; @@ -862,9 +854,7 @@ static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, switch (cmd) { case SET_KEY: - if (vnt_set_keys(hw, sta, vif, key)) - return -EOPNOTSUPP; - break; + return vnt_set_keys(hw, sta, vif, key); case DISABLE_KEY: if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) clear_bit(key->hw_key_idx, &priv->key_entry_inuse); @@ -973,7 +963,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id) struct vnt_private *priv; struct ieee80211_hw *hw; struct wiphy *wiphy; - int rc = 0; + int rc; udev = usb_get_dev(interface_to_usbdev(intf)); diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c index 29caba728906..9439d190f431 100644 --- a/drivers/staging/vt6656/rxtx.c +++ b/drivers/staging/vt6656/rxtx.c @@ -13,7 +13,6 @@ * * Functions: * vnt_generate_tx_parameter - Generate tx dma required parameter. - * vnt_get_duration_le - get tx data required duration * vnt_get_rtscts_duration_le- get rtx/cts required duration * vnt_get_rtscts_rsvtime_le- get rts/cts reserved time * vnt_get_rsvtime- get frame reserved time @@ -39,30 +38,12 @@ static const u16 vnt_time_stampoff[2][MAX_RATE] = { {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, }; -static const u16 vnt_fb_opt0[2][5] = { - {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, /* fallback_rate0 */ - {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, /* fallback_rate1 */ -}; - -static const u16 vnt_fb_opt1[2][5] = { - {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */ - {RATE_6M, RATE_6M, RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */ -}; - #define RTSDUR_BB 0 #define RTSDUR_BA 1 #define RTSDUR_AA 2 #define CTSDUR_BA 3 -#define RTSDUR_BA_F0 4 -#define RTSDUR_AA_F0 5 -#define RTSDUR_BA_F1 6 -#define RTSDUR_AA_F1 7 -#define CTSDUR_BA_F0 8 -#define CTSDUR_BA_F1 9 #define DATADUR_B 10 #define DATADUR_A 11 -#define DATADUR_A_F0 12 -#define DATADUR_A_F1 13 static struct vnt_usb_send_context *vnt_get_free_context(struct vnt_private *priv) @@ -184,27 +165,6 @@ static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv, u8 rsv_type, return cpu_to_le16((u16)rrv_time); } -static __le16 vnt_get_duration_le(struct vnt_private *priv, u8 pkt_type, - int need_ack) -{ - u32 ack_time = 0; - - if (need_ack) { - if (pkt_type == PK_TYPE_11B) - ack_time = vnt_get_frame_time(priv->preamble_type, - pkt_type, 14, - priv->top_cck_basic_rate); - else - ack_time = vnt_get_frame_time(priv->preamble_type, - pkt_type, 14, - priv->top_ofdm_basic_rate); - - return cpu_to_le16((u16)(priv->sifs + ack_time)); - } - - return 0; -} - static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context, u8 dur_type, u8 pkt_type, u16 rate) { @@ -216,8 +176,6 @@ static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context, switch (dur_type) { case RTSDUR_BB: case RTSDUR_BA: - case RTSDUR_BA_F0: - case RTSDUR_BA_F1: cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 14, priv->top_cck_basic_rate); dur_time = cts_time + 2 * priv->sifs + @@ -226,8 +184,6 @@ static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context, break; case RTSDUR_AA: - case RTSDUR_AA_F0: - case RTSDUR_AA_F1: cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 14, priv->top_ofdm_basic_rate); dur_time = cts_time + 2 * priv->sifs + @@ -236,8 +192,6 @@ static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context, break; case CTSDUR_BA: - case CTSDUR_BA_F0: - case CTSDUR_BA_F1: dur_time = priv->sifs + vnt_get_rsvtime(priv, pkt_type, frame_length, rate, need_ack); break; @@ -270,7 +224,6 @@ static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, (struct ieee80211_hdr *)tx_context->skb->data; u32 frame_len = tx_context->frame_len; u16 rate = tx_context->tx_rate; - u8 need_ack = tx_context->need_ack; /* Get SignalField,ServiceField,Length */ vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a); @@ -278,16 +231,8 @@ static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, PK_TYPE_11B, &buf->b); /* Get Duration and TimeStamp */ - if (ieee80211_is_nullfunc(hdr->frame_control)) { - buf->duration_a = hdr->duration_id; - buf->duration_b = hdr->duration_id; - } else { - buf->duration_a = vnt_get_duration_le(priv, - tx_context->pkt_type, need_ack); - buf->duration_b = vnt_get_duration_le(priv, - PK_TYPE_11B, need_ack); - } - + buf->duration_a = hdr->duration_id; + buf->duration_b = hdr->duration_id; buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); buf->time_stamp_off_b = vnt_time_stamp_off(priv, priv->top_cck_basic_rate); @@ -297,63 +242,6 @@ static u16 vnt_rxtx_datahead_g(struct vnt_usb_send_context *tx_context, return le16_to_cpu(buf->duration_a); } -static u16 vnt_rxtx_datahead_g_fb(struct vnt_usb_send_context *tx_context, - struct vnt_tx_datahead_g_fb *buf) -{ - struct vnt_private *priv = tx_context->priv; - u32 frame_len = tx_context->frame_len; - u16 rate = tx_context->tx_rate; - u8 need_ack = tx_context->need_ack; - - /* Get SignalField,ServiceField,Length */ - vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->a); - - vnt_get_phy_field(priv, frame_len, priv->top_cck_basic_rate, - PK_TYPE_11B, &buf->b); - - /* Get Duration and TimeStamp */ - buf->duration_a = vnt_get_duration_le(priv, tx_context->pkt_type, - need_ack); - buf->duration_b = vnt_get_duration_le(priv, PK_TYPE_11B, need_ack); - - buf->duration_a_f0 = vnt_get_duration_le(priv, tx_context->pkt_type, - need_ack); - buf->duration_a_f1 = vnt_get_duration_le(priv, tx_context->pkt_type, - need_ack); - - buf->time_stamp_off_a = vnt_time_stamp_off(priv, rate); - buf->time_stamp_off_b = vnt_time_stamp_off(priv, - priv->top_cck_basic_rate); - - tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); - - return le16_to_cpu(buf->duration_a); -} - -static u16 vnt_rxtx_datahead_a_fb(struct vnt_usb_send_context *tx_context, - struct vnt_tx_datahead_a_fb *buf) -{ - struct vnt_private *priv = tx_context->priv; - u16 rate = tx_context->tx_rate; - u8 pkt_type = tx_context->pkt_type; - u8 need_ack = tx_context->need_ack; - u32 frame_len = tx_context->frame_len; - - /* Get SignalField,ServiceField,Length */ - vnt_get_phy_field(priv, frame_len, rate, pkt_type, &buf->a); - /* Get Duration and TimeStampOff */ - buf->duration = vnt_get_duration_le(priv, pkt_type, need_ack); - - buf->duration_f0 = vnt_get_duration_le(priv, pkt_type, need_ack); - buf->duration_f1 = vnt_get_duration_le(priv, pkt_type, need_ack); - - buf->time_stamp_off = vnt_time_stamp_off(priv, rate); - - tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); - - return le16_to_cpu(buf->duration); -} - static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, struct vnt_tx_datahead_ab *buf) { @@ -362,20 +250,13 @@ static u16 vnt_rxtx_datahead_ab(struct vnt_usb_send_context *tx_context, (struct ieee80211_hdr *)tx_context->skb->data; u32 frame_len = tx_context->frame_len; u16 rate = tx_context->tx_rate; - u8 need_ack = tx_context->need_ack; /* Get SignalField,ServiceField,Length */ vnt_get_phy_field(priv, frame_len, rate, tx_context->pkt_type, &buf->ab); /* Get Duration and TimeStampOff */ - if (ieee80211_is_nullfunc(hdr->frame_control)) { - buf->duration = hdr->duration_id; - } else { - buf->duration = vnt_get_duration_le(priv, tx_context->pkt_type, - need_ack); - } - + buf->duration = hdr->duration_id; buf->time_stamp_off = vnt_time_stamp_off(priv, rate); tx_context->tx_hdr_size = vnt_mac_hdr_pos(tx_context, &buf->hdr); @@ -426,50 +307,6 @@ static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context, return vnt_rxtx_datahead_g(tx_context, &buf->data_head); } -static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context, - struct vnt_rts_g_fb *buf) -{ - struct vnt_private *priv = tx_context->priv; - u16 current_rate = tx_context->tx_rate; - u16 rts_frame_len = 20; - - vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, - PK_TYPE_11B, &buf->b); - vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, - tx_context->pkt_type, &buf->a); - - buf->duration_bb = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BB, - PK_TYPE_11B, - priv->top_cck_basic_rate); - buf->duration_aa = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, - tx_context->pkt_type, - current_rate); - buf->duration_ba = vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA, - tx_context->pkt_type, - current_rate); - - buf->rts_duration_ba_f0 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F0, - tx_context->pkt_type, - priv->tx_rate_fb0); - buf->rts_duration_aa_f0 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0, - tx_context->pkt_type, - priv->tx_rate_fb0); - buf->rts_duration_ba_f1 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_BA_F1, - tx_context->pkt_type, - priv->tx_rate_fb1); - buf->rts_duration_aa_f1 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1, - tx_context->pkt_type, - priv->tx_rate_fb1); - - vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration_aa); - - return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head); -} - static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, struct vnt_rts_ab *buf) { @@ -489,71 +326,6 @@ static u16 vnt_rxtx_rts_ab_head(struct vnt_usb_send_context *tx_context, return vnt_rxtx_datahead_ab(tx_context, &buf->data_head); } -static u16 vnt_rxtx_rts_a_fb_head(struct vnt_usb_send_context *tx_context, - struct vnt_rts_a_fb *buf) -{ - struct vnt_private *priv = tx_context->priv; - u16 current_rate = tx_context->tx_rate; - u16 rts_frame_len = 20; - - vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, - tx_context->pkt_type, &buf->a); - - buf->duration = vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA, - tx_context->pkt_type, - current_rate); - - buf->rts_duration_f0 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F0, - tx_context->pkt_type, - priv->tx_rate_fb0); - - buf->rts_duration_f1 = - vnt_get_rtscts_duration_le(tx_context, RTSDUR_AA_F1, - tx_context->pkt_type, - priv->tx_rate_fb1); - - vnt_fill_ieee80211_rts(tx_context, &buf->data, buf->duration); - - return vnt_rxtx_datahead_a_fb(tx_context, &buf->data_head); -} - -static u16 vnt_fill_cts_fb_head(struct vnt_usb_send_context *tx_context, - union vnt_tx_data_head *head) -{ - struct vnt_private *priv = tx_context->priv; - struct vnt_cts_fb *buf = &head->cts_g_fb; - u32 cts_frame_len = 14; - u16 current_rate = tx_context->tx_rate; - - /* Get SignalField,ServiceField,Length */ - vnt_get_phy_field(priv, cts_frame_len, priv->top_cck_basic_rate, - PK_TYPE_11B, &buf->b); - - buf->duration_ba = - vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA, - tx_context->pkt_type, - current_rate); - /* Get CTSDuration_ba_f0 */ - buf->cts_duration_ba_f0 = - vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F0, - tx_context->pkt_type, - priv->tx_rate_fb0); - /* Get CTSDuration_ba_f1 */ - buf->cts_duration_ba_f1 = - vnt_get_rtscts_duration_le(tx_context, CTSDUR_BA_F1, - tx_context->pkt_type, - priv->tx_rate_fb1); - /* Get CTS Frame body */ - buf->data.duration = buf->duration_ba; - buf->data.frame_control = - cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); - - ether_addr_copy(buf->data.ra, priv->current_net_addr); - - return vnt_rxtx_datahead_g_fb(tx_context, &buf->data_head); -} - static u16 vnt_fill_cts_head(struct vnt_usb_send_context *tx_context, union vnt_tx_data_head *head) { @@ -606,9 +378,6 @@ static u16 vnt_rxtx_rts(struct vnt_usb_send_context *tx_context, if (need_mic) head = &tx_head->tx_rts.tx.mic.head; - if (tx_context->fb_option) - return vnt_rxtx_rts_g_fb_head(tx_context, &head->rts_g_fb); - return vnt_rxtx_rts_g_head(tx_context, &head->rts_g); } @@ -633,10 +402,6 @@ static u16 vnt_rxtx_cts(struct vnt_usb_send_context *tx_context, if (need_mic) head = &tx_head->tx_cts.tx.mic.head; - /* Fill CTS */ - if (tx_context->fb_option) - return vnt_fill_cts_fb_head(tx_context, head); - return vnt_fill_cts_head(tx_context, head); } @@ -664,18 +429,9 @@ static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context, buf->rts_rrv_time = vnt_get_rtscts_rsvtime_le(priv, 2, tx_context->pkt_type, frame_len, current_rate); - if (tx_context->fb_option && - tx_context->pkt_type == PK_TYPE_11A) - return vnt_rxtx_rts_a_fb_head(tx_context, - &head->rts_a_fb); - return vnt_rxtx_rts_ab_head(tx_context, &head->rts_ab); } - if (tx_context->pkt_type == PK_TYPE_11A) - return vnt_rxtx_datahead_a_fb(tx_context, - &head->data_head_a_fb); - return vnt_rxtx_datahead_ab(tx_context, &head->data_head_ab); } @@ -792,7 +548,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) struct vnt_usb_send_context *tx_context; unsigned long flags; u16 tx_bytes, tx_header_size, tx_body_size, current_rate, duration_id; - u8 pkt_type, fb_option = AUTO_FB_NONE; + u8 pkt_type; bool need_rts = false; bool need_mic = false; @@ -912,33 +668,6 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) tx_buffer_head->current_rate = cpu_to_le16(current_rate); - /* legacy rates TODO use ieee80211_tx_rate */ - if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) { - if (priv->auto_fb_ctrl == AUTO_FB_0) { - tx_buffer_head->fifo_ctl |= - cpu_to_le16(FIFOCTL_AUTO_FB_0); - - priv->tx_rate_fb0 = - vnt_fb_opt0[FB_RATE0][current_rate - RATE_18M]; - priv->tx_rate_fb1 = - vnt_fb_opt0[FB_RATE1][current_rate - RATE_18M]; - - fb_option = AUTO_FB_0; - } else if (priv->auto_fb_ctrl == AUTO_FB_1) { - tx_buffer_head->fifo_ctl |= - cpu_to_le16(FIFOCTL_AUTO_FB_1); - - priv->tx_rate_fb0 = - vnt_fb_opt1[FB_RATE0][current_rate - RATE_18M]; - priv->tx_rate_fb1 = - vnt_fb_opt1[FB_RATE1][current_rate - RATE_18M]; - - fb_option = AUTO_FB_1; - } - } - - tx_context->fb_option = fb_option; - duration_id = vnt_generate_tx_parameter(tx_context, tx_buffer, &mic_hdr, need_mic, need_rts); @@ -954,8 +683,6 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) memcpy(tx_context->hdr, skb->data, tx_body_size); - hdr->duration_id = cpu_to_le16(duration_id); - if (info->control.hw_key) { tx_key = info->control.hw_key; if (tx_key->keylen > 0) @@ -977,7 +704,7 @@ int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb) spin_lock_irqsave(&priv->lock, flags); - if (vnt_tx_context(priv, tx_context) != STATUS_PENDING) { + if (vnt_tx_context(priv, tx_context)) { spin_unlock_irqrestore(&priv->lock, flags); return -EIO; } @@ -1021,9 +748,7 @@ static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) vnt_get_phy_field(priv, frame_size, current_rate, PK_TYPE_11A, &short_head->ab); - /* Get Duration and TimeStampOff */ - short_head->duration = vnt_get_duration_le(priv, - PK_TYPE_11A, false); + /* Get TimeStampOff */ short_head->time_stamp_off = vnt_time_stamp_off(priv, current_rate); } else { @@ -1034,9 +759,7 @@ static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) vnt_get_phy_field(priv, frame_size, current_rate, PK_TYPE_11B, &short_head->ab); - /* Get Duration and TimeStampOff */ - short_head->duration = vnt_get_duration_le(priv, - PK_TYPE_11B, false); + /* Get TimeStampOff */ short_head->time_stamp_off = vnt_time_stamp_off(priv, current_rate); } @@ -1045,6 +768,9 @@ static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) mgmt_hdr = &beacon_buffer->mgmt_hdr; memcpy(mgmt_hdr, skb->data, skb->len); + /* Get Duration */ + short_head->duration = mgmt_hdr->duration; + /* time stamp always 0 */ mgmt_hdr->u.beacon.timestamp = 0; @@ -1071,7 +797,7 @@ static int vnt_beacon_xmit(struct vnt_private *priv, struct sk_buff *skb) spin_lock_irqsave(&priv->lock, flags); - if (vnt_tx_context(priv, context) != STATUS_PENDING) + if (vnt_tx_context(priv, context)) ieee80211_free_txskb(priv->hw, context->skb); spin_unlock_irqrestore(&priv->lock, flags); diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h index d528607e02bf..0e6226af7d41 100644 --- a/drivers/staging/vt6656/rxtx.h +++ b/drivers/staging/vt6656/rxtx.h @@ -73,18 +73,6 @@ struct vnt_tx_datahead_g { struct ieee80211_hdr hdr; } __packed; -struct vnt_tx_datahead_g_fb { - struct vnt_phy_field b; - struct vnt_phy_field a; - __le16 duration_b; - __le16 duration_a; - __le16 duration_a_f0; - __le16 duration_a_f1; - __le16 time_stamp_off_b; - __le16 time_stamp_off_a; - struct ieee80211_hdr hdr; -} __packed; - struct vnt_tx_datahead_ab { struct vnt_phy_field ab; __le16 duration; @@ -92,15 +80,6 @@ struct vnt_tx_datahead_ab { struct ieee80211_hdr hdr; } __packed; -struct vnt_tx_datahead_a_fb { - struct vnt_phy_field a; - __le16 duration; - __le16 time_stamp_off; - __le16 duration_f0; - __le16 duration_f1; - struct ieee80211_hdr hdr; -} __packed; - /* RTS buffer header */ struct vnt_rts_g { struct vnt_phy_field b; @@ -113,21 +92,6 @@ struct vnt_rts_g { struct vnt_tx_datahead_g data_head; } __packed; -struct vnt_rts_g_fb { - struct vnt_phy_field b; - struct vnt_phy_field a; - __le16 duration_ba; - __le16 duration_aa; - __le16 duration_bb; - u16 wReserved; - __le16 rts_duration_ba_f0; - __le16 rts_duration_aa_f0; - __le16 rts_duration_ba_f1; - __le16 rts_duration_aa_f1; - struct ieee80211_rts data; - struct vnt_tx_datahead_g_fb data_head; -} __packed; - struct vnt_rts_ab { struct vnt_phy_field ab; __le16 duration; @@ -136,16 +100,6 @@ struct vnt_rts_ab { struct vnt_tx_datahead_ab data_head; } __packed; -struct vnt_rts_a_fb { - struct vnt_phy_field a; - __le16 duration; - u16 wReserved; - __le16 rts_duration_f0; - __le16 rts_duration_f1; - struct ieee80211_rts data; - struct vnt_tx_datahead_a_fb data_head; -} __packed; - /* CTS buffer header */ struct vnt_cts { struct vnt_phy_field b; @@ -156,29 +110,14 @@ struct vnt_cts { struct vnt_tx_datahead_g data_head; } __packed; -struct vnt_cts_fb { - struct vnt_phy_field b; - __le16 duration_ba; - u16 wReserved; - __le16 cts_duration_ba_f0; - __le16 cts_duration_ba_f1; - struct ieee80211_cts data; - u16 reserved2; - struct vnt_tx_datahead_g_fb data_head; -} __packed; - union vnt_tx_data_head { /* rts g */ struct vnt_rts_g rts_g; - struct vnt_rts_g_fb rts_g_fb; /* rts a/b */ struct vnt_rts_ab rts_ab; - struct vnt_rts_a_fb rts_a_fb; /* cts g */ struct vnt_cts cts_g; - struct vnt_cts_fb cts_g_fb; /* no rts/cts */ - struct vnt_tx_datahead_a_fb data_head_a_fb; struct vnt_tx_datahead_ab data_head_ab; }; diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c index 7bfccc48a366..eae211e5860f 100644 --- a/drivers/staging/vt6656/usbpipe.c +++ b/drivers/staging/vt6656/usbpipe.c @@ -24,12 +24,12 @@ * */ -#include "int.h" #include "rxtx.h" -#include "dpc.h" #include "desc.h" #include "device.h" #include "usbpipe.h" +#include "mac.h" +#include "rf.h" #define USB_CTL_WAIT 500 /* ms */ @@ -139,6 +139,90 @@ int vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data) reg_off, reg, sizeof(u8), data); } +static int vnt_int_report_rate(struct vnt_private *priv, u8 pkt_no, u8 tsr) +{ + struct vnt_usb_send_context *context; + struct ieee80211_tx_info *info; + u8 tx_retry = (tsr & 0xf0) >> 4; + s8 idx; + + if (pkt_no >= priv->num_tx_context) + return -EINVAL; + + context = priv->tx_context[pkt_no]; + + if (!context->skb) + return -EINVAL; + + info = IEEE80211_SKB_CB(context->skb); + idx = info->control.rates[0].idx; + + ieee80211_tx_info_clear_status(info); + + info->status.rates[0].count = tx_retry; + + if (!(tsr & TSR_TMO)) { + info->status.rates[0].idx = idx; + + if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) + info->flags |= IEEE80211_TX_STAT_ACK; + } + + ieee80211_tx_status_irqsafe(priv->hw, context->skb); + + context->in_use = false; + + return 0; +} + +static void vnt_int_process_data(struct vnt_private *priv) +{ + struct vnt_interrupt_data *int_data; + struct ieee80211_low_level_stats *low_stats = &priv->low_stats; + + dev_dbg(&priv->usb->dev, "---->s_nsInterruptProcessData\n"); + + int_data = (struct vnt_interrupt_data *)priv->int_buf.data_buf; + + if (int_data->tsr0 & TSR_VALID) + vnt_int_report_rate(priv, int_data->pkt0, int_data->tsr0); + + if (int_data->tsr1 & TSR_VALID) + vnt_int_report_rate(priv, int_data->pkt1, int_data->tsr1); + + if (int_data->tsr2 & TSR_VALID) + vnt_int_report_rate(priv, int_data->pkt2, int_data->tsr2); + + if (int_data->tsr3 & TSR_VALID) + vnt_int_report_rate(priv, int_data->pkt3, int_data->tsr3); + + if (int_data->isr0 != 0) { + if (int_data->isr0 & ISR_BNTX && + priv->op_mode == NL80211_IFTYPE_AP) + vnt_schedule_command(priv, WLAN_CMD_BECON_SEND); + + if (int_data->isr0 & ISR_TBTT && + priv->hw->conf.flags & IEEE80211_CONF_PS) { + if (!priv->wake_up_count) + priv->wake_up_count = + priv->hw->conf.listen_interval; + + --priv->wake_up_count; + + /* Turn on wake up to listen next beacon */ + if (priv->wake_up_count == 1) + vnt_schedule_command(priv, + WLAN_CMD_TBTT_WAKEUP); + } + priv->current_tsf = le64_to_cpu(int_data->tsf); + + low_stats->dot11RTSSuccessCount += int_data->rts_success; + low_stats->dot11RTSFailureCount += int_data->rts_fail; + low_stats->dot11ACKFailureCount += int_data->ack_fail; + low_stats->dot11FCSErrorCount += int_data->fcs_err; + } +} + static void vnt_start_interrupt_urb_complete(struct urb *urb) { struct vnt_private *priv = urb->context; @@ -151,37 +235,26 @@ static void vnt_start_interrupt_urb_complete(struct urb *urb) case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: - priv->int_buf.in_use = false; return; default: break; } - if (status) { - priv->int_buf.in_use = false; - + if (status) dev_dbg(&priv->usb->dev, "%s status = %d\n", __func__, status); - } else { + else vnt_int_process_data(priv); - } status = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC); if (status) dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", status); - else - priv->int_buf.in_use = true; } int vnt_start_interrupt_urb(struct vnt_private *priv) { int ret = 0; - if (priv->int_buf.in_use) { - ret = -EBUSY; - goto err; - } - - priv->int_buf.in_use = true; + dev_dbg(&priv->usb->dev, "---->Interrupt Polling Thread\n"); usb_fill_int_urb(priv->interrupt_urb, priv->usb, @@ -193,17 +266,110 @@ int vnt_start_interrupt_urb(struct vnt_private *priv) priv->int_interval); ret = usb_submit_urb(priv->interrupt_urb, GFP_ATOMIC); - if (ret) { + if (ret) dev_dbg(&priv->usb->dev, "Submit int URB failed %d\n", ret); - goto err_submit; + + return ret; +} + +static int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb, + unsigned long bytes_received) +{ + struct ieee80211_hw *hw = priv->hw; + struct ieee80211_supported_band *sband; + struct sk_buff *skb; + struct ieee80211_rx_status *rx_status; + struct vnt_rx_header *head; + struct vnt_rx_tail *tail; + u32 frame_size; + int ii; + u16 rx_bitrate, pay_load_with_padding; + u8 rate_idx = 0; + long rx_dbm; + + skb = ptr_rcb->skb; + rx_status = IEEE80211_SKB_RXCB(skb); + + /* [31:16]RcvByteCount ( not include 4-byte Status ) */ + head = (struct vnt_rx_header *)skb->data; + frame_size = head->wbk_status >> 16; + frame_size += 4; + + if (bytes_received != frame_size) { + dev_dbg(&priv->usb->dev, "------- WRONG Length 1\n"); + return false; } - return 0; + if ((bytes_received > 2372) || (bytes_received <= 40)) { + /* Frame Size error drop this packet.*/ + dev_dbg(&priv->usb->dev, "------ WRONG Length 2\n"); + return false; + } -err_submit: - priv->int_buf.in_use = false; -err: - return ret; + /* real Frame Size = USBframe_size -4WbkStatus - 4RxStatus */ + /* -8TSF - 4RSR - 4SQ3 - ?Padding */ + + /* if SQ3 the range is 24~27, if no SQ3 the range is 20~23 */ + + /*Fix hardware bug => PLCP_Length error */ + if (((bytes_received - head->pay_load_len) > 27) || + ((bytes_received - head->pay_load_len) < 24) || + (bytes_received < head->pay_load_len)) { + dev_dbg(&priv->usb->dev, "Wrong PLCP Length %x\n", + head->pay_load_len); + return false; + } + + sband = hw->wiphy->bands[hw->conf.chandef.chan->band]; + rx_bitrate = head->rx_rate * 5; /* rx_rate * 5 */ + + for (ii = 0; ii < sband->n_bitrates; ii++) { + if (sband->bitrates[ii].bitrate == rx_bitrate) { + rate_idx = ii; + break; + } + } + + if (ii == sband->n_bitrates) { + dev_dbg(&priv->usb->dev, "Wrong Rx Bit Rate %d\n", rx_bitrate); + return false; + } + + pay_load_with_padding = ((head->pay_load_len / 4) + + ((head->pay_load_len % 4) ? 1 : 0)) * 4; + + tail = (struct vnt_rx_tail *)(skb->data + + sizeof(*head) + pay_load_with_padding); + priv->tsf_time = le64_to_cpu(tail->tsf_time); + + if (tail->rsr & (RSR_IVLDTYP | RSR_IVLDLEN)) + return false; + + vnt_rf_rssi_to_dbm(priv, tail->rssi, &rx_dbm); + + priv->bb_pre_ed_rssi = (u8)-rx_dbm + 1; + priv->current_rssi = priv->bb_pre_ed_rssi; + + skb_pull(skb, sizeof(*head)); + skb_trim(skb, head->pay_load_len); + + rx_status->mactime = priv->tsf_time; + rx_status->band = hw->conf.chandef.chan->band; + rx_status->signal = rx_dbm; + rx_status->flag = 0; + rx_status->freq = hw->conf.chandef.chan->center_freq; + + if (!(tail->rsr & RSR_CRCOK)) + rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; + + rx_status->rate_idx = rate_idx; + + if (tail->new_rsr & NEWRSR_DECRYPTOK) + rx_status->flag |= RX_FLAG_DECRYPTED; + + ieee80211_rx_irqsafe(priv->hw, skb); + + return true; } static void vnt_submit_rx_urb_complete(struct urb *urb) @@ -227,10 +393,8 @@ static void vnt_submit_rx_urb_complete(struct urb *urb) if (urb->actual_length) { if (vnt_rx_data(priv, rcb, urb->actual_length)) { rcb->skb = dev_alloc_skb(priv->rx_buf_sz); - if (!rcb->skb) { - rcb->in_use = false; + if (!rcb->skb) return; - } } else { skb_push(rcb->skb, skb_headroom(rcb->skb)); skb_trim(rcb->skb, 0); @@ -240,11 +404,8 @@ static void vnt_submit_rx_urb_complete(struct urb *urb) skb_tailroom(rcb->skb)); } - if (usb_submit_urb(urb, GFP_ATOMIC)) { + if (usb_submit_urb(urb, GFP_ATOMIC)) dev_dbg(&priv->usb->dev, "Failed to re submit rx skb\n"); - - rcb->in_use = false; - } } int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb) @@ -267,13 +428,8 @@ int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb) rcb); ret = usb_submit_urb(urb, GFP_ATOMIC); - if (ret) { + if (ret) dev_dbg(&priv->usb->dev, "Submit Rx URB failed %d\n", ret); - goto end; - } - - rcb->in_use = true; - end: return ret; } @@ -317,7 +473,7 @@ int vnt_tx_context(struct vnt_private *priv, if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags)) { context->in_use = false; - return STATUS_RESOURCES; + return -ENODEV; } usb_fill_bulk_urb(urb, @@ -333,8 +489,7 @@ int vnt_tx_context(struct vnt_private *priv, dev_dbg(&priv->usb->dev, "Submit Tx URB failed %d\n", status); context->in_use = false; - return STATUS_FAILURE; } - return STATUS_PENDING; + return status; } diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h index 4e3341bc3221..35697b58d748 100644 --- a/drivers/staging/vt6656/usbpipe.h +++ b/drivers/staging/vt6656/usbpipe.h @@ -18,6 +18,29 @@ #include "device.h" +struct vnt_interrupt_data { + u8 tsr0; + u8 pkt0; + u16 time0; + u8 tsr1; + u8 pkt1; + u16 time1; + u8 tsr2; + u8 pkt2; + u16 time2; + u8 tsr3; + u8 pkt3; + u16 time3; + __le64 tsf; + u8 isr0; + u8 isr1; + u8 rts_success; + u8 rts_fail; + u8 ack_fail; + u8 fcs_err; + u8 sw[2]; +} __packed; + #define VNT_REG_BLOCK_SIZE 64 int vnt_control_out(struct vnt_private *priv, u8 request, u16 value, diff --git a/drivers/staging/wfx/Documentation/devicetree/bindings/net/wireless/siliabs,wfx.txt b/drivers/staging/wfx/Documentation/devicetree/bindings/net/wireless/siliabs,wfx.txt index 081d58abd5ac..17db67559f5e 100644 --- a/drivers/staging/wfx/Documentation/devicetree/bindings/net/wireless/siliabs,wfx.txt +++ b/drivers/staging/wfx/Documentation/devicetree/bindings/net/wireless/siliabs,wfx.txt @@ -6,7 +6,7 @@ SPI You have to declare the WFxxx chip in your device tree. Required properties: - - compatible: Should be "silabs,wfx-spi" + - compatible: Should be "silabs,wf200" - reg: Chip select address of device - spi-max-frequency: Maximum SPI clocking speed of device in Hz - interrupts-extended: Should contain interrupt line (interrupt-parent + @@ -15,6 +15,7 @@ Required properties: Optional properties: - reset-gpios: phandle of gpio that will be used to reset chip during probe. Without this property, you may encounter issues with warm boot. + (Legacy: when compatible == "silabs,wfx-spi", the gpio is inverted.) Please consult Documentation/devicetree/bindings/spi/spi-bus.txt for optional SPI connection related properties, @@ -23,12 +24,12 @@ Example: &spi1 { wfx { - compatible = "silabs,wfx-spi"; + compatible = "silabs,wf200"; pinctrl-names = "default"; pinctrl-0 = <&wfx_irq &wfx_gpios>; interrupts-extended = <&gpio 16 IRQ_TYPE_EDGE_RISING>; wakeup-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>; - reset-gpios = <&gpio 13 GPIO_ACTIVE_HIGH>; + reset-gpios = <&gpio 13 GPIO_ACTIVE_LOW>; reg = <0>; spi-max-frequency = <42000000>; }; @@ -44,7 +45,7 @@ case. Thus declaring WFxxx chip in device tree is strongly recommended (and may become mandatory in the future). Required properties: - - compatible: Should be "silabs,wfx-sdio" + - compatible: Should be "silabs,wf200" - reg: Should be 1 In addition, it is recommended to declare a mmc-pwrseq on SDIO host above WFx. @@ -70,7 +71,7 @@ Example: #size = <0>; mmc@1 { - compatible = "silabs,wfx-sdio"; + compatible = "silabs,wf200"; reg = <1>; pinctrl-names = "default"; pinctrl-0 = <&wfx_wakeup>; diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c index 983c41d1fe7c..9fcab00a3733 100644 --- a/drivers/staging/wfx/bh.c +++ b/drivers/staging/wfx/bh.c @@ -20,13 +20,13 @@ static void device_wakeup(struct wfx_dev *wdev) { if (!wdev->pdata.gpio_wakeup) return; - if (gpiod_get_value(wdev->pdata.gpio_wakeup)) + if (gpiod_get_value_cansleep(wdev->pdata.gpio_wakeup)) return; - gpiod_set_value(wdev->pdata.gpio_wakeup, 1); + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); if (wfx_api_older_than(wdev, 1, 4)) { if (!completion_done(&wdev->hif.ctrl_ready)) - udelay(2000); + usleep_range(2000, 2500); } else { // completion.h does not provide any function to wait // completion without consume it (a kind of @@ -45,7 +45,7 @@ static void device_release(struct wfx_dev *wdev) if (!wdev->pdata.gpio_wakeup) return; - gpiod_set_value(wdev->pdata.gpio_wakeup, 0); + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 0); } static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf) diff --git a/drivers/staging/wfx/bus_sdio.c b/drivers/staging/wfx/bus_sdio.c index f8901164c206..dedc3ff58d3e 100644 --- a/drivers/staging/wfx/bus_sdio.c +++ b/drivers/staging/wfx/bus_sdio.c @@ -200,25 +200,23 @@ static int wfx_sdio_probe(struct sdio_func *func, if (ret) goto err0; - ret = wfx_sdio_irq_subscribe(bus); - if (ret) - goto err1; - bus->core = wfx_init_common(&func->dev, &wfx_sdio_pdata, &wfx_sdio_hwbus_ops, bus); if (!bus->core) { ret = -EIO; - goto err2; + goto err1; } + ret = wfx_sdio_irq_subscribe(bus); + if (ret) + goto err1; + ret = wfx_probe(bus->core); if (ret) - goto err3; + goto err2; return 0; -err3: - wfx_free_common(bus->core); err2: wfx_sdio_irq_unsubscribe(bus); err1: @@ -234,7 +232,6 @@ static void wfx_sdio_remove(struct sdio_func *func) struct wfx_sdio_priv *bus = sdio_get_drvdata(func); wfx_release(bus->core); - wfx_free_common(bus->core); wfx_sdio_irq_unsubscribe(bus); sdio_claim_host(func); sdio_disable_func(func); @@ -254,6 +251,7 @@ MODULE_DEVICE_TABLE(sdio, wfx_sdio_ids); #ifdef CONFIG_OF static const struct of_device_id wfx_sdio_of_match[] = { { .compatible = "silabs,wfx-sdio" }, + { .compatible = "silabs,wf200" }, { }, }; MODULE_DEVICE_TABLE(of, wfx_sdio_of_match); diff --git a/drivers/staging/wfx/bus_spi.c b/drivers/staging/wfx/bus_spi.c index 40bc33035de2..61e99b09decb 100644 --- a/drivers/staging/wfx/bus_spi.c +++ b/drivers/staging/wfx/bus_spi.c @@ -27,6 +27,8 @@ MODULE_PARM_DESC(gpio_reset, "gpio number for reset. -1 for none."); #define SET_WRITE 0x7FFF /* usage: and operation */ #define SET_READ 0x8000 /* usage: or operation */ +#define WFX_RESET_INVERTED 1 + static const struct wfx_platform_data wfx_spi_pdata = { .file_fw = "wfm_wf200", .file_pds = "wf200.pds", @@ -154,6 +156,11 @@ static void wfx_spi_request_rx(struct work_struct *work) wfx_bh_request_rx(bus->core); } +static void wfx_flush_irq_work(void *w) +{ + flush_work(w); +} + static size_t wfx_spi_align_size(void *priv, size_t size) { // Most of SPI controllers avoid DMA if buffer size is not 32bit aligned @@ -201,28 +208,31 @@ static int wfx_spi_probe(struct spi_device *func) if (!bus->gpio_reset) { dev_warn(&func->dev, "try to load firmware anyway\n"); } else { - gpiod_set_value(bus->gpio_reset, 0); - udelay(100); - gpiod_set_value(bus->gpio_reset, 1); - udelay(2000); + if (spi_get_device_id(func)->driver_data & WFX_RESET_INVERTED) + gpiod_toggle_active_low(bus->gpio_reset); + gpiod_set_value_cansleep(bus->gpio_reset, 1); + usleep_range(100, 150); + gpiod_set_value_cansleep(bus->gpio_reset, 0); + usleep_range(2000, 2500); } - ret = devm_request_irq(&func->dev, func->irq, wfx_spi_irq_handler, - IRQF_TRIGGER_RISING, "wfx", bus); - if (ret) - return ret; - INIT_WORK(&bus->request_rx, wfx_spi_request_rx); bus->core = wfx_init_common(&func->dev, &wfx_spi_pdata, &wfx_spi_hwbus_ops, bus); if (!bus->core) return -EIO; - ret = wfx_probe(bus->core); + ret = devm_add_action_or_reset(&func->dev, wfx_flush_irq_work, + &bus->request_rx); if (ret) - wfx_free_common(bus->core); + return ret; - return ret; + ret = devm_request_irq(&func->dev, func->irq, wfx_spi_irq_handler, + IRQF_TRIGGER_RISING, "wfx", bus); + if (ret) + return ret; + + return wfx_probe(bus->core); } static int wfx_spi_remove(struct spi_device *func) @@ -230,11 +240,6 @@ static int wfx_spi_remove(struct spi_device *func) struct wfx_spi_priv *bus = spi_get_drvdata(func); wfx_release(bus->core); - wfx_free_common(bus->core); - // A few IRQ will be sent during device release. Hopefully, no IRQ - // should happen after wdev/wvif are released. - devm_free_irq(&func->dev, func->irq, bus); - flush_work(&bus->request_rx); return 0; } @@ -244,14 +249,16 @@ static int wfx_spi_remove(struct spi_device *func) * stripped. */ static const struct spi_device_id wfx_spi_id[] = { - { "wfx-spi", 0 }, + { "wfx-spi", WFX_RESET_INVERTED }, + { "wf200", 0 }, { }, }; MODULE_DEVICE_TABLE(spi, wfx_spi_id); #ifdef CONFIG_OF static const struct of_device_id wfx_spi_of_match[] = { - { .compatible = "silabs,wfx-spi" }, + { .compatible = "silabs,wfx-spi", .data = (void *)WFX_RESET_INVERTED }, + { .compatible = "silabs,wf200" }, { }, }; MODULE_DEVICE_TABLE(of, wfx_spi_of_match); diff --git a/drivers/staging/wfx/data_rx.c b/drivers/staging/wfx/data_rx.c index 5d198457c6ce..c5b83fedeb55 100644 --- a/drivers/staging/wfx/data_rx.c +++ b/drivers/staging/wfx/data_rx.c @@ -17,7 +17,7 @@ static int wfx_drop_encrypt_data(struct wfx_dev *wdev, const struct hif_ind_rx *arg, struct sk_buff *skb) { - struct ieee80211_hdr *frame = (struct ieee80211_hdr *) skb->data; + struct ieee80211_hdr *frame = (struct ieee80211_hdr *)skb->data; size_t hdrlen = ieee80211_hdrlen(frame->frame_control); size_t iv_len, icv_len; @@ -62,7 +62,6 @@ static int wfx_drop_encrypt_data(struct wfx_dev *wdev, memmove(skb->data + iv_len, skb->data, hdrlen); skb_pull(skb, iv_len); return 0; - } void wfx_rx_cb(struct wfx_vif *wvif, diff --git a/drivers/staging/wfx/data_tx.c b/drivers/staging/wfx/data_tx.c index 20f4740734f2..42183c70d4df 100644 --- a/drivers/staging/wfx/data_tx.c +++ b/drivers/staging/wfx/data_tx.c @@ -227,7 +227,7 @@ static int wfx_tx_policy_upload(struct wfx_vif *wvif) memzcmp(policies[i].rates, sizeof(policies[i].rates))) break; if (i < HIF_MIB_NUM_TX_RATE_RETRY_POLICIES) { - policies[i].uploaded = 1; + policies[i].uploaded = true; memcpy(tmp_rates, policies[i].rates, sizeof(tmp_rates)); spin_unlock_bh(&wvif->tx_policy_cache.lock); hif_set_tx_rate_retry_policy(wvif, i, tmp_rates); @@ -300,11 +300,11 @@ static void wfx_tx_manage_pm(struct wfx_vif *wvif, struct ieee80211_hdr *hdr, } static u8 wfx_tx_get_raw_link_id(struct wfx_vif *wvif, - struct ieee80211_sta *sta, - struct ieee80211_hdr *hdr) + struct ieee80211_sta *sta, + struct ieee80211_hdr *hdr) { struct wfx_sta_priv *sta_priv = - sta ? (struct wfx_sta_priv *) &sta->drv_priv : NULL; + sta ? (struct wfx_sta_priv *)&sta->drv_priv : NULL; const u8 *da = ieee80211_get_DA(hdr); if (sta_priv && sta_priv->link_id) @@ -368,7 +368,7 @@ static void wfx_tx_fixup_rates(struct ieee80211_tx_rate *rates) } static u8 wfx_tx_get_rate_id(struct wfx_vif *wvif, - struct ieee80211_tx_info *tx_info) + struct ieee80211_tx_info *tx_info) { bool tx_policy_renew = false; u8 rate_id; @@ -430,7 +430,7 @@ static int wfx_tx_inner(struct wfx_vif *wvif, struct ieee80211_sta *sta, struct ieee80211_key_conf *hw_key = tx_info->control.hw_key; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; int queue_id = tx_info->hw_queue; - size_t offset = (size_t) skb->data & 3; + size_t offset = (size_t)skb->data & 3; int wmsg_len = sizeof(struct hif_msg) + sizeof(struct hif_req_tx) + offset; diff --git a/drivers/staging/wfx/data_tx.h b/drivers/staging/wfx/data_tx.h index 04b2147101b6..c545dd75449b 100644 --- a/drivers/staging/wfx/data_tx.h +++ b/drivers/staging/wfx/data_tx.h @@ -61,7 +61,7 @@ static inline struct wfx_tx_priv *wfx_skb_tx_priv(struct sk_buff *skb) static inline struct hif_req_tx *wfx_skb_txreq(struct sk_buff *skb) { struct hif_msg *hif = (struct hif_msg *)skb->data; - struct hif_req_tx *req = (struct hif_req_tx *) hif->body; + struct hif_req_tx *req = (struct hif_req_tx *)hif->body; return req; } diff --git a/drivers/staging/wfx/hif_api_cmd.h b/drivers/staging/wfx/hif_api_cmd.h index 5554d6eddbf3..071b71e2a107 100644 --- a/drivers/staging/wfx/hif_api_cmd.h +++ b/drivers/staging/wfx/hif_api_cmd.h @@ -95,10 +95,6 @@ struct hif_req_reset { struct hif_reset_flags reset_flags; } __packed; -struct hif_cnf_reset { - u32 status; -} __packed; - struct hif_req_read_mib { u16 mib_id; u16 reserved; diff --git a/drivers/staging/wfx/hwio.c b/drivers/staging/wfx/hwio.c index 47e04c59ed93..d3a141d95a0e 100644 --- a/drivers/staging/wfx/hwio.c +++ b/drivers/staging/wfx/hwio.c @@ -142,7 +142,7 @@ static int indirect_read(struct wfx_dev *wdev, int reg, u32 addr, void *buf, goto err; if (!(cfg & prefetch)) break; - udelay(200); + usleep_range(200, 250); } if (i == 20) { ret = -ETIMEDOUT; diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c index 84adad64fc30..3c4c240229ad 100644 --- a/drivers/staging/wfx/main.c +++ b/drivers/staging/wfx/main.c @@ -262,6 +262,16 @@ static int wfx_send_pdata_pds(struct wfx_dev *wdev) return ret; } +static void wfx_free_common(void *data) +{ + struct wfx_dev *wdev = data; + + mutex_destroy(&wdev->rx_stats_lock); + mutex_destroy(&wdev->conf_mutex); + wfx_tx_queues_deinit(wdev); + ieee80211_free_hw(wdev->hw); +} + struct wfx_dev *wfx_init_common(struct device *dev, const struct wfx_platform_data *pdata, const struct hwbus_ops *hwbus_ops, @@ -332,15 +342,10 @@ struct wfx_dev *wfx_init_common(struct device *dev, wfx_init_hif_cmd(&wdev->hif_cmd); wfx_tx_queues_init(wdev); - return wdev; -} + if (devm_add_action_or_reset(dev, wfx_free_common, wdev)) + return NULL; -void wfx_free_common(struct wfx_dev *wdev) -{ - mutex_destroy(&wdev->rx_stats_lock); - mutex_destroy(&wdev->conf_mutex); - wfx_tx_queues_deinit(wdev); - ieee80211_free_hw(wdev->hw); + return wdev; } int wfx_probe(struct wfx_dev *wdev) @@ -420,7 +425,7 @@ int wfx_probe(struct wfx_dev *wdev) "enable 'quiescent' power mode with gpio %d and PDS file %s\n", desc_to_gpio(wdev->pdata.gpio_wakeup), wdev->pdata.file_pds); - gpiod_set_value(wdev->pdata.gpio_wakeup, 1); + gpiod_set_value_cansleep(wdev->pdata.gpio_wakeup, 1); control_reg_write(wdev, 0); hif_set_operational_mode(wdev, HIF_OP_POWER_MODE_QUIESCENT); } else { diff --git a/drivers/staging/wfx/main.h b/drivers/staging/wfx/main.h index 875f8c227803..9c9410072def 100644 --- a/drivers/staging/wfx/main.h +++ b/drivers/staging/wfx/main.h @@ -34,7 +34,6 @@ struct wfx_dev *wfx_init_common(struct device *dev, const struct wfx_platform_data *pdata, const struct hwbus_ops *hwbus_ops, void *hwbus_priv); -void wfx_free_common(struct wfx_dev *wdev); int wfx_probe(struct wfx_dev *wdev); void wfx_release(struct wfx_dev *wdev); diff --git a/drivers/staging/wfx/queue.c b/drivers/staging/wfx/queue.c index 0bcc61feee1d..39d9127ce4b9 100644 --- a/drivers/staging/wfx/queue.c +++ b/drivers/staging/wfx/queue.c @@ -130,12 +130,12 @@ static void wfx_tx_queue_clear(struct wfx_dev *wdev, struct wfx_queue *queue, spin_lock_bh(&queue->queue.lock); while ((item = __skb_dequeue(&queue->queue)) != NULL) skb_queue_head(gc_list, item); - spin_lock_bh(&stats->pending.lock); + spin_lock_nested(&stats->pending.lock, 1); for (i = 0; i < ARRAY_SIZE(stats->link_map_cache); ++i) { stats->link_map_cache[i] -= queue->link_map_cache[i]; queue->link_map_cache[i] = 0; } - spin_unlock_bh(&stats->pending.lock); + spin_unlock(&stats->pending.lock); spin_unlock_bh(&queue->queue.lock); } @@ -207,9 +207,9 @@ void wfx_tx_queue_put(struct wfx_dev *wdev, struct wfx_queue *queue, ++queue->link_map_cache[tx_priv->link_id]; - spin_lock_bh(&stats->pending.lock); + spin_lock_nested(&stats->pending.lock, 1); ++stats->link_map_cache[tx_priv->link_id]; - spin_unlock_bh(&stats->pending.lock); + spin_unlock(&stats->pending.lock); spin_unlock_bh(&queue->queue.lock); } @@ -237,11 +237,11 @@ static struct sk_buff *wfx_tx_queue_get(struct wfx_dev *wdev, __skb_unlink(skb, &queue->queue); --queue->link_map_cache[tx_priv->link_id]; - spin_lock_bh(&stats->pending.lock); + spin_lock_nested(&stats->pending.lock, 1); __skb_queue_tail(&stats->pending, skb); if (!--stats->link_map_cache[tx_priv->link_id]) wakeup_stats = true; - spin_unlock_bh(&stats->pending.lock); + spin_unlock(&stats->pending.lock); } spin_unlock_bh(&queue->queue.lock); if (wakeup_stats) @@ -259,10 +259,10 @@ int wfx_pending_requeue(struct wfx_dev *wdev, struct sk_buff *skb) spin_lock_bh(&queue->queue.lock); ++queue->link_map_cache[tx_priv->link_id]; - spin_lock_bh(&stats->pending.lock); + spin_lock_nested(&stats->pending.lock, 1); ++stats->link_map_cache[tx_priv->link_id]; __skb_unlink(skb, &stats->pending); - spin_unlock_bh(&stats->pending.lock); + spin_unlock(&stats->pending.lock); __skb_queue_tail(&queue->queue, skb); spin_unlock_bh(&queue->queue.lock); return 0; @@ -481,7 +481,6 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) struct wfx_queue *vif_queue = NULL; u32 tx_allowed_mask = 0; u32 vif_tx_allowed_mask = 0; - const struct wfx_tx_priv *tx_priv = NULL; struct wfx_vif *wvif; int not_found; int burst; @@ -541,8 +540,7 @@ struct hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) skb = wfx_tx_queue_get(wdev, queue, tx_allowed_mask); if (!skb) continue; - tx_priv = wfx_skb_tx_priv(skb); - hif = (struct hif_msg *) skb->data; + hif = (struct hif_msg *)skb->data; wvif = wdev_to_wvif(wdev, hif->interface); WARN_ON(!wvif); diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c index af4f4bbd0572..9d430346a58b 100644 --- a/drivers/staging/wfx/sta.c +++ b/drivers/staging/wfx/sta.c @@ -293,7 +293,6 @@ int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct wfx_dev *wdev = hw->priv; struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv; int old_uapsd = wvif->uapsd_mask; - int ret = 0; WARN_ON(queue >= hw->queues); @@ -307,7 +306,7 @@ int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, wfx_update_pm(wvif); } mutex_unlock(&wdev->conf_mutex); - return ret; + return 0; } int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value) @@ -909,7 +908,7 @@ static void wfx_update_tim_work(struct work_struct *work) int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set) { struct wfx_dev *wdev = hw->priv; - struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *) &sta->drv_priv; + struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv; struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id); schedule_work(&wvif->update_tim_work); diff --git a/drivers/staging/wilc1000/Kconfig b/drivers/staging/wilc1000/Kconfig index 59e58550d139..80c92e8bf8a5 100644 --- a/drivers/staging/wilc1000/Kconfig +++ b/drivers/staging/wilc1000/Kconfig @@ -2,6 +2,10 @@ config WILC1000 tristate help + Add support for the Atmel WILC1000 802.11 b/g/n SoC. + This provides Wi-FI over an SDIO or SPI interface, and + is usually found in IoT devices. + This module only support IEEE 802.11n WiFi. config WILC1000_SDIO @@ -22,6 +26,7 @@ config WILC1000_SPI tristate "Atmel WILC1000 SPI (WiFi only)" depends on CFG80211 && INET && SPI select WILC1000 + select CRC7 help This module adds support for the SPI interface of adapters using WILC1000 chipset. The Atmel WILC1000 has a Serial Peripheral diff --git a/drivers/staging/wilc1000/cfg80211.c b/drivers/staging/wilc1000/cfg80211.c index 4863e516ff13..4bdcbc5fd2fd 100644 --- a/drivers/staging/wilc1000/cfg80211.c +++ b/drivers/staging/wilc1000/cfg80211.c @@ -6,29 +6,17 @@ #include "cfg80211.h" -#define FRAME_TYPE_ID 0 -#define ACTION_CAT_ID 24 -#define ACTION_SUBTYPE_ID 25 -#define P2P_PUB_ACTION_SUBTYPE 30 - -#define ACTION_FRAME 0xd0 -#define GO_INTENT_ATTR_ID 0x04 -#define CHANLIST_ATTR_ID 0x0b -#define OPERCHAN_ATTR_ID 0x11 -#define PUB_ACTION_ATTR_ID 0x04 -#define P2PELEM_ATTR_ID 0xdd - #define GO_NEG_REQ 0x00 #define GO_NEG_RSP 0x01 #define GO_NEG_CONF 0x02 #define P2P_INV_REQ 0x03 #define P2P_INV_RSP 0x04 -#define PUBLIC_ACT_VENDORSPEC 0x09 -#define GAS_INITIAL_REQ 0x0a -#define GAS_INITIAL_RSP 0x0b #define WILC_INVALID_CHANNEL 0 +/* Operation at 2.4 GHz with channels 1-13 */ +#define WILC_WLAN_OPERATING_CLASS_2_4GHZ 0x51 + static const struct ieee80211_txrx_stypes wilc_wfi_cfg80211_mgmt_types[NUM_NL80211_IFTYPES] = { [NL80211_IFTYPE_STATION] = { @@ -67,8 +55,50 @@ struct wilc_p2p_mgmt_data { u8 *buff; }; -static const u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09}; -static const u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03}; +struct wilc_p2p_pub_act_frame { + u8 category; + u8 action; + u8 oui[3]; + u8 oui_type; + u8 oui_subtype; + u8 dialog_token; + u8 elem[]; +} __packed; + +struct wilc_vendor_specific_ie { + u8 tag_number; + u8 tag_len; + u8 oui[3]; + u8 oui_type; + u8 attr[]; +} __packed; + +struct wilc_attr_entry { + u8 attr_type; + __le16 attr_len; + u8 val[]; +} __packed; + +struct wilc_attr_oper_ch { + u8 attr_type; + __le16 attr_len; + u8 country_code[IEEE80211_COUNTRY_STRING_LEN]; + u8 op_class; + u8 op_channel; +} __packed; + +struct wilc_attr_ch_list { + u8 attr_type; + __le16 attr_len; + u8 country_code[IEEE80211_COUNTRY_STRING_LEN]; + u8 elem[]; +} __packed; + +struct wilc_ch_list_elem { + u8 op_class; + u8 no_of_channels; + u8 ch_list[]; +} __packed; static void cfg_scan_result(enum scan_event scan_event, struct wilc_rcvd_net_info *info, void *user_void) @@ -172,9 +202,6 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt, u8 mac_status, } else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) { u16 reason = 0; - priv->p2p.local_random = 0x01; - priv->p2p.recv_random = 0x00; - priv->p2p.is_wilc_ie = false; eth_zero_addr(priv->associated_bss); wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE); @@ -446,9 +473,6 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev, wilc->sta_ch = WILC_INVALID_CHANNEL; wilc_wlan_set_bssid(priv->dev, NULL, WILC_STATION_MODE); - priv->p2p.local_random = 0x01; - priv->p2p.recv_random = 0x00; - priv->p2p.is_wilc_ie = false; priv->hif_drv->p2p_timeout = 0; ret = wilc_disconnect(vif); @@ -864,7 +888,6 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, struct cfg80211_pmksa *pmksa) { u32 i; - int ret = 0; struct wilc_vif *vif = netdev_priv(netdev); struct wilc_priv *priv = &vif->priv; @@ -877,21 +900,20 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev, } } - if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) { - for (; i < (priv->pmkid_list.numpmkid - 1); i++) { - memcpy(priv->pmkid_list.pmkidlist[i].bssid, - priv->pmkid_list.pmkidlist[i + 1].bssid, - ETH_ALEN); - memcpy(priv->pmkid_list.pmkidlist[i].pmkid, - priv->pmkid_list.pmkidlist[i + 1].pmkid, - WLAN_PMKID_LEN); - } - priv->pmkid_list.numpmkid--; - } else { - ret = -EINVAL; + if (i == priv->pmkid_list.numpmkid) + return -EINVAL; + + for (; i < (priv->pmkid_list.numpmkid - 1); i++) { + memcpy(priv->pmkid_list.pmkidlist[i].bssid, + priv->pmkid_list.pmkidlist[i + 1].bssid, + ETH_ALEN); + memcpy(priv->pmkid_list.pmkidlist[i].pmkid, + priv->pmkid_list.pmkidlist[i + 1].pmkid, + WLAN_PMKID_LEN); } + priv->pmkid_list.numpmkid--; - return ret; + return 0; } static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) @@ -903,113 +925,50 @@ static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev) return 0; } -static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u8 ch_list_attr_idx, - u8 op_ch_attr_idx, u8 sta_ch) -{ - int i = 0; - int j = 0; - - if (ch_list_attr_idx) { - u8 limit = ch_list_attr_idx + 3 + buf[ch_list_attr_idx + 1]; - - for (i = ch_list_attr_idx + 3; i < limit; i++) { - if (buf[i] == 0x51) { - for (j = i + 2; j < ((i + 2) + buf[i + 1]); j++) - buf[j] = sta_ch; - break; - } - } - } - - if (op_ch_attr_idx) { - buf[op_ch_attr_idx + 6] = 0x51; - buf[op_ch_attr_idx + 7] = sta_ch; - } -} - -static void wilc_wfi_cfg_parse_rx_action(u8 *buf, u32 len, u8 sta_ch) +static inline void wilc_wfi_cfg_parse_ch_attr(u8 *buf, u32 len, u8 sta_ch) { + struct wilc_attr_entry *e; + struct wilc_attr_ch_list *ch_list; + struct wilc_attr_oper_ch *op_ch; u32 index = 0; - u8 op_channel_attr_index = 0; - u8 channel_list_attr_index = 0; - - while (index < len) { - if (buf[index] == GO_INTENT_ATTR_ID) - buf[index + 3] = (buf[index + 3] & 0x01) | (0x00 << 1); - - if (buf[index] == CHANLIST_ATTR_ID) - channel_list_attr_index = index; - else if (buf[index] == OPERCHAN_ATTR_ID) - op_channel_attr_index = index; - index += buf[index + 1] + 3; - } - if (sta_ch != WILC_INVALID_CHANNEL) - wilc_wfi_cfg_parse_ch_attr(buf, channel_list_attr_index, - op_channel_attr_index, sta_ch); -} + u8 ch_list_idx = 0; + u8 op_ch_idx = 0; -static void wilc_wfi_cfg_parse_tx_action(u8 *buf, u32 len, bool oper_ch, - u8 iftype, u8 sta_ch) -{ - u32 index = 0; - u8 op_channel_attr_index = 0; - u8 channel_list_attr_index = 0; - - while (index < len) { - if (buf[index] == GO_INTENT_ATTR_ID) { - buf[index + 3] = (buf[index + 3] & 0x01) | (0x0f << 1); + if (sta_ch == WILC_INVALID_CHANNEL) + return; + while (index + sizeof(*e) <= len) { + e = (struct wilc_attr_entry *)&buf[index]; + if (e->attr_type == IEEE80211_P2P_ATTR_CHANNEL_LIST) + ch_list_idx = index; + else if (e->attr_type == IEEE80211_P2P_ATTR_OPER_CHANNEL) + op_ch_idx = index; + if (ch_list_idx && op_ch_idx) break; - } - - if (buf[index] == CHANLIST_ATTR_ID) - channel_list_attr_index = index; - else if (buf[index] == OPERCHAN_ATTR_ID) - op_channel_attr_index = index; - index += buf[index + 1] + 3; + index += le16_to_cpu(e->attr_len) + sizeof(*e); } - if (sta_ch != WILC_INVALID_CHANNEL && oper_ch) - wilc_wfi_cfg_parse_ch_attr(buf, channel_list_attr_index, - op_channel_attr_index, sta_ch); -} -static void wilc_wfi_cfg_parse_rx_vendor_spec(struct wilc_priv *priv, u8 *buff, - u32 size) -{ - int i; - u8 subtype; - struct wilc_vif *vif = netdev_priv(priv->dev); - - subtype = buff[P2P_PUB_ACTION_SUBTYPE]; - if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && - !priv->p2p.is_wilc_ie) { - for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) { - if (!memcmp(p2p_vendor_spec, &buff[i], 6)) { - priv->p2p.recv_random = buff[i + 6]; - priv->p2p.is_wilc_ie = true; + if (ch_list_idx) { + u16 attr_size; + struct wilc_ch_list_elem *e; + int i; + + ch_list = (struct wilc_attr_ch_list *)&buf[ch_list_idx]; + attr_size = le16_to_cpu(ch_list->attr_len); + for (i = 0; i < attr_size;) { + e = (struct wilc_ch_list_elem *)(ch_list->elem + i); + if (e->op_class == WILC_WLAN_OPERATING_CLASS_2_4GHZ) { + memset(e->ch_list, sta_ch, e->no_of_channels); break; } + i += e->no_of_channels; } } - if (priv->p2p.local_random <= priv->p2p.recv_random) { - netdev_dbg(vif->ndev, - "PEER WILL BE GO LocaRand=%02x RecvRand %02x\n", - priv->p2p.local_random, priv->p2p.recv_random); - return; - } - - if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP || - subtype == P2P_INV_REQ || subtype == P2P_INV_RSP) { - for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < size; i++) { - if (buff[i] == P2PELEM_ATTR_ID && - !(memcmp(p2p_oui, &buff[i + 2], 4))) { - wilc_wfi_cfg_parse_rx_action(&buff[i + 6], - size - (i + 6), - vif->wilc->sta_ch); - break; - } - } + if (op_ch_idx) { + op_ch = (struct wilc_attr_oper_ch *)&buf[op_ch_idx]; + op_ch->op_class = WILC_WLAN_OPERATING_CLASS_2_4GHZ; + op_ch->op_channel = sta_ch; } } @@ -1018,17 +977,22 @@ void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size) struct wilc *wl = vif->wilc; struct wilc_priv *priv = &vif->priv; struct host_if_drv *wfi_drv = priv->hif_drv; + struct ieee80211_mgmt *mgmt; + struct wilc_vendor_specific_ie *p; + struct wilc_p2p_pub_act_frame *d; + int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d); + const u8 *vendor_ie; u32 header, pkt_offset; s32 freq; - __le16 fc; header = get_unaligned_le32(buff - HOST_HDR_OFFSET); - pkt_offset = GET_PKT_OFFSET(header); + pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header); if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { bool ack = false; + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)buff; - if (buff[FRAME_TYPE_ID] == IEEE80211_STYPE_PROBE_RESP || + if (ieee80211_is_probe_resp(hdr->frame_control) || pkt_offset & IS_MGMT_STATUS_SUCCES) ack = true; @@ -1039,44 +1003,33 @@ void wilc_wfi_p2p_rx(struct wilc_vif *vif, u8 *buff, u32 size) freq = ieee80211_channel_to_frequency(wl->op_ch, NL80211_BAND_2GHZ); - fc = ((struct ieee80211_hdr *)buff)->frame_control; - if (!ieee80211_is_action(fc)) { - cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0); - return; - } + mgmt = (struct ieee80211_mgmt *)buff; + if (!ieee80211_is_action(mgmt->frame_control)) + goto out_rx_mgmt; if (priv->cfg_scanning && time_after_eq(jiffies, (unsigned long)wfi_drv->p2p_timeout)) { netdev_dbg(vif->ndev, "Receiving action wrong ch\n"); return; } - if (buff[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) { - u8 subtype = buff[P2P_PUB_ACTION_SUBTYPE]; - switch (buff[ACTION_SUBTYPE_ID]) { - case GAS_INITIAL_REQ: - case GAS_INITIAL_RSP: - break; + if (!ieee80211_is_public_action((struct ieee80211_hdr *)buff, size)) + goto out_rx_mgmt; - case PUBLIC_ACT_VENDORSPEC: - if (!memcmp(p2p_oui, &buff[ACTION_SUBTYPE_ID + 1], 4)) - wilc_wfi_cfg_parse_rx_vendor_spec(priv, buff, - size); + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action); + if (d->oui_subtype != GO_NEG_REQ && d->oui_subtype != GO_NEG_RSP && + d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP) + goto out_rx_mgmt; - if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && - priv->p2p.is_wilc_ie) - size -= 7; + vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, + buff + ie_offset, size - ie_offset); + if (!vendor_ie) + goto out_rx_mgmt; - break; - - default: - netdev_dbg(vif->ndev, - "%s: Not handled action frame type:%x\n", - __func__, buff[ACTION_SUBTYPE_ID]); - break; - } - } + p = (struct wilc_vendor_specific_ie *)vendor_ie; + wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch); +out_rx_mgmt: cfg80211_rx_mgmt(&priv->wdev, freq, 0, buff, size, 0); } @@ -1156,57 +1109,6 @@ static int cancel_remain_on_channel(struct wiphy *wiphy, return wilc_listen_state_expired(vif, cookie); } -static void wilc_wfi_cfg_tx_vendor_spec(struct wilc_priv *priv, - struct wilc_p2p_mgmt_data *mgmt_tx, - struct cfg80211_mgmt_tx_params *params, - u8 iftype, u32 buf_len) -{ - const u8 *buf = params->buf; - size_t len = params->len; - u32 i; - u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE]; - struct wilc_vif *vif = netdev_priv(priv->dev); - - if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) { - if (priv->p2p.local_random == 1 && - priv->p2p.recv_random < priv->p2p.local_random) { - get_random_bytes(&priv->p2p.local_random, 1); - priv->p2p.local_random++; - } - } - - if (priv->p2p.local_random <= priv->p2p.recv_random || - !(subtype == GO_NEG_REQ || subtype == GO_NEG_RSP || - subtype == P2P_INV_REQ || subtype == P2P_INV_RSP)) - return; - - for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) { - if (buf[i] == P2PELEM_ATTR_ID && - !memcmp(p2p_oui, &buf[i + 2], 4)) { - bool oper_ch = false; - u8 *tx_buff = &mgmt_tx->buff[i + 6]; - - if (subtype == P2P_INV_REQ || subtype == P2P_INV_RSP) - oper_ch = true; - - wilc_wfi_cfg_parse_tx_action(tx_buff, len - (i + 6), - oper_ch, iftype, - vif->wilc->sta_ch); - - break; - } - } - - if (subtype != P2P_INV_REQ && subtype != P2P_INV_RSP) { - int vendor_spec_len = sizeof(p2p_vendor_spec); - - memcpy(&mgmt_tx->buff[len], p2p_vendor_spec, - vendor_spec_len); - mgmt_tx->buff[len + vendor_spec_len] = priv->p2p.local_random; - mgmt_tx->size = buf_len; - } -} - static int mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev, struct cfg80211_mgmt_tx_params *params, @@ -1221,8 +1123,10 @@ static int mgmt_tx(struct wiphy *wiphy, struct wilc_vif *vif = netdev_priv(wdev->netdev); struct wilc_priv *priv = &vif->priv; struct host_if_drv *wfi_drv = priv->hif_drv; - u32 buf_len = len + sizeof(p2p_vendor_spec) + - sizeof(priv->p2p.local_random); + struct wilc_vendor_specific_ie *p; + struct wilc_p2p_pub_act_frame *d; + int ie_offset = offsetof(struct ieee80211_mgmt, u) + sizeof(*d); + const u8 *vendor_ie; int ret = 0; *cookie = prandom_u32(); @@ -1238,14 +1142,13 @@ static int mgmt_tx(struct wiphy *wiphy, goto out; } - mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL); + mgmt_tx->buff = kmemdup(buf, len, GFP_KERNEL); if (!mgmt_tx->buff) { ret = -ENOMEM; kfree(mgmt_tx); goto out; } - memcpy(mgmt_tx->buff, buf, len); mgmt_tx->size = len; if (ieee80211_is_probe_resp(mgmt->frame_control)) { @@ -1254,39 +1157,29 @@ static int mgmt_tx(struct wiphy *wiphy, goto out_txq_add_pkt; } - if (!ieee80211_is_action(mgmt->frame_control)) - goto out_txq_add_pkt; + if (!ieee80211_is_public_action((struct ieee80211_hdr *)buf, len)) + goto out_set_timeout; - if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) { - if (buf[ACTION_SUBTYPE_ID] != PUBLIC_ACT_VENDORSPEC || - buf[P2P_PUB_ACTION_SUBTYPE] != GO_NEG_CONF) { - wilc_set_mac_chnl_num(vif, chan->hw_value); - vif->wilc->op_ch = chan->hw_value; - } - switch (buf[ACTION_SUBTYPE_ID]) { - case GAS_INITIAL_REQ: - case GAS_INITIAL_RSP: - break; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action); + if (d->oui_type != WLAN_OUI_TYPE_WFA_P2P || + d->oui_subtype != GO_NEG_CONF) { + wilc_set_mac_chnl_num(vif, chan->hw_value); + vif->wilc->op_ch = chan->hw_value; + } - case PUBLIC_ACT_VENDORSPEC: - if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4)) - wilc_wfi_cfg_tx_vendor_spec(priv, mgmt_tx, - params, vif->iftype, - buf_len); - else - netdev_dbg(vif->ndev, - "Not a P2P public action frame\n"); + if (d->oui_subtype != P2P_INV_REQ && d->oui_subtype != P2P_INV_RSP) + goto out_set_timeout; - break; + vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, + mgmt_tx->buff + ie_offset, + len - ie_offset); + if (!vendor_ie) + goto out_set_timeout; - default: - netdev_dbg(vif->ndev, - "%s: Not handled action frame type:%x\n", - __func__, buf[ACTION_SUBTYPE_ID]); - break; - } - } + p = (struct wilc_vendor_specific_ie *)vendor_ie; + wilc_wfi_cfg_parse_ch_attr(p->attr, p->tag_len - 4, vif->wilc->sta_ch); +out_set_timeout: wfi_drv->p2p_timeout = (jiffies + msecs_to_jiffies(wait)); out_txq_add_pkt: @@ -1400,10 +1293,6 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev, struct wilc_vif *vif = netdev_priv(dev); struct wilc_priv *priv = &vif->priv; - priv->p2p.local_random = 0x01; - priv->p2p.recv_random = 0x00; - priv->p2p.is_wilc_ie = false; - switch (type) { case NL80211_IFTYPE_STATION: vif->connecting = false; diff --git a/drivers/staging/wilc1000/hif.c b/drivers/staging/wilc1000/hif.c index 658790bd465b..6c7de2f8d3f2 100644 --- a/drivers/staging/wilc1000/hif.c +++ b/drivers/staging/wilc1000/hif.c @@ -801,7 +801,7 @@ static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac, if (params->ht_capa) { *cur_byte++ = true; - memcpy(cur_byte, ¶ms->ht_capa, + memcpy(cur_byte, params->ht_capa, sizeof(struct ieee80211_ht_cap)); } else { *cur_byte++ = false; @@ -861,9 +861,8 @@ static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie) struct wid wid; int result; struct host_if_drv *hif_drv = vif->hif_drv; - struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr); - if (priv->p2p_listen_state) { + if (vif->priv.p2p_listen_state) { remain_on_chan_flag = false; wid.id = WID_REMAIN_ON_CHAN; wid.type = WID_STR; diff --git a/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt b/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt deleted file mode 100644 index da5235950a70..000000000000 --- a/drivers/staging/wilc1000/microchip,wilc1000,sdio.txt +++ /dev/null @@ -1,38 +0,0 @@ -* Microchip WILC wireless SDIO device - -The wilc1000 chips can be connected via SDIO. The node is used to specifiy -child node to the SDIO controller that connects the device to the system. - -Required properties: -- compatible : Should be "microchip,wilc1000-spi" -- irq-gpios : Connect to a host IRQ -- reg : Slot ID used in the controller - -Optional: -- bus-width : Number of data lines wired up the slot. Default 1 bit. -- rtc_clk : Clock connected on the rtc clock line. Must be assigned - a frequency with assigned-clocks property, and must be - connected to a clock provider. - -Examples: -mmc1: mmc@fc000000 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_mmc1_clk_cmd_dat0 &pinctrl_mmc1_dat1_3>; - non-removable; - vmmc-supply = <&vcc_mmc1_reg>; - vqmmc-supply = <&vcc_3v3_reg>; - status = "okay"; - - wilc_sdio@0 { - compatible = "microchip,wilc1000-sdio"; - irq-gpios = <&pioC 27 0>; - clocks = <&pck1>; - clock-names = "rtc_clk"; - assigned-clocks = <&pck1>; - assigned-clock-rates = <32768>; - status = "okay"; - reg = <0>; - bus-width = <4>; - } - }; -} diff --git a/drivers/staging/wilc1000/microchip,wilc1000,spi.txt b/drivers/staging/wilc1000/microchip,wilc1000,spi.txt deleted file mode 100644 index 34236932dbb6..000000000000 --- a/drivers/staging/wilc1000/microchip,wilc1000,spi.txt +++ /dev/null @@ -1,34 +0,0 @@ -* Microchip WILC wireless SPI device - -The wilc1000 chips can be connected via SPI. This document describes -the binding for the SPI connected module. - -Required properties: -- compatible : Should be "microchip,wilc1000-spi" -- spi-max-frequency : Maximum SPI clocking speed of device in Hz -- reg : Chip select address of device -- irq-gpios : Connect to a host IRQ - -Optional: -- rtc_clk : Clock connected on the rtc clock line. Must be assigned - a frequency with assigned-clocks property, and must be - connected to a clock provider. - -Examples: - -spi1: spi@fc018000 { - cs-gpios = <&pioB 21 0>; - status = "okay"; - - wilc_spi@0 { - compatible = "microchip,wilc1000-spi"; - spi-max-frequency = <48000000>; - reg = <0>; - irq-gpios = <&pioC 27 0>; - clocks = <&pck1>; - clock-names = "rtc_clk"; - assigned-clocks = <&pck1>; - assigned-clock-rates = <32768>; - status = "okay"; - }; -}; diff --git a/drivers/staging/wilc1000/microchip,wilc1000.yaml b/drivers/staging/wilc1000/microchip,wilc1000.yaml new file mode 100644 index 000000000000..2c320eb2a8c4 --- /dev/null +++ b/drivers/staging/wilc1000/microchip,wilc1000.yaml @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/wireless/microchip,wilc1000.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip WILC wireless devicetree bindings + +maintainers: + - Adham Abozaeid <adham.abozaeid@microchip.com> + - Ajay Singh <ajay.kathat@microchip.com> + +description: + The wilc1000 chips can be connected via SPI or SDIO. This document + describes the binding to connect wilc devices. + +properties: + compatible: + const: microchip,wilc1000 + + spi-max-frequency: true + + interrupts: + maxItems: 1 + + clocks: + description: phandle to the clock connected on rtc clock line. + maxItems: 1 + + clock-names: + const: rtc + +required: + - compatible + - interrupts + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + wifi@0 { + compatible = "microchip,wilc1000"; + spi-max-frequency = <48000000>; + reg = <0>; + interrupt-parent = <&pioC>; + interrupts = <27 0>; + clocks = <&pck1>; + clock-names = "rtc"; + }; + }; + + - | + mmc { + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_mmc1_clk_cmd_dat0 &pinctrl_mmc1_dat1_3>; + non-removable; + vmmc-supply = <&vcc_mmc1_reg>; + vqmmc-supply = <&vcc_3v3_reg>; + bus-width = <4>; + wifi@0 { + compatible = "microchip,wilc1000"; + reg = <0>; + interrupt-parent = <&pioC>; + interrupts = <27 0>; + clocks = <&pck1>; + clock-names = "rtc"; + }; + }; diff --git a/drivers/staging/wilc1000/mon.c b/drivers/staging/wilc1000/mon.c index 48ac33f06f63..60331417bd98 100644 --- a/drivers/staging/wilc1000/mon.c +++ b/drivers/staging/wilc1000/mon.c @@ -40,7 +40,7 @@ void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size) * The packet offset field contain info about what type of management * the frame we are dealing with and ack status */ - pkt_offset = GET_PKT_OFFSET(header); + pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header); if (pkt_offset & IS_MANAGMEMENT_CALLBACK) { /* hostapd callback mgmt frame */ diff --git a/drivers/staging/wilc1000/netdev.c b/drivers/staging/wilc1000/netdev.c index fce5bf2d82fa..f94a17babd12 100644 --- a/drivers/staging/wilc1000/netdev.c +++ b/drivers/staging/wilc1000/netdev.c @@ -46,29 +46,21 @@ static irqreturn_t isr_bh_routine(int irq, void *userdata) static int init_irq(struct net_device *dev) { - int ret = 0; struct wilc_vif *vif = netdev_priv(dev); struct wilc *wl = vif->wilc; - - ret = gpiod_direction_input(wl->gpio_irq); - if (ret) { - netdev_err(dev, "could not obtain gpio for WILC_INTR\n"); - return ret; - } - - wl->dev_irq_num = gpiod_to_irq(wl->gpio_irq); + int ret; ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine, isr_bh_routine, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "WILC_IRQ", dev); - if (ret < 0) - netdev_err(dev, "Failed to request IRQ\n"); - else - netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n", - wl->dev_irq_num); + if (ret) { + netdev_err(dev, "Failed to request IRQ [%d]\n", ret); + return ret; + } + netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n", wl->dev_irq_num); - return ret; + return 0; } static void deinit_irq(struct net_device *dev) @@ -501,7 +493,7 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif) if (ret) goto fail_wilc_wlan; - if (wl->gpio_irq && init_irq(dev)) { + if (wl->dev_irq_num && init_irq(dev)) { ret = -EIO; goto fail_threads; } @@ -577,7 +569,6 @@ static int wilc_mac_open(struct net_device *ndev) { struct wilc_vif *vif = netdev_priv(ndev); struct wilc *wl = vif->wilc; - struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr); unsigned char mac_add[ETH_ALEN] = {0}; int ret = 0; @@ -621,7 +612,6 @@ static int wilc_mac_open(struct net_device *ndev) vif->frame_reg[1].reg); netif_wake_queue(ndev); wl->open_ifcs++; - priv->p2p.local_random = 0x01; vif->mac_opened = 1; return 0; } @@ -804,8 +794,10 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size) u16 type = le16_to_cpup((__le16 *)buff); if (vif->priv.p2p_listen_state && - ((type == vif->frame_reg[0].type && vif->frame_reg[0].reg) || - (type == vif->frame_reg[1].type && vif->frame_reg[1].reg))) + ((type == vif->frame_reg[0].type && + vif->frame_reg[0].reg) || + (type == vif->frame_reg[1].type && + vif->frame_reg[1].reg))) wilc_wfi_p2p_rx(vif, buff, size); if (vif->monitor_flag) diff --git a/drivers/staging/wilc1000/netdev.h b/drivers/staging/wilc1000/netdev.h index d5f7a6037fbc..61cbec674a62 100644 --- a/drivers/staging/wilc1000/netdev.h +++ b/drivers/staging/wilc1000/netdev.h @@ -29,8 +29,6 @@ #define TCP_ACK_FILTER_LINK_SPEED_THRESH 54 #define DEFAULT_LINK_SPEED 72 -#define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff) - struct wilc_wfi_stats { unsigned long rx_packets; unsigned long tx_packets; @@ -66,12 +64,6 @@ struct wilc_wfi_p2p_listen_params { u64 listen_cookie; }; -struct wilc_p2p_var { - u8 local_random; - u8 recv_random; - bool is_wilc_ie; -}; - static const u32 wilc_cipher_suites[] = { WLAN_CIPHER_SUITE_WEP40, WLAN_CIPHER_SUITE_WEP104, @@ -155,7 +147,6 @@ struct wilc_priv { struct mutex scan_req_lock; bool p2p_listen_state; int scanned_cnt; - struct wilc_p2p_var p2p; u64 inc_roc_cookie; }; @@ -218,7 +209,6 @@ struct wilc { const struct wilc_hif_func *hif_func; int io_type; s8 mac_status; - struct gpio_desc *gpio_irq; struct clk *rtc_clk; bool initialized; int dev_irq_num; diff --git a/drivers/staging/wilc1000/sdio.c b/drivers/staging/wilc1000/sdio.c index ca99335687c4..36eb589263bf 100644 --- a/drivers/staging/wilc1000/sdio.c +++ b/drivers/staging/wilc1000/sdio.c @@ -7,6 +7,8 @@ #include <linux/clk.h> #include <linux/mmc/sdio_func.h> #include <linux/mmc/host.h> +#include <linux/mmc/sdio.h> +#include <linux/of_irq.h> #include "netdev.h" #include "cfg80211.h" @@ -26,9 +28,6 @@ static const struct sdio_device_id wilc_sdio_ids[] = { struct wilc_sdio { bool irq_gpio; u32 block_size; - int nint; -/* Max num interrupts allowed in registers 0xf7, 0xf8 */ -#define MAX_NUN_INT_THRPT_ENH2 (5) int has_thrpt_enh3; }; @@ -124,35 +123,34 @@ static int wilc_sdio_probe(struct sdio_func *func, { struct wilc *wilc; int ret; - struct gpio_desc *gpio = NULL; struct wilc_sdio *sdio_priv; sdio_priv = kzalloc(sizeof(*sdio_priv), GFP_KERNEL); if (!sdio_priv) return -ENOMEM; - if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { - gpio = gpiod_get(&func->dev, "irq", GPIOD_IN); - if (IS_ERR(gpio)) { - /* get the GPIO descriptor from hardcode GPIO number */ - gpio = gpio_to_desc(GPIO_NUM); - if (!gpio) - dev_err(&func->dev, "failed to get irq gpio\n"); - } - } - ret = wilc_cfg80211_init(&wilc, &func->dev, WILC_HIF_SDIO, &wilc_hif_sdio); if (ret) { kfree(sdio_priv); return ret; } + + if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) { + struct device_node *np = func->card->dev.of_node; + int irq_num = of_irq_get(np, 0); + + if (irq_num > 0) { + wilc->dev_irq_num = irq_num; + sdio_priv->irq_gpio = true; + } + } + sdio_set_drvdata(func, wilc); wilc->bus_data = sdio_priv; wilc->dev = &func->dev; - wilc->gpio_irq = gpio; - wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc_clk"); + wilc->rtc_clk = devm_clk_get(&func->card->dev, "rtc"); if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) return -EPROBE_DEFER; else if (!IS_ERR(wilc->rtc_clk)) @@ -166,10 +164,6 @@ static void wilc_sdio_remove(struct sdio_func *func) { struct wilc *wilc = sdio_get_drvdata(func); - /* free the GPIO in module remove */ - if (wilc->gpio_irq) - gpiod_put(wilc->gpio_irq); - if (!IS_ERR(wilc->rtc_clk)) clk_disable_unprepare(wilc->rtc_clk); @@ -185,8 +179,8 @@ static int wilc_sdio_reset(struct wilc *wilc) cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; - cmd.address = 0x6; - cmd.data = 0x8; + cmd.address = SDIO_CCCR_ABORT; + cmd.data = WILC_SDIO_CCCR_ABORT_RESET; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, "Fail cmd 52, reset cmd ...\n"); @@ -268,34 +262,38 @@ static int wilc_sdio_set_func0_csa_address(struct wilc *wilc, u32 adr) cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; - cmd.address = 0x10c; + cmd.address = WILC_SDIO_FBR_CSA_REG; cmd.data = (u8)adr; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x10c data...\n"); + dev_err(&func->dev, "Failed cmd52, set %04x data...\n", + cmd.address); return ret; } - cmd.address = 0x10d; + cmd.address = WILC_SDIO_FBR_CSA_REG + 1; cmd.data = (u8)(adr >> 8); ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x10d data...\n"); + dev_err(&func->dev, "Failed cmd52, set %04x data...\n", + cmd.address); return ret; } - cmd.address = 0x10e; + cmd.address = WILC_SDIO_FBR_CSA_REG + 2; cmd.data = (u8)(adr >> 16); ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x10e data...\n"); + dev_err(&func->dev, "Failed cmd52, set %04x data...\n", + cmd.address); return ret; } return 0; } -static int wilc_sdio_set_func0_block_size(struct wilc *wilc, u32 block_size) +static int wilc_sdio_set_block_size(struct wilc *wilc, u8 func_num, + u32 block_size) { struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct sdio_cmd52 cmd; @@ -304,52 +302,21 @@ static int wilc_sdio_set_func0_block_size(struct wilc *wilc, u32 block_size) cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; - cmd.address = 0x10; + cmd.address = SDIO_FBR_BASE(func_num) + SDIO_CCCR_BLKSIZE; cmd.data = (u8)block_size; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x10 data...\n"); + dev_err(&func->dev, "Failed cmd52, set %04x data...\n", + cmd.address); return ret; } - cmd.address = 0x11; - cmd.data = (u8)(block_size >> 8); - ret = wilc_sdio_cmd52(wilc, &cmd); - if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x11 data...\n"); - return ret; - } - - return 0; -} - -/******************************************** - * - * Function 1 - * - ********************************************/ - -static int wilc_sdio_set_func1_block_size(struct wilc *wilc, u32 block_size) -{ - struct sdio_func *func = dev_to_sdio_func(wilc->dev); - struct sdio_cmd52 cmd; - int ret; - - cmd.read_write = 1; - cmd.function = 0; - cmd.raw = 0; - cmd.address = 0x110; - cmd.data = (u8)block_size; - ret = wilc_sdio_cmd52(wilc, &cmd); - if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x110 data...\n"); - return ret; - } - cmd.address = 0x111; + cmd.address = SDIO_FBR_BASE(func_num) + SDIO_CCCR_BLKSIZE + 1; cmd.data = (u8)(block_size >> 8); ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { - dev_err(&func->dev, "Failed cmd52, set 0x111 data...\n"); + dev_err(&func->dev, "Failed cmd52, set %04x data...\n", + cmd.address); return ret; } @@ -369,7 +336,7 @@ static int wilc_sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) cpu_to_le32s(&data); - if (addr >= 0xf0 && addr <= 0xff) { + if (addr >= 0xf0 && addr <= 0xff) { /* only vendor specific registers */ struct sdio_cmd52 cmd; cmd.read_write = 1; @@ -393,7 +360,7 @@ static int wilc_sdio_write_reg(struct wilc *wilc, u32 addr, u32 data) cmd.read_write = 1; cmd.function = 0; - cmd.address = 0x10f; + cmd.address = WILC_SDIO_FBR_DATA_REG; cmd.block_mode = 0; cmd.increment = 1; cmd.count = 4; @@ -419,34 +386,19 @@ static int wilc_sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) cmd.read_write = 1; if (addr > 0) { /** - * has to be word aligned... - **/ - if (size & 0x3) { - size += 4; - size &= ~0x3; - } - - /** * func 0 access **/ cmd.function = 0; - cmd.address = 0x10f; + cmd.address = WILC_SDIO_FBR_DATA_REG; } else { /** - * has to be word aligned... - **/ - if (size & 0x3) { - size += 4; - size &= ~0x3; - } - - /** * func 1 access **/ cmd.function = 1; - cmd.address = 0; + cmd.address = WILC_SDIO_F1_DATA_REG; } + size = ALIGN(size, 4); nblk = size / block_size; nleft = size % block_size; @@ -502,7 +454,7 @@ static int wilc_sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) struct wilc_sdio *sdio_priv = wilc->bus_data; int ret; - if (addr >= 0xf0 && addr <= 0xff) { + if (addr >= 0xf0 && addr <= 0xff) { /* only vendor specific registers */ struct sdio_cmd52 cmd; cmd.read_write = 0; @@ -525,7 +477,7 @@ static int wilc_sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data) cmd.read_write = 0; cmd.function = 0; - cmd.address = 0x10f; + cmd.address = WILC_SDIO_FBR_DATA_REG; cmd.block_mode = 0; cmd.increment = 1; cmd.count = 4; @@ -555,34 +507,19 @@ static int wilc_sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) cmd.read_write = 0; if (addr > 0) { /** - * has to be word aligned... - **/ - if (size & 0x3) { - size += 4; - size &= ~0x3; - } - - /** * func 0 access **/ cmd.function = 0; - cmd.address = 0x10f; + cmd.address = WILC_SDIO_FBR_DATA_REG; } else { /** - * has to be word aligned... - **/ - if (size & 0x3) { - size += 4; - size &= ~0x3; - } - - /** * func 1 access **/ cmd.function = 1; - cmd.address = 0; + cmd.address = WILC_SDIO_F1_DATA_REG; } + size = ALIGN(size, 4); nblk = size / block_size; nleft = size % block_size; @@ -651,17 +588,14 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) int loop, ret; u32 chipid; - if (!resume) - sdio_priv->irq_gpio = wilc->dev_irq_num; - /** * function 0 csa enable **/ cmd.read_write = 1; cmd.function = 0; cmd.raw = 1; - cmd.address = 0x100; - cmd.data = 0x80; + cmd.address = SDIO_FBR_BASE(func->num); + cmd.data = SDIO_FBR_ENABLE_CSA; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, "Fail cmd 52, enable csa...\n"); @@ -671,7 +605,7 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) /** * function 0 block size **/ - ret = wilc_sdio_set_func0_block_size(wilc, WILC_SDIO_BLOCK_SIZE); + ret = wilc_sdio_set_block_size(wilc, 0, WILC_SDIO_BLOCK_SIZE); if (ret) { dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n"); return ret; @@ -684,8 +618,8 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) cmd.read_write = 1; cmd.function = 0; cmd.raw = 1; - cmd.address = 0x2; - cmd.data = 0x2; + cmd.address = SDIO_CCCR_IOEx; + cmd.data = WILC_SDIO_CCCR_IO_EN_FUNC1; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, @@ -699,7 +633,7 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) cmd.read_write = 0; cmd.function = 0; cmd.raw = 0; - cmd.address = 0x3; + cmd.address = SDIO_CCCR_IORx; loop = 3; do { cmd.data = 0; @@ -709,7 +643,7 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) "Fail cmd 52, get IOR register...\n"); return ret; } - if (cmd.data == 0x2) + if (cmd.data == WILC_SDIO_CCCR_IO_EN_FUNC1) break; } while (loop--); @@ -721,7 +655,7 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) /** * func 1 is ready, set func 1 block size **/ - ret = wilc_sdio_set_func1_block_size(wilc, WILC_SDIO_BLOCK_SIZE); + ret = wilc_sdio_set_block_size(wilc, 1, WILC_SDIO_BLOCK_SIZE); if (ret) { dev_err(&func->dev, "Fail set func 1 block size...\n"); return ret; @@ -733,8 +667,8 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) cmd.read_write = 1; cmd.function = 0; cmd.raw = 1; - cmd.address = 0x4; - cmd.data = 0x3; + cmd.address = SDIO_CCCR_IENx; + cmd.data = WILC_SDIO_CCCR_IEN_MASTER | WILC_SDIO_CCCR_IEN_FUNC1; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, "Fail cmd 52, set IEN register...\n"); @@ -745,13 +679,16 @@ static int wilc_sdio_init(struct wilc *wilc, bool resume) * make sure can read back chip id correctly **/ if (!resume) { - ret = wilc_sdio_read_reg(wilc, 0x1000, &chipid); + int rev; + + ret = wilc_sdio_read_reg(wilc, WILC_CHIPID, &chipid); if (ret) { dev_err(&func->dev, "Fail cmd read chip id...\n"); return ret; } dev_err(&func->dev, "chipid (%08x)\n", chipid); - if ((chipid & 0xfff) > 0x2a0) + rev = FIELD_GET(WILC_CHIP_REV_FIELD, chipid); + if (rev > FIELD_GET(WILC_CHIP_REV_FIELD, WILC_1000_BASE_ID_2A)) sdio_priv->has_thrpt_enh3 = 1; else sdio_priv->has_thrpt_enh3 = 0; @@ -773,12 +710,12 @@ static int wilc_sdio_read_size(struct wilc *wilc, u32 *size) cmd.read_write = 0; cmd.function = 0; cmd.raw = 0; - cmd.address = 0xf2; + cmd.address = WILC_SDIO_INTERRUPT_DATA_SZ_REG; cmd.data = 0; wilc_sdio_cmd52(wilc, &cmd); tmp = cmd.data; - cmd.address = 0xf3; + cmd.address = WILC_SDIO_INTERRUPT_DATA_SZ_REG + 1; cmd.data = 0; wilc_sdio_cmd52(wilc, &cmd); tmp |= (cmd.data << 8); @@ -792,6 +729,7 @@ static int wilc_sdio_read_int(struct wilc *wilc, u32 *int_status) struct sdio_func *func = dev_to_sdio_func(wilc->dev); struct wilc_sdio *sdio_priv = wilc->bus_data; u32 tmp; + u8 irq_flags; struct sdio_cmd52 cmd; wilc_sdio_read_size(wilc, &tmp); @@ -800,46 +738,22 @@ static int wilc_sdio_read_int(struct wilc *wilc, u32 *int_status) * Read IRQ flags **/ if (!sdio_priv->irq_gpio) { - int i; - - cmd.read_write = 0; cmd.function = 1; - cmd.address = 0x04; - cmd.data = 0; - wilc_sdio_cmd52(wilc, &cmd); - - if (cmd.data & BIT(0)) - tmp |= INT_0; - if (cmd.data & BIT(2)) - tmp |= INT_1; - if (cmd.data & BIT(3)) - tmp |= INT_2; - if (cmd.data & BIT(4)) - tmp |= INT_3; - if (cmd.data & BIT(5)) - tmp |= INT_4; - if (cmd.data & BIT(6)) - tmp |= INT_5; - for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) { - if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) { - dev_err(&func->dev, - "Unexpected interrupt (1) : tmp=%x, data=%x\n", - tmp, cmd.data); - break; - } - } + cmd.address = WILC_SDIO_EXT_IRQ_FLAG_REG; } else { - u32 irq_flags; - - cmd.read_write = 0; cmd.function = 0; - cmd.raw = 0; - cmd.address = 0xf7; - cmd.data = 0; - wilc_sdio_cmd52(wilc, &cmd); - irq_flags = cmd.data & 0x1f; - tmp |= ((irq_flags >> 0) << IRG_FLAGS_OFFSET); + cmd.address = WILC_SDIO_IRQ_FLAG_REG; } + cmd.raw = 0; + cmd.read_write = 0; + cmd.data = 0; + wilc_sdio_cmd52(wilc, &cmd); + irq_flags = cmd.data; + tmp |= FIELD_PREP(IRG_FLAGS_MASK, cmd.data); + + if (FIELD_GET(UNHANDLED_IRQ_MASK, irq_flags)) + dev_err(&func->dev, "Unexpected interrupt (1) int=%lx\n", + FIELD_GET(UNHANDLED_IRQ_MASK, irq_flags)); *int_status = tmp; @@ -854,16 +768,11 @@ static int wilc_sdio_clear_int_ext(struct wilc *wilc, u32 val) int vmm_ctl; if (sdio_priv->has_thrpt_enh3) { - u32 reg; + u32 reg = 0; - if (sdio_priv->irq_gpio) { - u32 flags; + if (sdio_priv->irq_gpio) + reg = val & (BIT(MAX_NUM_INT) - 1); - flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1); - reg = flags; - } else { - reg = 0; - } /* select VMM table 0 */ if (val & SEL_VMM_TBL0) reg |= BIT(5); @@ -879,14 +788,14 @@ static int wilc_sdio_clear_int_ext(struct wilc *wilc, u32 val) cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; - cmd.address = 0xf8; + cmd.address = WILC_SDIO_IRQ_CLEAR_FLAG_REG; cmd.data = reg; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, - "Failed cmd52, set 0xf8 data (%d) ...\n", - __LINE__); + "Failed cmd52, set (%02x) data (%d) ...\n", + cmd.address, __LINE__); return ret; } } @@ -899,38 +808,36 @@ static int wilc_sdio_clear_int_ext(struct wilc *wilc, u32 val) * Must clear each interrupt individually. */ u32 flags; + int i; flags = val & (BIT(MAX_NUM_INT) - 1); - if (flags) { - int i; - - for (i = 0; i < sdio_priv->nint; i++) { - if (flags & 1) { - struct sdio_cmd52 cmd; - - cmd.read_write = 1; - cmd.function = 0; - cmd.raw = 0; - cmd.address = 0xf8; - cmd.data = BIT(i); - - ret = wilc_sdio_cmd52(wilc, &cmd); - if (ret) { - dev_err(&func->dev, - "Failed cmd52, set 0xf8 data (%d) ...\n", - __LINE__); - return ret; - } + for (i = 0; i < NUM_INT_EXT && flags; i++) { + if (flags & BIT(i)) { + struct sdio_cmd52 cmd; + + cmd.read_write = 1; + cmd.function = 0; + cmd.raw = 0; + cmd.address = WILC_SDIO_IRQ_CLEAR_FLAG_REG; + cmd.data = BIT(i); + + ret = wilc_sdio_cmd52(wilc, &cmd); + if (ret) { + dev_err(&func->dev, + "Failed cmd52, set (%02x) data (%d) ...\n", + cmd.address, __LINE__); + return ret; } - flags >>= 1; + flags &= ~BIT(i); } + } - for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) { - if (flags & 1) - dev_err(&func->dev, - "Unexpected interrupt cleared %d...\n", - i); - flags >>= 1; + for (i = NUM_INT_EXT; i < MAX_NUM_INT && flags; i++) { + if (flags & BIT(i)) { + dev_err(&func->dev, + "Unexpected interrupt cleared %d...\n", + i); + flags &= ~BIT(i); } } } @@ -952,13 +859,13 @@ static int wilc_sdio_clear_int_ext(struct wilc *wilc, u32 val) cmd.read_write = 1; cmd.function = 0; cmd.raw = 0; - cmd.address = 0xf6; + cmd.address = WILC_SDIO_VMM_TBL_CTRL_REG; cmd.data = vmm_ctl; ret = wilc_sdio_cmd52(wilc, &cmd); if (ret) { dev_err(&func->dev, - "Failed cmd52, set 0xf6 data (%d) ...\n", - __LINE__); + "Failed cmd52, set (%02x) data (%d) ...\n", + cmd.address, __LINE__); return ret; } } @@ -975,13 +882,6 @@ static int wilc_sdio_sync_ext(struct wilc *wilc, int nint) dev_err(&func->dev, "Too many interrupts (%d)...\n", nint); return -EINVAL; } - if (nint > MAX_NUN_INT_THRPT_ENH2) { - dev_err(&func->dev, - "Cannot support more than 5 interrupts when has_thrpt_enh2=1.\n"); - return -EINVAL; - } - - sdio_priv->nint = nint; /** * Disable power sequencer @@ -1097,7 +997,7 @@ static int wilc_sdio_resume(struct device *dev) } static const struct of_device_id wilc_of_match[] = { - { .compatible = "microchip,wilc1000-sdio", }, + { .compatible = "microchip,wilc1000", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, wilc_of_match); diff --git a/drivers/staging/wilc1000/spi.c b/drivers/staging/wilc1000/spi.c index 3ffc7b4fddf6..3f19e3f38a39 100644 --- a/drivers/staging/wilc1000/spi.c +++ b/drivers/staging/wilc1000/spi.c @@ -6,72 +6,19 @@ #include <linux/clk.h> #include <linux/spi/spi.h> +#include <linux/crc7.h> #include "netdev.h" #include "cfg80211.h" struct wilc_spi { int crc_off; - int nint; }; static const struct wilc_hif_func wilc_hif_spi; /******************************************** * - * Crc7 - * - ********************************************/ - -static const u8 crc7_syndrome_table[256] = { - 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f, - 0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77, - 0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26, - 0x51, 0x58, 0x43, 0x4a, 0x75, 0x7c, 0x67, 0x6e, - 0x32, 0x3b, 0x20, 0x29, 0x16, 0x1f, 0x04, 0x0d, - 0x7a, 0x73, 0x68, 0x61, 0x5e, 0x57, 0x4c, 0x45, - 0x2b, 0x22, 0x39, 0x30, 0x0f, 0x06, 0x1d, 0x14, - 0x63, 0x6a, 0x71, 0x78, 0x47, 0x4e, 0x55, 0x5c, - 0x64, 0x6d, 0x76, 0x7f, 0x40, 0x49, 0x52, 0x5b, - 0x2c, 0x25, 0x3e, 0x37, 0x08, 0x01, 0x1a, 0x13, - 0x7d, 0x74, 0x6f, 0x66, 0x59, 0x50, 0x4b, 0x42, - 0x35, 0x3c, 0x27, 0x2e, 0x11, 0x18, 0x03, 0x0a, - 0x56, 0x5f, 0x44, 0x4d, 0x72, 0x7b, 0x60, 0x69, - 0x1e, 0x17, 0x0c, 0x05, 0x3a, 0x33, 0x28, 0x21, - 0x4f, 0x46, 0x5d, 0x54, 0x6b, 0x62, 0x79, 0x70, - 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31, 0x38, - 0x41, 0x48, 0x53, 0x5a, 0x65, 0x6c, 0x77, 0x7e, - 0x09, 0x00, 0x1b, 0x12, 0x2d, 0x24, 0x3f, 0x36, - 0x58, 0x51, 0x4a, 0x43, 0x7c, 0x75, 0x6e, 0x67, - 0x10, 0x19, 0x02, 0x0b, 0x34, 0x3d, 0x26, 0x2f, - 0x73, 0x7a, 0x61, 0x68, 0x57, 0x5e, 0x45, 0x4c, - 0x3b, 0x32, 0x29, 0x20, 0x1f, 0x16, 0x0d, 0x04, - 0x6a, 0x63, 0x78, 0x71, 0x4e, 0x47, 0x5c, 0x55, - 0x22, 0x2b, 0x30, 0x39, 0x06, 0x0f, 0x14, 0x1d, - 0x25, 0x2c, 0x37, 0x3e, 0x01, 0x08, 0x13, 0x1a, - 0x6d, 0x64, 0x7f, 0x76, 0x49, 0x40, 0x5b, 0x52, - 0x3c, 0x35, 0x2e, 0x27, 0x18, 0x11, 0x0a, 0x03, - 0x74, 0x7d, 0x66, 0x6f, 0x50, 0x59, 0x42, 0x4b, - 0x17, 0x1e, 0x05, 0x0c, 0x33, 0x3a, 0x21, 0x28, - 0x5f, 0x56, 0x4d, 0x44, 0x7b, 0x72, 0x69, 0x60, - 0x0e, 0x07, 0x1c, 0x15, 0x2a, 0x23, 0x38, 0x31, - 0x46, 0x4f, 0x54, 0x5d, 0x62, 0x6b, 0x70, 0x79 -}; - -static u8 crc7_byte(u8 crc, u8 data) -{ - return crc7_syndrome_table[(crc << 1) ^ data]; -} - -static u8 crc7(u8 crc, const u8 *buffer, u32 len) -{ - while (len--) - crc = crc7_byte(crc, *buffer++); - return crc; -} - -/******************************************** - * * Spi protocol Function * ********************************************/ @@ -97,25 +44,62 @@ static u8 crc7(u8 crc, const u8 *buffer, u32 len) #define USE_SPI_DMA 0 +#define WILC_SPI_COMMAND_STAT_SUCCESS 0 +#define WILC_GET_RESP_HDR_START(h) (((h) >> 4) & 0xf) + +struct wilc_spi_cmd { + u8 cmd_type; + union { + struct { + u8 addr[3]; + u8 crc[]; + } __packed simple_cmd; + struct { + u8 addr[3]; + u8 size[2]; + u8 crc[]; + } __packed dma_cmd; + struct { + u8 addr[3]; + u8 size[3]; + u8 crc[]; + } __packed dma_cmd_ext; + struct { + u8 addr[2]; + __be32 data; + u8 crc[]; + } __packed internal_w_cmd; + struct { + u8 addr[3]; + __be32 data; + u8 crc[]; + } __packed w_cmd; + } u; +} __packed; + +struct wilc_spi_read_rsp_data { + u8 rsp_cmd_type; + u8 status; + u8 resp_header; + u8 resp_data[4]; + u8 crc[]; +} __packed; + +struct wilc_spi_rsp_data { + u8 rsp_cmd_type; + u8 status; +} __packed; + static int wilc_bus_probe(struct spi_device *spi) { int ret; struct wilc *wilc; - struct gpio_desc *gpio; struct wilc_spi *spi_priv; spi_priv = kzalloc(sizeof(*spi_priv), GFP_KERNEL); if (!spi_priv) return -ENOMEM; - gpio = gpiod_get(&spi->dev, "irq", GPIOD_IN); - if (IS_ERR(gpio)) { - /* get the GPIO descriptor from hardcode GPIO number */ - gpio = gpio_to_desc(GPIO_NUM); - if (!gpio) - dev_err(&spi->dev, "failed to get the irq gpio\n"); - } - ret = wilc_cfg80211_init(&wilc, &spi->dev, WILC_HIF_SPI, &wilc_hif_spi); if (ret) { kfree(spi_priv); @@ -125,7 +109,7 @@ static int wilc_bus_probe(struct spi_device *spi) spi_set_drvdata(spi, wilc); wilc->dev = &spi->dev; wilc->bus_data = spi_priv; - wilc->gpio_irq = gpio; + wilc->dev_irq_num = spi->irq; wilc->rtc_clk = devm_clk_get(&spi->dev, "rtc_clk"); if (PTR_ERR_OR_ZERO(wilc->rtc_clk) == -EPROBE_DEFER) @@ -140,10 +124,6 @@ static int wilc_bus_remove(struct spi_device *spi) { struct wilc *wilc = spi_get_drvdata(spi); - /* free the GPIO in module remove */ - if (wilc->gpio_irq) - gpiod_put(wilc->gpio_irq); - if (!IS_ERR(wilc->rtc_clk)) clk_disable_unprepare(wilc->rtc_clk); @@ -152,7 +132,7 @@ static int wilc_bus_remove(struct spi_device *spi) } static const struct of_device_id wilc_of_match[] = { - { .compatible = "microchip,wilc1000-spi", }, + { .compatible = "microchip,wilc1000", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, wilc_of_match); @@ -178,7 +158,10 @@ static int wilc_spi_tx(struct wilc *wilc, u8 *b, u32 len) struct spi_transfer tr = { .tx_buf = b, .len = len, - .delay_usecs = 0, + .delay = { + .value = 0, + .unit = SPI_DELAY_UNIT_USECS + }, }; char *r_buffer = kzalloc(len, GFP_KERNEL); @@ -219,7 +202,10 @@ static int wilc_spi_rx(struct wilc *wilc, u8 *rb, u32 rlen) struct spi_transfer tr = { .rx_buf = rb, .len = rlen, - .delay_usecs = 0, + .delay = { + .value = 0, + .unit = SPI_DELAY_UNIT_USECS + }, }; char *t_buffer = kzalloc(rlen, GFP_KERNEL); @@ -261,7 +247,10 @@ static int wilc_spi_tx_rx(struct wilc *wilc, u8 *wb, u8 *rb, u32 rlen) .tx_buf = wb, .len = rlen, .bits_per_word = 8, - .delay_usecs = 0, + .delay = { + .value = 0, + .unit = SPI_DELAY_UNIT_USECS + }, }; @@ -284,335 +273,6 @@ static int wilc_spi_tx_rx(struct wilc *wilc, u8 *wb, u8 *rb, u32 rlen) return ret; } -static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz, - u8 clockless) -{ - struct spi_device *spi = to_spi_device(wilc->dev); - struct wilc_spi *spi_priv = wilc->bus_data; - u8 wb[32], rb[32]; - u8 wix, rix; - u32 len2; - u8 rsp; - int len = 0; - int result = 0; - int retry; - u8 crc[2]; - - wb[0] = cmd; - switch (cmd) { - case CMD_SINGLE_READ: /* single word (4 bytes) read */ - wb[1] = (u8)(adr >> 16); - wb[2] = (u8)(adr >> 8); - wb[3] = (u8)adr; - len = 5; - break; - - case CMD_INTERNAL_READ: /* internal register read */ - wb[1] = (u8)(adr >> 8); - if (clockless == 1) - wb[1] |= BIT(7); - wb[2] = (u8)adr; - wb[3] = 0x00; - len = 5; - break; - - case CMD_TERMINATE: - wb[1] = 0x00; - wb[2] = 0x00; - wb[3] = 0x00; - len = 5; - break; - - case CMD_REPEAT: - wb[1] = 0x00; - wb[2] = 0x00; - wb[3] = 0x00; - len = 5; - break; - - case CMD_RESET: - wb[1] = 0xff; - wb[2] = 0xff; - wb[3] = 0xff; - len = 5; - break; - - case CMD_DMA_WRITE: /* dma write */ - case CMD_DMA_READ: /* dma read */ - wb[1] = (u8)(adr >> 16); - wb[2] = (u8)(adr >> 8); - wb[3] = (u8)adr; - wb[4] = (u8)(sz >> 8); - wb[5] = (u8)(sz); - len = 7; - break; - - case CMD_DMA_EXT_WRITE: /* dma extended write */ - case CMD_DMA_EXT_READ: /* dma extended read */ - wb[1] = (u8)(adr >> 16); - wb[2] = (u8)(adr >> 8); - wb[3] = (u8)adr; - wb[4] = (u8)(sz >> 16); - wb[5] = (u8)(sz >> 8); - wb[6] = (u8)(sz); - len = 8; - break; - - case CMD_INTERNAL_WRITE: /* internal register write */ - wb[1] = (u8)(adr >> 8); - if (clockless == 1) - wb[1] |= BIT(7); - wb[2] = (u8)(adr); - wb[3] = b[3]; - wb[4] = b[2]; - wb[5] = b[1]; - wb[6] = b[0]; - len = 8; - break; - - case CMD_SINGLE_WRITE: /* single word write */ - wb[1] = (u8)(adr >> 16); - wb[2] = (u8)(adr >> 8); - wb[3] = (u8)(adr); - wb[4] = b[3]; - wb[5] = b[2]; - wb[6] = b[1]; - wb[7] = b[0]; - len = 9; - break; - - default: - result = -EINVAL; - break; - } - - if (result) - return result; - - if (!spi_priv->crc_off) - wb[len - 1] = (crc7(0x7f, (const u8 *)&wb[0], len - 1)) << 1; - else - len -= 1; - -#define NUM_SKIP_BYTES (1) -#define NUM_RSP_BYTES (2) -#define NUM_DATA_HDR_BYTES (1) -#define NUM_DATA_BYTES (4) -#define NUM_CRC_BYTES (2) -#define NUM_DUMMY_BYTES (3) - if (cmd == CMD_RESET || - cmd == CMD_TERMINATE || - cmd == CMD_REPEAT) { - len2 = len + (NUM_SKIP_BYTES + NUM_RSP_BYTES + NUM_DUMMY_BYTES); - } else if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) { - int tmp = NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES - + NUM_DUMMY_BYTES; - if (!spi_priv->crc_off) - len2 = len + tmp + NUM_CRC_BYTES; - else - len2 = len + tmp; - } else { - len2 = len + (NUM_RSP_BYTES + NUM_DUMMY_BYTES); - } -#undef NUM_DUMMY_BYTES - - if (len2 > ARRAY_SIZE(wb)) { - dev_err(&spi->dev, "spi buffer size too small (%d) (%zu)\n", - len2, ARRAY_SIZE(wb)); - return -EINVAL; - } - /* zero spi write buffers. */ - for (wix = len; wix < len2; wix++) - wb[wix] = 0; - rix = len; - - if (wilc_spi_tx_rx(wilc, wb, rb, len2)) { - dev_err(&spi->dev, "Failed cmd write, bus error...\n"); - return -EINVAL; - } - - /* - * Command/Control response - */ - if (cmd == CMD_RESET || cmd == CMD_TERMINATE || cmd == CMD_REPEAT) - rix++; /* skip 1 byte */ - - rsp = rb[rix++]; - - if (rsp != cmd) { - dev_err(&spi->dev, - "Failed cmd response, cmd (%02x), resp (%02x)\n", - cmd, rsp); - return -EINVAL; - } - - /* - * State response - */ - rsp = rb[rix++]; - if (rsp != 0x00) { - dev_err(&spi->dev, "Failed cmd state response state (%02x)\n", - rsp); - return -EINVAL; - } - - if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ || - cmd == CMD_DMA_READ || cmd == CMD_DMA_EXT_READ) { - /* - * Data Respnose header - */ - retry = 100; - do { - /* - * ensure there is room in buffer later - * to read data and crc - */ - if (rix < len2) { - rsp = rb[rix++]; - } else { - retry = 0; - break; - } - if (((rsp >> 4) & 0xf) == 0xf) - break; - } while (retry--); - - if (retry <= 0) { - dev_err(&spi->dev, - "Error, data read response (%02x)\n", rsp); - return -EAGAIN; - } - } - - if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) { - /* - * Read bytes - */ - if ((rix + 3) < len2) { - b[0] = rb[rix++]; - b[1] = rb[rix++]; - b[2] = rb[rix++]; - b[3] = rb[rix++]; - } else { - dev_err(&spi->dev, - "buffer overrun when reading data.\n"); - return -EINVAL; - } - - if (!spi_priv->crc_off) { - /* - * Read Crc - */ - if ((rix + 1) < len2) { - crc[0] = rb[rix++]; - crc[1] = rb[rix++]; - } else { - dev_err(&spi->dev, - "buffer overrun when reading crc.\n"); - return -EINVAL; - } - } - } else if ((cmd == CMD_DMA_READ) || (cmd == CMD_DMA_EXT_READ)) { - int ix; - - /* some data may be read in response to dummy bytes. */ - for (ix = 0; (rix < len2) && (ix < sz); ) - b[ix++] = rb[rix++]; - - sz -= ix; - - if (sz > 0) { - int nbytes; - - if (sz <= (DATA_PKT_SZ - ix)) - nbytes = sz; - else - nbytes = DATA_PKT_SZ - ix; - - /* - * Read bytes - */ - if (wilc_spi_rx(wilc, &b[ix], nbytes)) { - dev_err(&spi->dev, - "Failed block read, bus err\n"); - return -EINVAL; - } - - /* - * Read Crc - */ - if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) { - dev_err(&spi->dev, - "Failed block crc read, bus err\n"); - return -EINVAL; - } - - ix += nbytes; - sz -= nbytes; - } - - /* - * if any data in left unread, - * then read the rest using normal DMA code. - */ - while (sz > 0) { - int nbytes; - - if (sz <= DATA_PKT_SZ) - nbytes = sz; - else - nbytes = DATA_PKT_SZ; - - /* - * read data response only on the next DMA cycles not - * the first DMA since data response header is already - * handled above for the first DMA. - */ - /* - * Data Respnose header - */ - retry = 10; - do { - if (wilc_spi_rx(wilc, &rsp, 1)) { - dev_err(&spi->dev, - "Failed resp read, bus err\n"); - result = -EINVAL; - break; - } - if (((rsp >> 4) & 0xf) == 0xf) - break; - } while (retry--); - - if (result) - break; - - /* - * Read bytes - */ - if (wilc_spi_rx(wilc, &b[ix], nbytes)) { - dev_err(&spi->dev, - "Failed block read, bus err\n"); - result = -EINVAL; - break; - } - - /* - * Read Crc - */ - if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) { - dev_err(&spi->dev, - "Failed block crc read, bus err\n"); - result = -EINVAL; - break; - } - - ix += nbytes; - sz -= nbytes; - } - } - return result; -} - static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz) { struct spi_device *spi = to_spi_device(wilc->dev); @@ -686,19 +346,333 @@ static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz) * Spi Internal Read/Write Function * ********************************************/ +static u8 wilc_get_crc7(u8 *buffer, u32 len) +{ + return crc7_be(0xfe, buffer, len); +} + +static int wilc_spi_single_read(struct wilc *wilc, u8 cmd, u32 adr, void *b, + u8 clockless) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + struct wilc_spi *spi_priv = wilc->bus_data; + u8 wb[32], rb[32]; + int cmd_len, resp_len; + u8 crc[2]; + struct wilc_spi_cmd *c; + struct wilc_spi_read_rsp_data *r; + + memset(wb, 0x0, sizeof(wb)); + memset(rb, 0x0, sizeof(rb)); + c = (struct wilc_spi_cmd *)wb; + c->cmd_type = cmd; + if (cmd == CMD_SINGLE_READ) { + c->u.simple_cmd.addr[0] = adr >> 16; + c->u.simple_cmd.addr[1] = adr >> 8; + c->u.simple_cmd.addr[2] = adr; + } else if (cmd == CMD_INTERNAL_READ) { + c->u.simple_cmd.addr[0] = adr >> 8; + if (clockless == 1) + c->u.simple_cmd.addr[0] |= BIT(7); + c->u.simple_cmd.addr[1] = adr; + c->u.simple_cmd.addr[2] = 0x0; + } else { + dev_err(&spi->dev, "cmd [%x] not supported\n", cmd); + return -EINVAL; + } + + cmd_len = offsetof(struct wilc_spi_cmd, u.simple_cmd.crc); + resp_len = sizeof(*r); + if (!spi_priv->crc_off) { + c->u.simple_cmd.crc[0] = wilc_get_crc7(wb, cmd_len); + cmd_len += 1; + resp_len += 2; + } + + if (cmd_len + resp_len > ARRAY_SIZE(wb)) { + dev_err(&spi->dev, + "spi buffer size too small (%d) (%d) (%zu)\n", + cmd_len, resp_len, ARRAY_SIZE(wb)); + return -EINVAL; + } + + if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) { + dev_err(&spi->dev, "Failed cmd write, bus error...\n"); + return -EINVAL; + } + + r = (struct wilc_spi_read_rsp_data *)&rb[cmd_len]; + if (r->rsp_cmd_type != cmd) { + dev_err(&spi->dev, + "Failed cmd response, cmd (%02x), resp (%02x)\n", + cmd, r->rsp_cmd_type); + return -EINVAL; + } + + if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) { + dev_err(&spi->dev, "Failed cmd state response state (%02x)\n", + r->status); + return -EINVAL; + } + + if (WILC_GET_RESP_HDR_START(r->resp_header) != 0xf) { + dev_err(&spi->dev, "Error, data read response (%02x)\n", + r->resp_header); + return -EINVAL; + } + + if (b) + memcpy(b, r->resp_data, 4); + + if (!spi_priv->crc_off) + memcpy(crc, r->crc, 2); + + return 0; +} + +static int wilc_spi_write_cmd(struct wilc *wilc, u8 cmd, u32 adr, u32 data, + u8 clockless) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + struct wilc_spi *spi_priv = wilc->bus_data; + u8 wb[32], rb[32]; + int cmd_len, resp_len; + struct wilc_spi_cmd *c; + struct wilc_spi_rsp_data *r; + + memset(wb, 0x0, sizeof(wb)); + memset(rb, 0x0, sizeof(rb)); + c = (struct wilc_spi_cmd *)wb; + c->cmd_type = cmd; + if (cmd == CMD_INTERNAL_WRITE) { + c->u.internal_w_cmd.addr[0] = adr >> 8; + if (clockless == 1) + c->u.internal_w_cmd.addr[0] |= BIT(7); + + c->u.internal_w_cmd.addr[1] = adr; + c->u.internal_w_cmd.data = cpu_to_be32(data); + cmd_len = offsetof(struct wilc_spi_cmd, u.internal_w_cmd.crc); + if (!spi_priv->crc_off) + c->u.internal_w_cmd.crc[0] = wilc_get_crc7(wb, cmd_len); + } else if (cmd == CMD_SINGLE_WRITE) { + c->u.w_cmd.addr[0] = adr >> 16; + c->u.w_cmd.addr[1] = adr >> 8; + c->u.w_cmd.addr[2] = adr; + c->u.w_cmd.data = cpu_to_be32(data); + cmd_len = offsetof(struct wilc_spi_cmd, u.w_cmd.crc); + if (!spi_priv->crc_off) + c->u.w_cmd.crc[0] = wilc_get_crc7(wb, cmd_len); + } else { + dev_err(&spi->dev, "write cmd [%x] not supported\n", cmd); + return -EINVAL; + } + + if (!spi_priv->crc_off) + cmd_len += 1; + + resp_len = sizeof(*r); + + if (cmd_len + resp_len > ARRAY_SIZE(wb)) { + dev_err(&spi->dev, + "spi buffer size too small (%d) (%d) (%zu)\n", + cmd_len, resp_len, ARRAY_SIZE(wb)); + return -EINVAL; + } + + if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) { + dev_err(&spi->dev, "Failed cmd write, bus error...\n"); + return -EINVAL; + } + + r = (struct wilc_spi_rsp_data *)&rb[cmd_len]; + if (r->rsp_cmd_type != cmd) { + dev_err(&spi->dev, + "Failed cmd response, cmd (%02x), resp (%02x)\n", + cmd, r->rsp_cmd_type); + return -EINVAL; + } + + if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) { + dev_err(&spi->dev, "Failed cmd state response state (%02x)\n", + r->status); + return -EINVAL; + } + + return 0; +} + +static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + struct wilc_spi *spi_priv = wilc->bus_data; + u8 wb[32], rb[32]; + int cmd_len, resp_len; + int retry, ix = 0; + u8 crc[2]; + struct wilc_spi_cmd *c; + struct wilc_spi_rsp_data *r; + + memset(wb, 0x0, sizeof(wb)); + memset(rb, 0x0, sizeof(rb)); + c = (struct wilc_spi_cmd *)wb; + c->cmd_type = cmd; + if (cmd == CMD_DMA_WRITE || cmd == CMD_DMA_READ) { + c->u.dma_cmd.addr[0] = adr >> 16; + c->u.dma_cmd.addr[1] = adr >> 8; + c->u.dma_cmd.addr[2] = adr; + c->u.dma_cmd.size[0] = sz >> 8; + c->u.dma_cmd.size[1] = sz; + cmd_len = offsetof(struct wilc_spi_cmd, u.dma_cmd.crc); + if (!spi_priv->crc_off) + c->u.dma_cmd.crc[0] = wilc_get_crc7(wb, cmd_len); + } else if (cmd == CMD_DMA_EXT_WRITE || cmd == CMD_DMA_EXT_READ) { + c->u.dma_cmd_ext.addr[0] = adr >> 16; + c->u.dma_cmd_ext.addr[1] = adr >> 8; + c->u.dma_cmd_ext.addr[2] = adr; + c->u.dma_cmd_ext.size[0] = sz >> 16; + c->u.dma_cmd_ext.size[1] = sz >> 8; + c->u.dma_cmd_ext.size[2] = sz; + cmd_len = offsetof(struct wilc_spi_cmd, u.dma_cmd_ext.crc); + if (!spi_priv->crc_off) + c->u.dma_cmd_ext.crc[0] = wilc_get_crc7(wb, cmd_len); + } else { + dev_err(&spi->dev, "dma read write cmd [%x] not supported\n", + cmd); + return -EINVAL; + } + if (!spi_priv->crc_off) + cmd_len += 1; + + resp_len = sizeof(*r); + + if (cmd_len + resp_len > ARRAY_SIZE(wb)) { + dev_err(&spi->dev, "spi buffer size too small (%d)(%d) (%zu)\n", + cmd_len, resp_len, ARRAY_SIZE(wb)); + return -EINVAL; + } + + if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) { + dev_err(&spi->dev, "Failed cmd write, bus error...\n"); + return -EINVAL; + } + + r = (struct wilc_spi_rsp_data *)&rb[cmd_len]; + if (r->rsp_cmd_type != cmd) { + dev_err(&spi->dev, + "Failed cmd response, cmd (%02x), resp (%02x)\n", + cmd, r->rsp_cmd_type); + return -EINVAL; + } + + if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) { + dev_err(&spi->dev, "Failed cmd state response state (%02x)\n", + r->status); + return -EINVAL; + } + + if (cmd == CMD_DMA_WRITE || cmd == CMD_DMA_EXT_WRITE) + return 0; + + while (sz > 0) { + int nbytes; + u8 rsp; + + if (sz <= DATA_PKT_SZ) + nbytes = sz; + else + nbytes = DATA_PKT_SZ; + + /* + * Data Response header + */ + retry = 100; + do { + if (wilc_spi_rx(wilc, &rsp, 1)) { + dev_err(&spi->dev, + "Failed resp read, bus err\n"); + return -EINVAL; + } + if (WILC_GET_RESP_HDR_START(rsp) == 0xf) + break; + } while (retry--); + + /* + * Read bytes + */ + if (wilc_spi_rx(wilc, &b[ix], nbytes)) { + dev_err(&spi->dev, + "Failed block read, bus err\n"); + return -EINVAL; + } + + /* + * Read Crc + */ + if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) { + dev_err(&spi->dev, + "Failed block crc read, bus err\n"); + return -EINVAL; + } + + ix += nbytes; + sz -= nbytes; + } + return 0; +} + +static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + int result; + u8 cmd = CMD_SINGLE_READ; + u8 clockless = 0; + + if (addr < WILC_SPI_CLOCKLESS_ADDR_LIMIT) { + /* Clockless register */ + cmd = CMD_INTERNAL_READ; + clockless = 1; + } + + result = wilc_spi_single_read(wilc, cmd, addr, data, clockless); + if (result) { + dev_err(&spi->dev, "Failed cmd, read reg (%08x)...\n", addr); + return result; + } + + le32_to_cpus(data); + + return 0; +} + +static int wilc_spi_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) +{ + struct spi_device *spi = to_spi_device(wilc->dev); + int result; + + if (size <= 4) + return -EINVAL; + + result = wilc_spi_dma_rw(wilc, CMD_DMA_EXT_READ, addr, buf, size); + if (result) { + dev_err(&spi->dev, "Failed cmd, read block (%08x)...\n", addr); + return result; + } + + return 0; +} static int spi_internal_write(struct wilc *wilc, u32 adr, u32 dat) { struct spi_device *spi = to_spi_device(wilc->dev); int result; - cpu_to_le32s(&dat); - result = spi_cmd_complete(wilc, CMD_INTERNAL_WRITE, adr, (u8 *)&dat, 4, - 0); - if (result) + result = wilc_spi_write_cmd(wilc, CMD_INTERNAL_WRITE, adr, dat, 0); + if (result) { dev_err(&spi->dev, "Failed internal write cmd...\n"); + return result; + } - return result; + return 0; } static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data) @@ -706,8 +680,7 @@ static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data) struct spi_device *spi = to_spi_device(wilc->dev); int result; - result = spi_cmd_complete(wilc, CMD_INTERNAL_READ, adr, (u8 *)data, 4, - 0); + result = wilc_spi_single_read(wilc, CMD_INTERNAL_READ, adr, data, 0); if (result) { dev_err(&spi->dev, "Failed internal read cmd...\n"); return result; @@ -715,7 +688,7 @@ static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data) le32_to_cpus(data); - return result; + return 0; } /******************************************** @@ -731,18 +704,19 @@ static int wilc_spi_write_reg(struct wilc *wilc, u32 addr, u32 data) u8 cmd = CMD_SINGLE_WRITE; u8 clockless = 0; - cpu_to_le32s(&data); - if (addr < 0x30) { + if (addr < WILC_SPI_CLOCKLESS_ADDR_LIMIT) { /* Clockless register */ cmd = CMD_INTERNAL_WRITE; clockless = 1; } - result = spi_cmd_complete(wilc, cmd, addr, (u8 *)&data, 4, clockless); - if (result) + result = wilc_spi_write_cmd(wilc, cmd, addr, data, clockless); + if (result) { dev_err(&spi->dev, "Failed cmd, write reg (%08x)...\n", addr); + return result; + } - return result; + return 0; } static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) @@ -756,7 +730,7 @@ static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) if (size <= 4) return -EINVAL; - result = spi_cmd_complete(wilc, CMD_DMA_EXT_WRITE, addr, NULL, size, 0); + result = wilc_spi_dma_rw(wilc, CMD_DMA_EXT_WRITE, addr, NULL, size); if (result) { dev_err(&spi->dev, "Failed cmd, write block (%08x)...\n", addr); @@ -767,51 +741,14 @@ static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size) * Data */ result = spi_data_write(wilc, buf, size); - if (result) - dev_err(&spi->dev, "Failed block data write...\n"); - - return result; -} - -static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data) -{ - struct spi_device *spi = to_spi_device(wilc->dev); - int result; - u8 cmd = CMD_SINGLE_READ; - u8 clockless = 0; - - if (addr < 0x30) { - /* Clockless register */ - cmd = CMD_INTERNAL_READ; - clockless = 1; - } - - result = spi_cmd_complete(wilc, cmd, addr, (u8 *)data, 4, clockless); if (result) { - dev_err(&spi->dev, "Failed cmd, read reg (%08x)...\n", addr); + dev_err(&spi->dev, "Failed block data write...\n"); return result; } - le32_to_cpus(data); - return 0; } -static int wilc_spi_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size) -{ - struct spi_device *spi = to_spi_device(wilc->dev); - int result; - - if (size <= 4) - return -EINVAL; - - result = spi_cmd_complete(wilc, CMD_DMA_EXT_READ, addr, buf, size, 0); - if (result) - dev_err(&spi->dev, "Failed cmd, read block (%08x)...\n", addr); - - return result; -} - /******************************************** * * Bus interfaces @@ -836,7 +773,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume) int ret; if (isinit) { - ret = wilc_spi_read_reg(wilc, 0x1000, &chipid); + ret = wilc_spi_read_reg(wilc, WILC_CHIPID, &chipid); if (ret) dev_err(&spi->dev, "Fail cmd read chip id...\n"); @@ -888,7 +825,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume) /* * make sure can read back chip id correctly */ - ret = wilc_spi_read_reg(wilc, 0x1000, &chipid); + ret = wilc_spi_read_reg(wilc, WILC_CHIPID, &chipid); if (ret) { dev_err(&spi->dev, "Fail cmd read chip id...\n"); return ret; @@ -903,26 +840,28 @@ static int wilc_spi_read_size(struct wilc *wilc, u32 *size) { int ret; - ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, size); - *size = *size & IRQ_DMA_WD_CNT_MASK; + ret = spi_internal_read(wilc, + WILC_SPI_INT_STATUS - WILC_SPI_REG_BASE, size); + *size = FIELD_GET(IRQ_DMA_WD_CNT_MASK, *size); return ret; } static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status) { - return spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE, int_status); + return spi_internal_read(wilc, WILC_SPI_INT_STATUS - WILC_SPI_REG_BASE, + int_status); } static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val) { - return spi_internal_write(wilc, 0xe844 - WILC_SPI_REG_BASE, val); + return spi_internal_write(wilc, WILC_SPI_INT_CLEAR - WILC_SPI_REG_BASE, + val); } static int wilc_spi_sync_ext(struct wilc *wilc, int nint) { struct spi_device *spi = to_spi_device(wilc->dev); - struct wilc_spi *spi_priv = wilc->bus_data; u32 reg; int ret, i; @@ -931,8 +870,6 @@ static int wilc_spi_sync_ext(struct wilc *wilc, int nint) return -EINVAL; } - spi_priv->nint = nint; - /* * interrupt pin mux select */ diff --git a/drivers/staging/wilc1000/wlan.c b/drivers/staging/wilc1000/wlan.c index 601e4d1345d2..6a82fb2f283e 100644 --- a/drivers/staging/wilc1000/wlan.c +++ b/drivers/staging/wilc1000/wlan.c @@ -11,7 +11,7 @@ static inline bool is_wilc1000(u32 id) { - return (id & 0xfffff000) == 0x100000; + return (id & (~WILC_CHIP_REV_FIELD)) == WILC_1000_BASE_ID; } static inline void acquire_bus(struct wilc *wilc, enum bus_acquire acquire) @@ -393,62 +393,67 @@ void chip_allow_sleep(struct wilc *wilc) { u32 reg = 0; - wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); + wilc->hif_func->hif_read_reg(wilc, WILC_SDIO_WAKEUP_REG, ®); - wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0)); - wilc->hif_func->hif_write_reg(wilc, 0xfa, 0); + wilc->hif_func->hif_write_reg(wilc, WILC_SDIO_WAKEUP_REG, + reg & ~WILC_SDIO_WAKEUP_BIT); + wilc->hif_func->hif_write_reg(wilc, WILC_SDIO_HOST_TO_FW_REG, 0); } EXPORT_SYMBOL_GPL(chip_allow_sleep); void chip_wakeup(struct wilc *wilc) { u32 reg, clk_status_reg; + const struct wilc_hif_func *h = wilc->hif_func; - if ((wilc->io_type & 0x1) == WILC_HIF_SPI) { + if (wilc->io_type == WILC_HIF_SPI) { do { - wilc->hif_func->hif_read_reg(wilc, 1, ®); - wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1)); - wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1)); + h->hif_read_reg(wilc, WILC_SPI_WAKEUP_REG, ®); + h->hif_write_reg(wilc, WILC_SPI_WAKEUP_REG, + reg | WILC_SPI_WAKEUP_BIT); + h->hif_write_reg(wilc, WILC_SPI_WAKEUP_REG, + reg & ~WILC_SPI_WAKEUP_BIT); do { usleep_range(2000, 2500); wilc_get_chipid(wilc, true); } while (wilc_get_chipid(wilc, true) == 0); } while (wilc_get_chipid(wilc, true) == 0); - } else if ((wilc->io_type & 0x1) == WILC_HIF_SDIO) { - wilc->hif_func->hif_write_reg(wilc, 0xfa, 1); + } else if (wilc->io_type == WILC_HIF_SDIO) { + h->hif_write_reg(wilc, WILC_SDIO_HOST_TO_FW_REG, + WILC_SDIO_HOST_TO_FW_BIT); usleep_range(200, 400); - wilc->hif_func->hif_read_reg(wilc, 0xf0, ®); + h->hif_read_reg(wilc, WILC_SDIO_WAKEUP_REG, ®); do { - wilc->hif_func->hif_write_reg(wilc, 0xf0, - reg | BIT(0)); - wilc->hif_func->hif_read_reg(wilc, 0xf1, - &clk_status_reg); + h->hif_write_reg(wilc, WILC_SDIO_WAKEUP_REG, + reg | WILC_SDIO_WAKEUP_BIT); + h->hif_read_reg(wilc, WILC_SDIO_CLK_STATUS_REG, + &clk_status_reg); - while ((clk_status_reg & 0x1) == 0) { + while (!(clk_status_reg & WILC_SDIO_CLK_STATUS_BIT)) { usleep_range(2000, 2500); - wilc->hif_func->hif_read_reg(wilc, 0xf1, - &clk_status_reg); + h->hif_read_reg(wilc, WILC_SDIO_CLK_STATUS_REG, + &clk_status_reg); } - if ((clk_status_reg & 0x1) == 0) { - wilc->hif_func->hif_write_reg(wilc, 0xf0, - reg & (~BIT(0))); + if (!(clk_status_reg & WILC_SDIO_CLK_STATUS_BIT)) { + h->hif_write_reg(wilc, WILC_SDIO_WAKEUP_REG, + reg & ~WILC_SDIO_WAKEUP_BIT); } - } while ((clk_status_reg & 0x1) == 0); + } while (!(clk_status_reg & WILC_SDIO_CLK_STATUS_BIT)); } if (wilc->chip_ps_state == WILC_CHIP_SLEEPING_MANUAL) { - if (wilc_get_chipid(wilc, false) < 0x1002b0) { + if (wilc_get_chipid(wilc, false) < WILC_1000_BASE_ID_2B) { u32 val32; - wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32); + h->hif_read_reg(wilc, WILC_REG_4_TO_1_RX, &val32); val32 |= BIT(6); - wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32); + h->hif_write_reg(wilc, WILC_REG_4_TO_1_RX, val32); - wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32); + h->hif_read_reg(wilc, WILC_REG_4_TO_1_TX_BANK0, &val32); val32 |= BIT(6); - wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32); + h->hif_write_reg(wilc, WILC_REG_4_TO_1_TX_BANK0, val32); } } wilc->chip_ps_state = WILC_CHIP_WAKEDUP; @@ -458,7 +463,7 @@ EXPORT_SYMBOL_GPL(chip_wakeup); void host_wakeup_notify(struct wilc *wilc) { acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY); - wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1); + wilc->hif_func->hif_write_reg(wilc, WILC_CORTUS_INTERRUPT_2, 1); release_bus(wilc, WILC_BUS_RELEASE_ONLY); } EXPORT_SYMBOL_GPL(host_wakeup_notify); @@ -466,7 +471,7 @@ EXPORT_SYMBOL_GPL(host_wakeup_notify); void host_sleep_notify(struct wilc *wilc) { acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY); - wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1); + wilc->hif_func->hif_write_reg(wilc, WILC_CORTUS_INTERRUPT_1, 1); release_bus(wilc, WILC_BUS_RELEASE_ONLY); } EXPORT_SYMBOL_GPL(host_sleep_notify); @@ -508,9 +513,7 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count) vmm_sz = HOST_HDR_OFFSET; vmm_sz += tqe->buffer_size; - - if (vmm_sz & 0x3) - vmm_sz = (vmm_sz + 4) & ~0x3; + vmm_sz = ALIGN(vmm_sz, 4); if ((sum + vmm_sz) > WILC_TX_BUFF_SIZE) break; @@ -568,11 +571,10 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count) ret = func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®); if (ret) break; - if ((reg >> 2) & 0x1) { - entries = ((reg >> 3) & 0x3f); + if (FIELD_GET(WILC_VMM_ENTRY_AVAILABLE, reg)) { + entries = FIELD_GET(WILC_VMM_ENTRY_COUNT, reg); break; } - release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP); } while (--timeout); if (timeout <= 0) { ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0); @@ -610,6 +612,7 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count) do { u32 header, buffer_offset; char *bssid; + u8 mgmt_ptk = 0; tqe = wilc_wlan_txq_remove_from_head(dev); if (!tqe) @@ -620,15 +623,16 @@ int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count) break; le32_to_cpus(&vmm_table[i]); - vmm_sz = (vmm_table[i] & 0x3ff); + vmm_sz = FIELD_GET(WILC_VMM_BUFFER_SIZE, vmm_table[i]); vmm_sz *= 4; - header = (tqe->type << 31) | - (tqe->buffer_size << 15) | - vmm_sz; + if (tqe->type == WILC_MGMT_PKT) - header |= BIT(30); - else - header &= ~BIT(30); + mgmt_ptk = 1; + + header = (FIELD_PREP(WILC_VMM_HDR_TYPE, tqe->type) | + FIELD_PREP(WILC_VMM_HDR_MGMT_FIELD, mgmt_ptk) | + FIELD_PREP(WILC_VMM_HDR_PKT_SIZE, tqe->buffer_size) | + FIELD_PREP(WILC_VMM_HDR_BUFF_SIZE, vmm_sz)); cpu_to_le32s(&header); memcpy(&txb[offset], &header, 4); @@ -686,10 +690,10 @@ static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size) buff_ptr = buffer + offset; header = get_unaligned_le32(buff_ptr); - is_cfg_packet = (header >> 31) & 0x1; - pkt_offset = (header >> 22) & 0x1ff; - tp_len = (header >> 11) & 0x7ff; - pkt_len = header & 0x7ff; + is_cfg_packet = FIELD_GET(WILC_PKT_HDR_CONFIG_FIELD, header); + pkt_offset = FIELD_GET(WILC_PKT_HDR_OFFSET_FIELD, header); + tp_len = FIELD_GET(WILC_PKT_HDR_TOTAL_LEN_FIELD, header); + pkt_len = FIELD_GET(WILC_PKT_HDR_LEN_FIELD, header); if (pkt_len == 0 || tp_len == 0) break; @@ -699,10 +703,8 @@ static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size) wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len); } else { if (!is_cfg_packet) { - if (pkt_len > 0) { - wilc_frmw_to_host(wilc, buff_ptr, - pkt_len, pkt_offset); - } + wilc_frmw_to_host(wilc, buff_ptr, pkt_len, + pkt_offset); } else { struct wilc_cfg_rsp rsp; @@ -758,11 +760,11 @@ static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status) int ret = 0; struct rxq_entry_t *rqe; - size = (int_status & 0x7fff) << 2; + size = FIELD_GET(WILC_INTERRUPT_DATA_SIZE, int_status) << 2; while (!size && retries < 10) { wilc->hif_func->hif_read_size(wilc, &size); - size = (size & 0x7fff) << 2; + size = FIELD_GET(WILC_INTERRUPT_DATA_SIZE, size) << 2; retries++; } @@ -887,7 +889,7 @@ int wilc_wlan_start(struct wilc *wilc) wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT); - ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid); + ret = wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &chipid); if (ret) { release_bus(wilc, WILC_BUS_RELEASE_ONLY); return ret; @@ -1128,18 +1130,24 @@ static int init_chip(struct net_device *dev) chipid = wilc_get_chipid(wilc, true); if ((chipid & 0xfff) != 0xa0) { - ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®); + ret = wilc->hif_func->hif_read_reg(wilc, + WILC_CORTUS_RESET_MUX_SEL, + ®); if (ret) { netdev_err(dev, "fail read reg 0x1118\n"); goto release; } reg |= BIT(0); - ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg); + ret = wilc->hif_func->hif_write_reg(wilc, + WILC_CORTUS_RESET_MUX_SEL, + reg); if (ret) { netdev_err(dev, "fail write reg 0x1118\n"); goto release; } - ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71); + ret = wilc->hif_func->hif_write_reg(wilc, + WILC_CORTUS_BOOT_REGISTER, + WILC_CORTUS_BOOT_FROM_IRAM); if (ret) { netdev_err(dev, "fail write reg 0xc0000\n"); goto release; @@ -1159,20 +1167,21 @@ u32 wilc_get_chipid(struct wilc *wilc, bool update) u32 rfrevid = 0; if (chipid == 0 || update) { - wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid); - wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid); + wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &tempchipid); + wilc->hif_func->hif_read_reg(wilc, WILC_RF_REVISION_ID, + &rfrevid); if (!is_wilc1000(tempchipid)) { chipid = 0; return chipid; } - if (tempchipid == 0x1002a0) { + if (tempchipid == WILC_1000_BASE_ID_2A) { /* 0x1002A0 */ if (rfrevid != 0x1) - tempchipid = 0x1002a1; - } else if (tempchipid == 0x1002b0) { + tempchipid = WILC_1000_BASE_ID_2A_REV1; + } else if (tempchipid == WILC_1000_BASE_ID_2B) { /* 0x1002B0 */ if (rfrevid == 0x4) - tempchipid = 0x1002b1; + tempchipid = WILC_1000_BASE_ID_2B_REV1; else if (rfrevid != 0x3) - tempchipid = 0x1002b2; + tempchipid = WILC_1000_BASE_ID_2B_REV2; } chipid = tempchipid; diff --git a/drivers/staging/wilc1000/wlan.h b/drivers/staging/wilc1000/wlan.h index 8c4634262adb..7689569cd82f 100644 --- a/drivers/staging/wilc1000/wlan.h +++ b/drivers/staging/wilc1000/wlan.h @@ -8,6 +8,7 @@ #define WILC_WLAN_H #include <linux/types.h> +#include <linux/bitfield.h> /******************************************** * @@ -65,6 +66,8 @@ #define WILC_INTR_CLEAR (WILC_INTR_REG_BASE + 0x30) #define WILC_INTR_STATUS (WILC_INTR_REG_BASE + 0x40) +#define WILC_RF_REVISION_ID 0x13f4 + #define WILC_VMM_TBL_SIZE 64 #define WILC_VMM_TX_TBL_BASE 0x150400 #define WILC_VMM_RX_TBL_BASE 0x150500 @@ -88,10 +91,53 @@ #define WILC_SPI_TX_MODE (WILC_SPI_REG_BASE + 0x20) #define WILC_SPI_PROTOCOL_CONFIG (WILC_SPI_REG_BASE + 0x24) #define WILC_SPI_INTR_CTL (WILC_SPI_REG_BASE + 0x2c) +#define WILC_SPI_INT_STATUS (WILC_SPI_REG_BASE + 0x40) +#define WILC_SPI_INT_CLEAR (WILC_SPI_REG_BASE + 0x44) + +#define WILC_SPI_WAKEUP_REG 0x1 +#define WILC_SPI_WAKEUP_BIT BIT(1) #define WILC_SPI_PROTOCOL_OFFSET (WILC_SPI_PROTOCOL_CONFIG - \ WILC_SPI_REG_BASE) +#define WILC_SPI_CLOCKLESS_ADDR_LIMIT 0x30 + +/* Functions IO enables bits */ +#define WILC_SDIO_CCCR_IO_EN_FUNC1 BIT(1) + +/* Function/Interrupt enables bits */ +#define WILC_SDIO_CCCR_IEN_MASTER BIT(0) +#define WILC_SDIO_CCCR_IEN_FUNC1 BIT(1) + +/* Abort CCCR register bits */ +#define WILC_SDIO_CCCR_ABORT_RESET BIT(3) + +/* Vendor specific CCCR registers */ +#define WILC_SDIO_WAKEUP_REG 0xf0 +#define WILC_SDIO_WAKEUP_BIT BIT(0) + +#define WILC_SDIO_CLK_STATUS_REG 0xf1 +#define WILC_SDIO_CLK_STATUS_BIT BIT(0) + +#define WILC_SDIO_INTERRUPT_DATA_SZ_REG 0xf2 /* Read size (2 bytes) */ + +#define WILC_SDIO_VMM_TBL_CTRL_REG 0xf6 +#define WILC_SDIO_IRQ_FLAG_REG 0xf7 +#define WILC_SDIO_IRQ_CLEAR_FLAG_REG 0xf8 + +#define WILC_SDIO_HOST_TO_FW_REG 0xfa +#define WILC_SDIO_HOST_TO_FW_BIT BIT(0) + +#define WILC_SDIO_FW_TO_HOST_REG 0xfc +#define WILC_SDIO_FW_TO_HOST_BIT BIT(0) + +/* Function 1 specific FBR register */ +#define WILC_SDIO_FBR_CSA_REG 0x10C /* CSA pointer (3 bytes) */ +#define WILC_SDIO_FBR_DATA_REG 0x10F + +#define WILC_SDIO_F1_DATA_REG 0x0 +#define WILC_SDIO_EXT_IRQ_FLAG_REG 0x4 + #define WILC_AHB_DATA_MEM_BASE 0x30000 #define WILC_AHB_SHARE_MEM_BASE 0xd0000 @@ -112,6 +158,32 @@ #define WILC_HAVE_DISABLE_WILC_UART BIT(7) #define WILC_HAVE_USE_IRQ_AS_HOST_WAKE BIT(8) +#define WILC_CORTUS_INTERRUPT_BASE 0x10A8 +#define WILC_CORTUS_INTERRUPT_1 (WILC_CORTUS_INTERRUPT_BASE + 0x4) +#define WILC_CORTUS_INTERRUPT_2 (WILC_CORTUS_INTERRUPT_BASE + 0x8) + +/* tx control register 1 to 4 for RX */ +#define WILC_REG_4_TO_1_RX 0x1e1c + +/* tx control register 1 to 4 for TX Bank_0 */ +#define WILC_REG_4_TO_1_TX_BANK0 0x1e9c + +#define WILC_CORTUS_RESET_MUX_SEL 0x1118 +#define WILC_CORTUS_BOOT_REGISTER 0xc0000 + +#define WILC_CORTUS_BOOT_FROM_IRAM 0x71 + +#define WILC_1000_BASE_ID 0x100000 + +#define WILC_1000_BASE_ID_2A 0x1002A0 +#define WILC_1000_BASE_ID_2A_REV1 (WILC_1000_BASE_ID_2A + 1) + +#define WILC_1000_BASE_ID_2B 0x1002B0 +#define WILC_1000_BASE_ID_2B_REV1 (WILC_1000_BASE_ID_2B + 1) +#define WILC_1000_BASE_ID_2B_REV2 (WILC_1000_BASE_ID_2B + 2) + +#define WILC_CHIP_REV_FIELD GENMASK(11, 0) + /******************************************** * * Wlan Defines @@ -134,7 +206,23 @@ #define WILC_TX_BUFF_SIZE (64 * 1024) #define MODALIAS "WILC_SPI" -#define GPIO_NUM 0x44 + +#define WILC_PKT_HDR_CONFIG_FIELD BIT(31) +#define WILC_PKT_HDR_OFFSET_FIELD GENMASK(30, 22) +#define WILC_PKT_HDR_TOTAL_LEN_FIELD GENMASK(21, 11) +#define WILC_PKT_HDR_LEN_FIELD GENMASK(10, 0) + +#define WILC_INTERRUPT_DATA_SIZE GENMASK(14, 0) + +#define WILC_VMM_BUFFER_SIZE GENMASK(9, 0) + +#define WILC_VMM_HDR_TYPE BIT(31) +#define WILC_VMM_HDR_MGMT_FIELD BIT(30) +#define WILC_VMM_HDR_PKT_SIZE GENMASK(29, 15) +#define WILC_VMM_HDR_BUFF_SIZE GENMASK(14, 0) + +#define WILC_VMM_ENTRY_COUNT GENMASK(8, 3) +#define WILC_VMM_ENTRY_AVAILABLE BIT(2) /*******************************************/ /* E0 and later Interrupt flags. */ /*******************************************/ @@ -150,14 +238,16 @@ /* 21: INT5 flag */ /*******************************************/ #define IRG_FLAGS_OFFSET 16 -#define IRQ_DMA_WD_CNT_MASK ((1ul << IRG_FLAGS_OFFSET) - 1) +#define IRQ_DMA_WD_CNT_MASK GENMASK(IRG_FLAGS_OFFSET - 1, 0) #define INT_0 BIT(IRG_FLAGS_OFFSET) #define INT_1 BIT(IRG_FLAGS_OFFSET + 1) #define INT_2 BIT(IRG_FLAGS_OFFSET + 2) #define INT_3 BIT(IRG_FLAGS_OFFSET + 3) #define INT_4 BIT(IRG_FLAGS_OFFSET + 4) #define INT_5 BIT(IRG_FLAGS_OFFSET + 5) -#define MAX_NUM_INT 6 +#define MAX_NUM_INT 5 +#define IRG_FLAGS_MASK GENMASK(IRG_FLAGS_OFFSET + MAX_NUM_INT, \ + IRG_FLAGS_OFFSET) /*******************************************/ /* E0 and later Interrupt flags. */ @@ -185,6 +275,7 @@ #define DATA_INT_EXT INT_0 #define ALL_INT_EXT DATA_INT_EXT #define NUM_INT_EXT 1 +#define UNHANDLED_IRQ_MASK GENMASK(MAX_NUM_INT - 1, NUM_INT_EXT) #define DATA_INT_CLR CLR_INT0 diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h index bdd7f414fdbb..88e894dd3568 100644 --- a/drivers/staging/wlan-ng/hfa384x.h +++ b/drivers/staging/wlan-ng/hfa384x.h @@ -355,7 +355,7 @@ /* Commonly used basic types */ struct hfa384x_bytestr { __le16 len; - u8 data[0]; + u8 data[]; } __packed; struct hfa384x_bytestr32 { @@ -421,7 +421,7 @@ struct hfa384x_authenticate_station_data { /*-- Configuration Record: WPAData (data portion only) --*/ struct hfa384x_wpa_data { __le16 datalen; - u8 data[0]; /* max 80 */ + u8 data[]; /* max 80 */ } __packed; /*-------------------------------------------------------------------- diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c index b71756ab0394..fa1bf8b069fd 100644 --- a/drivers/staging/wlan-ng/hfa384x_usb.c +++ b/drivers/staging/wlan-ng/hfa384x_usb.c @@ -3254,13 +3254,16 @@ static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb) struct p80211_rxmeta *rxmeta; u16 data_len; u16 fc; + u16 status; /* Byte order convert once up front. */ le16_to_cpus(&usbin->rxfrm.desc.status); le32_to_cpus(&usbin->rxfrm.desc.time); /* Now handle frame based on port# */ - switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) { + status = HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status); + + switch (status) { case 0: fc = le16_to_cpu(usbin->rxfrm.desc.frame_control); @@ -3317,8 +3320,9 @@ static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb) break; default: - netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n", - HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)); + netdev_warn(hw->wlandev->netdev, + "Received frame on unsupported port=%d\n", + status); break; } } @@ -3372,6 +3376,8 @@ static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) { pr_debug("overlen frm: len=%zd\n", skblen - sizeof(struct p80211_caphdr)); + + return; } skb = dev_alloc_skb(skblen); diff --git a/drivers/staging/wlan-ng/p80211types.h b/drivers/staging/wlan-ng/p80211types.h index ac254542fde6..3dcdd022da61 100644 --- a/drivers/staging/wlan-ng/p80211types.h +++ b/drivers/staging/wlan-ng/p80211types.h @@ -204,7 +204,7 @@ struct p80211pstr { struct p80211pstrd { u8 len; - u8 data[0]; + u8 data[]; } __packed; /* Maximum pascal string */ @@ -249,7 +249,7 @@ struct p80211itemd { u32 did; u16 status; u16 len; - u8 data[0]; + u8 data[]; } __packed; /* message data item for int, BOUNDEDINT, ENUMINT */ diff --git a/drivers/staging/wlan-ng/prism2usb.c b/drivers/staging/wlan-ng/prism2usb.c index 352556f6870a..4689b2170e4f 100644 --- a/drivers/staging/wlan-ng/prism2usb.c +++ b/drivers/staging/wlan-ng/prism2usb.c @@ -180,6 +180,7 @@ static void prism2sta_disconnect_usb(struct usb_interface *interface) cancel_work_sync(&hw->link_bh); cancel_work_sync(&hw->commsqual_bh); + cancel_work_sync(&hw->usb_work); /* Now we complete any outstanding commands * and tell everyone who is waiting for their diff --git a/drivers/staging/wusbcore/Documentation/wusb-cbaf b/drivers/staging/wusbcore/Documentation/wusb-cbaf deleted file mode 100644 index 8b3d43efce90..000000000000 --- a/drivers/staging/wusbcore/Documentation/wusb-cbaf +++ /dev/null @@ -1,130 +0,0 @@ -#! /bin/bash -# - -set -e - -progname=$(basename $0) -function help -{ - cat <<EOF -Usage: $progname COMMAND DEVICEs [ARGS] - -Command for manipulating the pairing/authentication credentials of a -Wireless USB device that supports wired-mode Cable-Based-Association. - -Works in conjunction with the wusb-cba.ko driver from http://linuxuwb.org. - - -DEVICE - - sysfs path to the device to authenticate; for example, both this - guys are the same: - - /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4.4/1-4.4:1.1 - /sys/bus/usb/drivers/wusb-cbaf/1-4.4:1.1 - -COMMAND/ARGS are - - start - - Start a WUSB host controller (by setting up a CHID) - - set-chid DEVICE HOST-CHID HOST-BANDGROUP HOST-NAME - - Sets host information in the device; after this you can call the - get-cdid to see how does this device report itself to us. - - get-cdid DEVICE - - Get the device ID associated to the HOST-CHID we sent with - 'set-chid'. We might not know about it. - - set-cc DEVICE - - If we allow the device to connect, set a random new CDID and CK - (connection key). Device saves them for the next time it wants to - connect wireless. We save them for that next time also so we can - authenticate the device (when we see the CDID he uses to id - itself) and the CK to crypto talk to it. - -CHID is always 16 hex bytes in 'XX YY ZZ...' form -BANDGROUP is almost always 0001 - -Examples: - - You can default most arguments to '' to get a sane value: - - $ $progname set-chid '' '' '' "My host name" - - A full sequence: - - $ $progname set-chid '' '' '' "My host name" - $ $progname get-cdid '' - $ $progname set-cc '' - -EOF -} - - -# Defaults -# FIXME: CHID should come from a database :), band group from the host -host_CHID="00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff" -host_band_group="0001" -host_name=$(hostname) - -devs="$(echo /sys/bus/usb/drivers/wusb-cbaf/[0-9]*)" -hdevs="$(for h in /sys/class/uwb_rc/*/wusbhc; do readlink -f $h; done)" - -result=0 -case $1 in - start) - for dev in ${2:-$hdevs} - do - echo $host_CHID > $dev/wusb_chid - echo I: started host $(basename $dev) >&2 - done - ;; - stop) - for dev in ${2:-$hdevs} - do - echo 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > $dev/wusb_chid - echo I: stopped host $(basename $dev) >&2 - done - ;; - set-chid) - shift - for dev in ${2:-$devs}; do - echo "${4:-$host_name}" > $dev/wusb_host_name - echo "${3:-$host_band_group}" > $dev/wusb_host_band_groups - echo ${2:-$host_CHID} > $dev/wusb_chid - done - ;; - get-cdid) - for dev in ${2:-$devs} - do - cat $dev/wusb_cdid - done - ;; - set-cc) - for dev in ${2:-$devs}; do - shift - CDID="$(head --bytes=16 /dev/urandom | od -tx1 -An)" - CK="$(head --bytes=16 /dev/urandom | od -tx1 -An)" - echo "$CDID" > $dev/wusb_cdid - echo "$CK" > $dev/wusb_ck - - echo I: CC set >&2 - echo "CHID: $(cat $dev/wusb_chid)" - echo "CDID:$CDID" - echo "CK: $CK" - done - ;; - help|h|--help|-h) - help - ;; - *) - echo "E: Unknown usage" 1>&2 - help 1>&2 - result=1 -esac -exit $result diff --git a/drivers/staging/wusbcore/Documentation/wusb-design-overview.rst b/drivers/staging/wusbcore/Documentation/wusb-design-overview.rst deleted file mode 100644 index dc5e21609bb5..000000000000 --- a/drivers/staging/wusbcore/Documentation/wusb-design-overview.rst +++ /dev/null @@ -1,457 +0,0 @@ -================================ -Linux UWB + Wireless USB + WiNET -================================ - - Copyright (C) 2005-2006 Intel Corporation - - Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - - 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 Street, Fifth Floor, Boston, MA - 02110-1301, USA. - - -Please visit http://bughost.org/thewiki/Design-overview.txt-1.8 for -updated content. - - * Design-overview.txt-1.8 - -This code implements a Ultra Wide Band stack for Linux, as well as -drivers for the USB based UWB radio controllers defined in the -Wireless USB 1.0 specification (including Wireless USB host controller -and an Intel WiNET controller). - -.. Contents - 1. Introduction - 1. HWA: Host Wire adapters, your Wireless USB dongle - - 2. DWA: Device Wired Adaptor, a Wireless USB hub for wired - devices - 3. WHCI: Wireless Host Controller Interface, the PCI WUSB host - adapter - 2. The UWB stack - 1. Devices and hosts: the basic structure - - 2. Host Controller life cycle - - 3. On the air: beacons and enumerating the radio neighborhood - - 4. Device lists - 5. Bandwidth allocation - - 3. Wireless USB Host Controller drivers - - 4. Glossary - - -Introduction -============ - -UWB is a wide-band communication protocol that is to serve also as the -low-level protocol for others (much like TCP sits on IP). Currently -these others are Wireless USB and TCP/IP, but seems Bluetooth and -Firewire/1394 are coming along. - -UWB uses a band from roughly 3 to 10 GHz, transmitting at a max of -~-41dB (or 0.074 uW/MHz--geography specific data is still being -negotiated w/ regulators, so watch for changes). That band is divided in -a bunch of ~1.5 GHz wide channels (or band groups) composed of three -subbands/subchannels (528 MHz each). Each channel is independent of each -other, so you could consider them different "busses". Initially this -driver considers them all a single one. - -Radio time is divided in 65536 us long /superframes/, each one divided -in 256 256us long /MASs/ (Media Allocation Slots), which are the basic -time/media allocation units for transferring data. At the beginning of -each superframe there is a Beacon Period (BP), where every device -transmit its beacon on a single MAS. The length of the BP depends on how -many devices are present and the length of their beacons. - -Devices have a MAC (fixed, 48 bit address) and a device (changeable, 16 -bit address) and send periodic beacons to advertise themselves and pass -info on what they are and do. They advertise their capabilities and a -bunch of other stuff. - -The different logical parts of this driver are: - - * - - *UWB*: the Ultra-Wide-Band stack -- manages the radio and - associated spectrum to allow for devices sharing it. Allows to - control bandwidth assignment, beaconing, scanning, etc - - * - - *WUSB*: the layer that sits on top of UWB to provide Wireless USB. - The Wireless USB spec defines means to control a UWB radio and to - do the actual WUSB. - - -HWA: Host Wire adapters, your Wireless USB dongle -------------------------------------------------- - -WUSB also defines a device called a Host Wire Adaptor (HWA), which in -mere terms is a USB dongle that enables your PC to have UWB and Wireless -USB. The Wireless USB Host Controller in a HWA looks to the host like a -[Wireless] USB controller connected via USB (!) - -The HWA itself is broken in two or three main interfaces: - - * - - *RC*: Radio control -- this implements an interface to the - Ultra-Wide-Band radio controller. The driver for this implements a - USB-based UWB Radio Controller to the UWB stack. - - * - - *HC*: the wireless USB host controller. It looks like a USB host - whose root port is the radio and the WUSB devices connect to it. - To the system it looks like a separate USB host. The driver (will) - implement a USB host controller (similar to UHCI, OHCI or EHCI) - for which the root hub is the radio...To reiterate: it is a USB - controller that is connected via USB instead of PCI. - - * - - *WINET*: some HW provide a WiNET interface (IP over UWB). This - package provides a driver for it (it looks like a network - interface, winetX). The driver detects when there is a link up for - their type and kick into gear. - - -DWA: Device Wired Adaptor, a Wireless USB hub for wired devices ---------------------------------------------------------------- - -These are the complement to HWAs. They are a USB host for connecting -wired devices, but it is connected to your PC connected via Wireless -USB. To the system it looks like yet another USB host. To the untrained -eye, it looks like a hub that connects upstream wirelessly. - -We still offer no support for this; however, it should share a lot of -code with the HWA-RC driver; there is a bunch of factorization work that -has been done to support that in upcoming releases. - - -WHCI: Wireless Host Controller Interface, the PCI WUSB host adapter -------------------------------------------------------------------- - -This is your usual PCI device that implements WHCI. Similar in concept -to EHCI, it allows your wireless USB devices (including DWAs) to connect -to your host via a PCI interface. As in the case of the HWA, it has a -Radio Control interface and the WUSB Host Controller interface per se. - -There is still no driver support for this, but will be in upcoming -releases. - - -The UWB stack -============= - -The main mission of the UWB stack is to keep a tally of which devices -are in radio proximity to allow drivers to connect to them. As well, it -provides an API for controlling the local radio controllers (RCs from -now on), such as to start/stop beaconing, scan, allocate bandwidth, etc. - - -Devices and hosts: the basic structure --------------------------------------- - -The main building block here is the UWB device (struct uwb_dev). For -each device that pops up in radio presence (ie: the UWB host receives a -beacon from it) you get a struct uwb_dev that will show up in -/sys/bus/uwb/devices. - -For each RC that is detected, a new struct uwb_rc and struct uwb_dev are -created. An entry is also created in /sys/class/uwb_rc for each RC. - -Each RC driver is implemented by a separate driver that plugs into the -interface that the UWB stack provides through a struct uwb_rc_ops. The -spec creators have been nice enough to make the message format the same -for HWA and WHCI RCs, so the driver is really a very thin transport that -moves the requests from the UWB API to the device [/uwb_rc_ops->cmd()/] -and sends the replies and notifications back to the API -[/uwb_rc_neh_grok()/]. Notifications are handled to the UWB daemon, that -is chartered, among other things, to keep the tab of how the UWB radio -neighborhood looks, creating and destroying devices as they show up or -disappear. - -Command execution is very simple: a command block is sent and a event -block or reply is expected back. For sending/receiving command/events, a -handle called /neh/ (Notification/Event Handle) is opened with -/uwb_rc_neh_open()/. - -The HWA-RC (USB dongle) driver (drivers/uwb/hwa-rc.c) does this job for -the USB connected HWA. Eventually, drivers/whci-rc.c will do the same -for the PCI connected WHCI controller. - - -Host Controller life cycle --------------------------- - -So let's say we connect a dongle to the system: it is detected and -firmware uploaded if needed [for Intel's i1480 -/drivers/uwb/ptc/usb.c:ptc_usb_probe()/] and then it is reenumerated. -Now we have a real HWA device connected and -/drivers/uwb/hwa-rc.c:hwarc_probe()/ picks it up, that will set up the -Wire-Adaptor environment and then suck it into the UWB stack's vision of -the world [/drivers/uwb/lc-rc.c:uwb_rc_add()/]. - - * - - [*] The stack should put a new RC to scan for devices - [/uwb_rc_scan()/] so it finds what's available around and tries to - connect to them, but this is policy stuff and should be driven - from user space. As of now, the operator is expected to do it - manually; see the release notes for documentation on the procedure. - -When a dongle is disconnected, /drivers/uwb/hwa-rc.c:hwarc_disconnect()/ -takes time of tearing everything down safely (or not...). - - -On the air: beacons and enumerating the radio neighborhood ----------------------------------------------------------- - -So assuming we have devices and we have agreed for a channel to connect -on (let's say 9), we put the new RC to beacon: - - * - - $ echo 9 0 > /sys/class/uwb_rc/uwb0/beacon - -Now it is visible. If there were other devices in the same radio channel -and beacon group (that's what the zero is for), the dongle's radio -control interface will send beacon notifications on its -notification/event endpoint (NEEP). The beacon notifications are part of -the event stream that is funneled into the API with -/drivers/uwb/neh.c:uwb_rc_neh_grok()/ and delivered to the UWBD, the UWB -daemon through a notification list. - -UWBD wakes up and scans the event list; finds a beacon and adds it to -the BEACON CACHE (/uwb_beca/). If he receives a number of beacons from -the same device, he considers it to be 'onair' and creates a new device -[/drivers/uwb/lc-dev.c:uwbd_dev_onair()/]. Similarly, when no beacons -are received in some time, the device is considered gone and wiped out -[uwbd calls periodically /uwb/beacon.c:uwb_beca_purge()/ that will purge -the beacon cache of dead devices]. - - -Device lists ------------- - -All UWB devices are kept in the list of the struct bus_type uwb_bus_type. - - -Bandwidth allocation --------------------- - -The UWB stack maintains a local copy of DRP availability through -processing of incoming *DRP Availability Change* notifications. This -local copy is currently used to present the current bandwidth -availability to the user through the sysfs file -/sys/class/uwb_rc/uwbx/bw_avail. In the future the bandwidth -availability information will be used by the bandwidth reservation -routines. - -The bandwidth reservation routines are in progress and are thus not -present in the current release. When completed they will enable a user -to initiate DRP reservation requests through interaction with sysfs. DRP -reservation requests from remote UWB devices will also be handled. The -bandwidth management done by the UWB stack will include callbacks to the -higher layers will enable the higher layers to use the reservations upon -completion. [Note: The bandwidth reservation work is in progress and -subject to change.] - - -Wireless USB Host Controller drivers -==================================== - -*WARNING* This section needs a lot of work! - -As explained above, there are three different types of HCs in the WUSB -world: HWA-HC, DWA-HC and WHCI-HC. - -HWA-HC and DWA-HC share that they are Wire-Adapters (USB or WUSB -connected controllers), and their transfer management system is almost -identical. So is their notification delivery system. - -HWA-HC and WHCI-HC share that they are both WUSB host controllers, so -they have to deal with WUSB device life cycle and maintenance, wireless -root-hub - -HWA exposes a Host Controller interface (HWA-HC 0xe0/02/02). This has -three endpoints (Notifications, Data Transfer In and Data Transfer -Out--known as NEP, DTI and DTO in the code). - -We reserve UWB bandwidth for our Wireless USB Cluster, create a Cluster -ID and tell the HC to use all that. Then we start it. This means the HC -starts sending MMCs. - - * - - The MMCs are blocks of data defined somewhere in the WUSB1.0 spec - that define a stream in the UWB channel time allocated for sending - WUSB IEs (host to device commands/notifications) and Device - Notifications (device initiated to host). Each host defines a - unique Wireless USB cluster through MMCs. Devices can connect to a - single cluster at the time. The IEs are Information Elements, and - among them are the bandwidth allocations that tell each device - when can they transmit or receive. - -Now it all depends on external stimuli. - -New device connection ---------------------- - -A new device pops up, it scans the radio looking for MMCs that give out -the existence of Wireless USB channels. Once one (or more) are found, -selects which one to connect to. Sends a /DN_Connect/ (device -notification connect) during the DNTS (Device Notification Time -Slot--announced in the MMCs - -HC picks the /DN_Connect/ out (nep module sends to notif.c for delivery -into /devconnect/). This process starts the authentication process for -the device. First we allocate a /fake port/ and assign an -unauthenticated address (128 to 255--what we really do is -0x80 | fake_port_idx). We fiddle with the fake port status and /hub_wq/ -sees a new connection, so he moves on to enable the fake port with a reset. - -So now we are in the reset path -- we know we have a non-yet enumerated -device with an unauthorized address; we ask user space to authenticate -(FIXME: not yet done, similar to bluetooth pairing), then we do the key -exchange (FIXME: not yet done) and issue a /set address 0/ to bring the -device to the default state. Device is authenticated. - -From here, the USB stack takes control through the usb_hcd ops. hub_wq -has seen the port status changes, as we have been toggling them. It will -start enumerating and doing transfers through usb_hcd->urb_enqueue() to -read descriptors and move our data. - -Device life cycle and keep alives ---------------------------------- - -Every time there is a successful transfer to/from a device, we update a -per-device activity timestamp. If not, every now and then we check and -if the activity timestamp gets old, we ping the device by sending it a -Keep Alive IE; it responds with a /DN_Alive/ pong during the DNTS (this -arrives to us as a notification through -devconnect.c:wusb_handle_dn_alive(). If a device times out, we -disconnect it from the system (cleaning up internal information and -toggling the bits in the fake hub port, which kicks hub_wq into removing -the rest of the stuff). - -This is done through devconnect:__wusb_check_devs(), which will scan the -device list looking for whom needs refreshing. - -If the device wants to disconnect, it will either die (ugly) or send a -/DN_Disconnect/ that will prompt a disconnection from the system. - -Sending and receiving data --------------------------- - -Data is sent and received through /Remote Pipes/ (rpipes). An rpipe is -/aimed/ at an endpoint in a WUSB device. This is the same for HWAs and -DWAs. - -Each HC has a number of rpipes and buffers that can be assigned to them; -when doing a data transfer (xfer), first the rpipe has to be aimed and -prepared (buffers assigned), then we can start queueing requests for -data in or out. - -Data buffers have to be segmented out before sending--so we send first a -header (segment request) and then if there is any data, a data buffer -immediately after to the DTI interface (yep, even the request). If our -buffer is bigger than the max segment size, then we just do multiple -requests. - -[This sucks, because doing USB scatter gatter in Linux is resource -intensive, if any...not that the current approach is not. It just has to -be cleaned up a lot :)]. - -If reading, we don't send data buffers, just the segment headers saying -we want to read segments. - -When the xfer is executed, we receive a notification that says data is -ready in the DTI endpoint (handled through -xfer.c:wa_handle_notif_xfer()). In there we read from the DTI endpoint a -descriptor that gives us the status of the transfer, its identification -(given when we issued it) and the segment number. If it was a data read, -we issue another URB to read into the destination buffer the chunk of -data coming out of the remote endpoint. Done, wait for the next guy. The -callbacks for the URBs issued from here are the ones that will declare -the xfer complete at some point and call its callback. - -Seems simple, but the implementation is not trivial. - - * - - *WARNING* Old!! - -The main xfer descriptor, wa_xfer (equivalent to a URB) contains an -array of segments, tallys on segments and buffers and callback -information. Buried in there is a lot of URBs for executing the segments -and buffer transfers. - -For OUT xfers, there is an array of segments, one URB for each, another -one of buffer URB. When submitting, we submit URBs for segment request -1, buffer 1, segment 2, buffer 2...etc. Then we wait on the DTI for xfer -result data; when all the segments are complete, we call the callback to -finalize the transfer. - -For IN xfers, we only issue URBs for the segments we want to read and -then wait for the xfer result data. - -URB mapping into xfers -^^^^^^^^^^^^^^^^^^^^^^ - -This is done by hwahc_op_urb_[en|de]queue(). In enqueue() we aim an -rpipe to the endpoint where we have to transmit, create a transfer -context (wa_xfer) and submit it. When the xfer is done, our callback is -called and we assign the status bits and release the xfer resources. - -In dequeue() we are basically cancelling/aborting the transfer. We issue -a xfer abort request to the HC, cancel all the URBs we had submitted -and not yet done and when all that is done, the xfer callback will be -called--this will call the URB callback. - - -Glossary -======== - -*DWA* -- Device Wire Adapter - -USB host, wired for downstream devices, upstream connects wirelessly -with Wireless USB. - -*EVENT* -- Response to a command on the NEEP - -*HWA* -- Host Wire Adapter / USB dongle for UWB and Wireless USB - -*NEH* -- Notification/Event Handle - -Handle/file descriptor for receiving notifications or events. The WA -code requires you to get one of this to listen for notifications or -events on the NEEP. - -*NEEP* -- Notification/Event EndPoint - -Stuff related to the management of the first endpoint of a HWA USB -dongle that is used to deliver an stream of events and notifications to -the host. - -*NOTIFICATION* -- Message coming in the NEEP as response to something. - -*RC* -- Radio Control - -Design-overview.txt-1.8 (last edited 2006-11-04 12:22:24 by -InakyPerezGonzalez) diff --git a/drivers/staging/wusbcore/Kconfig b/drivers/staging/wusbcore/Kconfig deleted file mode 100644 index a559d023b508..000000000000 --- a/drivers/staging/wusbcore/Kconfig +++ /dev/null @@ -1,39 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Wireless USB Core configuration -# -config USB_WUSB - tristate "Enable Wireless USB extensions" - depends on UWB && USB - select CRYPTO - select CRYPTO_AES - select CRYPTO_CCM - help - Enable the host-side support for Wireless USB. - - To compile this support select Y (built in). It is safe to - select even if you don't have the hardware. - -config USB_WUSB_CBAF - tristate "Support WUSB Cable Based Association (CBA)" - depends on USB - help - Some WUSB devices support Cable Based Association. It's used to - enable the secure communication between the host and the - device. - - Enable this option if your WUSB device must to be connected - via wired USB before establishing a wireless link. - - It is safe to select even if you don't have a compatible - hardware. - -config USB_WUSB_CBAF_DEBUG - bool "Enable CBA debug messages" - depends on USB_WUSB_CBAF - help - Say Y here if you want the CBA to produce a bunch of debug messages - to the system log. Select this if you are having a problem with - CBA support and want to see more of what is going on. - -source "drivers/staging/wusbcore/host/Kconfig" diff --git a/drivers/staging/wusbcore/Makefile b/drivers/staging/wusbcore/Makefile deleted file mode 100644 index b47b874268ac..000000000000 --- a/drivers/staging/wusbcore/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -ccflags-$(CONFIG_USB_WUSB_CBAF_DEBUG) := -DDEBUG - -obj-$(CONFIG_USB_WUSB) += wusbcore.o -obj-$(CONFIG_USB_HWA_HCD) += wusb-wa.o -obj-$(CONFIG_USB_WUSB_CBAF) += wusb-cbaf.o - - -wusbcore-y := \ - crypto.o \ - devconnect.o \ - dev-sysfs.o \ - mmc.o \ - pal.o \ - rh.o \ - reservation.o \ - security.o \ - wusbhc.o - -wusb-cbaf-y := cbaf.o - -wusb-wa-y := \ - wa-hc.o \ - wa-nep.o \ - wa-rpipe.o \ - wa-xfer.o - -obj-y += host/ diff --git a/drivers/staging/wusbcore/TODO b/drivers/staging/wusbcore/TODO deleted file mode 100644 index abae57000534..000000000000 --- a/drivers/staging/wusbcore/TODO +++ /dev/null @@ -1,8 +0,0 @@ -TODO: Remove in late 2019 unless there are users - -There seems to not be any real wireless USB devices anywhere in the wild -anymore. It turned out to be a failed technology :( - -This will be removed from the tree if no one objects. - -Greg Kroah-Hartman <gregkh@linuxfoundation.org> diff --git a/drivers/staging/wusbcore/cbaf.c b/drivers/staging/wusbcore/cbaf.c deleted file mode 100644 index 57062eaf7558..000000000000 --- a/drivers/staging/wusbcore/cbaf.c +++ /dev/null @@ -1,645 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB - Cable Based Association - * - * - * Copyright (C) 2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - * - * WUSB devices have to be paired (associated in WUSB lingo) so - * that they can connect to the system. - * - * One way of pairing is using CBA-Cable Based Association. First - * time you plug the device with a cable, association is done between - * host and device and subsequent times, you can connect wirelessly - * without having to associate again. That's the idea. - * - * This driver does nothing Earth shattering. It just provides an - * interface to chat with the wire-connected device so we can get a - * CDID (device ID) that might have been previously associated to a - * CHID (host ID) and to set up a new <CHID,CDID,CK> triplet - * (connection context), with the CK being the secret, or connection - * key. This is the pairing data. - * - * When a device with the CBA capability connects, the probe routine - * just creates a bunch of sysfs files that a user space enumeration - * manager uses to allow it to connect wirelessly to the system or not. - * - * The process goes like this: - * - * 1. Device plugs, cbaf is loaded, notifications happen. - * - * 2. The connection manager (CM) sees a device with CBAF capability - * (the wusb_chid etc. files in /sys/devices/blah/OURDEVICE). - * - * 3. The CM writes the host name, supported band groups, and the CHID - * (host ID) into the wusb_host_name, wusb_host_band_groups and - * wusb_chid files. These get sent to the device and the CDID (if - * any) for this host is requested. - * - * 4. The CM can verify that the device's supported band groups - * (wusb_device_band_groups) are compatible with the host. - * - * 5. The CM reads the wusb_cdid file. - * - * 6. The CM looks up its database - * - * 6.1 If it has a matching CHID,CDID entry, the device has been - * authorized before (paired) and nothing further needs to be - * done. - * - * 6.2 If the CDID is zero (or the CM doesn't find a matching CDID in - * its database), the device is assumed to be not known. The CM - * may associate the host with device by: writing a randomly - * generated CDID to wusb_cdid and then a random CK to wusb_ck - * (this uploads the new CC to the device). - * - * CMD may choose to prompt the user before associating with a new - * device. - * - * 7. Device is unplugged. - * - * When the device tries to connect wirelessly, it will present its - * CDID to the WUSB host controller. The CM will query the - * database. If the CHID/CDID pair found, it will (with a 4-way - * handshake) challenge the device to demonstrate it has the CK secret - * key (from our database) without actually exchanging it. Once - * satisfied, crypto keys are derived from the CK, the device is - * connected and all communication is encrypted. - * - * References: - * [WUSB-AM] Association Models Supplement to the Certified Wireless - * Universal Serial Bus Specification, version 1.0. - */ -#include <linux/module.h> -#include <linux/ctype.h> -#include <linux/usb.h> -#include <linux/interrupt.h> -#include <linux/delay.h> -#include <linux/random.h> -#include <linux/slab.h> -#include <linux/mutex.h> -#include "../uwb/uwb.h" -#include "include/wusb.h" -#include "include/association.h" - -#define CBA_NAME_LEN 0x40 /* [WUSB-AM] table 4-7 */ - -/* An instance of a Cable-Based-Association-Framework device */ -struct cbaf { - struct usb_device *usb_dev; - struct usb_interface *usb_iface; - void *buffer; - size_t buffer_size; - - struct wusb_ckhdid chid; - char host_name[CBA_NAME_LEN]; - u16 host_band_groups; - - struct wusb_ckhdid cdid; - char device_name[CBA_NAME_LEN]; - u16 device_band_groups; - - struct wusb_ckhdid ck; -}; - -/* - * Verify that a CBAF USB-interface has what we need - * - * According to [WUSB-AM], CBA devices should provide at least two - * interfaces: - * - RETRIEVE_HOST_INFO - * - ASSOCIATE - * - * If the device doesn't provide these interfaces, we do not know how - * to deal with it. - */ -static int cbaf_check(struct cbaf *cbaf) -{ - int result; - struct device *dev = &cbaf->usb_iface->dev; - struct wusb_cbaf_assoc_info *assoc_info; - struct wusb_cbaf_assoc_request *assoc_request; - size_t assoc_size; - void *itr, *top; - int ar_rhi = 0, ar_assoc = 0; - - result = usb_control_msg( - cbaf->usb_dev, usb_rcvctrlpipe(cbaf->usb_dev, 0), - CBAF_REQ_GET_ASSOCIATION_INFORMATION, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, - cbaf->buffer, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Cannot get available association types: %d\n", - result); - return result; - } - - assoc_info = cbaf->buffer; - if (result < sizeof(*assoc_info)) { - dev_err(dev, "Not enough data to decode association info " - "header (%zu vs %zu bytes required)\n", - (size_t)result, sizeof(*assoc_info)); - return result; - } - - assoc_size = le16_to_cpu(assoc_info->Length); - if (result < assoc_size) { - dev_err(dev, "Not enough data to decode association info " - "(%zu vs %zu bytes required)\n", - (size_t)assoc_size, sizeof(*assoc_info)); - return result; - } - /* - * From now on, we just verify, but won't error out unless we - * don't find the AR_TYPE_WUSB_{RETRIEVE_HOST_INFO,ASSOCIATE} - * types. - */ - itr = cbaf->buffer + sizeof(*assoc_info); - top = cbaf->buffer + assoc_size; - dev_dbg(dev, "Found %u association requests (%zu bytes)\n", - assoc_info->NumAssociationRequests, assoc_size); - - while (itr < top) { - u16 ar_type, ar_subtype; - u32 ar_size; - const char *ar_name; - - assoc_request = itr; - - if (top - itr < sizeof(*assoc_request)) { - dev_err(dev, "Not enough data to decode association " - "request (%zu vs %zu bytes needed)\n", - top - itr, sizeof(*assoc_request)); - break; - } - - ar_type = le16_to_cpu(assoc_request->AssociationTypeId); - ar_subtype = le16_to_cpu(assoc_request->AssociationSubTypeId); - ar_size = le32_to_cpu(assoc_request->AssociationTypeInfoSize); - ar_name = "unknown"; - - switch (ar_type) { - case AR_TYPE_WUSB: - /* Verify we have what is mandated by [WUSB-AM]. */ - switch (ar_subtype) { - case AR_TYPE_WUSB_RETRIEVE_HOST_INFO: - ar_name = "RETRIEVE_HOST_INFO"; - ar_rhi = 1; - break; - case AR_TYPE_WUSB_ASSOCIATE: - /* send assoc data */ - ar_name = "ASSOCIATE"; - ar_assoc = 1; - break; - } - break; - } - - dev_dbg(dev, "Association request #%02u: 0x%04x/%04x " - "(%zu bytes): %s\n", - assoc_request->AssociationDataIndex, ar_type, - ar_subtype, (size_t)ar_size, ar_name); - - itr += sizeof(*assoc_request); - } - - if (!ar_rhi) { - dev_err(dev, "Missing RETRIEVE_HOST_INFO association " - "request\n"); - return -EINVAL; - } - if (!ar_assoc) { - dev_err(dev, "Missing ASSOCIATE association request\n"); - return -EINVAL; - } - - return 0; -} - -static const struct wusb_cbaf_host_info cbaf_host_info_defaults = { - .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, - .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), - .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, - .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_RETRIEVE_HOST_INFO), - .CHID_hdr = WUSB_AR_CHID, - .LangID_hdr = WUSB_AR_LangID, - .HostFriendlyName_hdr = WUSB_AR_HostFriendlyName, -}; - -/* Send WUSB host information (CHID and name) to a CBAF device */ -static int cbaf_send_host_info(struct cbaf *cbaf) -{ - struct wusb_cbaf_host_info *hi; - size_t name_len; - size_t hi_size; - - hi = cbaf->buffer; - memset(hi, 0, sizeof(*hi)); - *hi = cbaf_host_info_defaults; - hi->CHID = cbaf->chid; - hi->LangID = 0; /* FIXME: I guess... */ - strlcpy(hi->HostFriendlyName, cbaf->host_name, CBA_NAME_LEN); - name_len = strlen(cbaf->host_name); - hi->HostFriendlyName_hdr.len = cpu_to_le16(name_len); - hi_size = sizeof(*hi) + name_len; - - return usb_control_msg(cbaf->usb_dev, - usb_sndctrlpipe(cbaf->usb_dev, 0), - CBAF_REQ_SET_ASSOCIATION_RESPONSE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0x0101, - cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, - hi, hi_size, USB_CTRL_SET_TIMEOUT); -} - -/* - * Get device's information (CDID) associated to CHID - * - * The device will return it's information (CDID, name, bandgroups) - * associated to the CHID we have set before, or 0 CDID and default - * name and bandgroup if no CHID set or unknown. - */ -static int cbaf_cdid_get(struct cbaf *cbaf) -{ - int result; - struct device *dev = &cbaf->usb_iface->dev; - struct wusb_cbaf_device_info *di; - size_t needed; - - di = cbaf->buffer; - result = usb_control_msg( - cbaf->usb_dev, usb_rcvctrlpipe(cbaf->usb_dev, 0), - CBAF_REQ_GET_ASSOCIATION_REQUEST, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0x0200, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, - di, cbaf->buffer_size, USB_CTRL_GET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Cannot request device information: %d\n", - result); - return result; - } - - needed = result < sizeof(*di) ? sizeof(*di) : le32_to_cpu(di->Length); - if (result < needed) { - dev_err(dev, "Not enough data in DEVICE_INFO reply (%zu vs " - "%zu bytes needed)\n", (size_t)result, needed); - return -ENOENT; - } - - strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN); - cbaf->cdid = di->CDID; - cbaf->device_band_groups = le16_to_cpu(di->BandGroups); - - return 0; -} - -static ssize_t cbaf_wusb_chid_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return sprintf(buf, "%16ph\n", cbaf->chid.data); -} - -static ssize_t cbaf_wusb_chid_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - ssize_t result; - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - result = sscanf(buf, - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx", - &cbaf->chid.data[0] , &cbaf->chid.data[1], - &cbaf->chid.data[2] , &cbaf->chid.data[3], - &cbaf->chid.data[4] , &cbaf->chid.data[5], - &cbaf->chid.data[6] , &cbaf->chid.data[7], - &cbaf->chid.data[8] , &cbaf->chid.data[9], - &cbaf->chid.data[10], &cbaf->chid.data[11], - &cbaf->chid.data[12], &cbaf->chid.data[13], - &cbaf->chid.data[14], &cbaf->chid.data[15]); - - if (result != 16) - return -EINVAL; - - result = cbaf_send_host_info(cbaf); - if (result < 0) - return result; - result = cbaf_cdid_get(cbaf); - if (result < 0) - return result; - return size; -} -static DEVICE_ATTR(wusb_chid, 0600, cbaf_wusb_chid_show, cbaf_wusb_chid_store); - -static ssize_t cbaf_wusb_host_name_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return scnprintf(buf, PAGE_SIZE, "%s\n", cbaf->host_name); -} - -static ssize_t cbaf_wusb_host_name_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - ssize_t result; - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - result = sscanf(buf, "%63s", cbaf->host_name); - if (result != 1) - return -EINVAL; - - return size; -} -static DEVICE_ATTR(wusb_host_name, 0600, cbaf_wusb_host_name_show, - cbaf_wusb_host_name_store); - -static ssize_t cbaf_wusb_host_band_groups_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return scnprintf(buf, PAGE_SIZE, "0x%04x\n", cbaf->host_band_groups); -} - -static ssize_t cbaf_wusb_host_band_groups_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - ssize_t result; - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - u16 band_groups = 0; - - result = sscanf(buf, "%04hx", &band_groups); - if (result != 1) - return -EINVAL; - - cbaf->host_band_groups = band_groups; - - return size; -} - -static DEVICE_ATTR(wusb_host_band_groups, 0600, - cbaf_wusb_host_band_groups_show, - cbaf_wusb_host_band_groups_store); - -static const struct wusb_cbaf_device_info cbaf_device_info_defaults = { - .Length_hdr = WUSB_AR_Length, - .CDID_hdr = WUSB_AR_CDID, - .BandGroups_hdr = WUSB_AR_BandGroups, - .LangID_hdr = WUSB_AR_LangID, - .DeviceFriendlyName_hdr = WUSB_AR_DeviceFriendlyName, -}; - -static ssize_t cbaf_wusb_cdid_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return sprintf(buf, "%16ph\n", cbaf->cdid.data); -} - -static ssize_t cbaf_wusb_cdid_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - ssize_t result; - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - struct wusb_ckhdid cdid; - - result = sscanf(buf, - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx", - &cdid.data[0] , &cdid.data[1], - &cdid.data[2] , &cdid.data[3], - &cdid.data[4] , &cdid.data[5], - &cdid.data[6] , &cdid.data[7], - &cdid.data[8] , &cdid.data[9], - &cdid.data[10], &cdid.data[11], - &cdid.data[12], &cdid.data[13], - &cdid.data[14], &cdid.data[15]); - if (result != 16) - return -EINVAL; - - cbaf->cdid = cdid; - - return size; -} -static DEVICE_ATTR(wusb_cdid, 0600, cbaf_wusb_cdid_show, cbaf_wusb_cdid_store); - -static ssize_t cbaf_wusb_device_band_groups_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return scnprintf(buf, PAGE_SIZE, "0x%04x\n", cbaf->device_band_groups); -} - -static DEVICE_ATTR(wusb_device_band_groups, 0600, - cbaf_wusb_device_band_groups_show, - NULL); - -static ssize_t cbaf_wusb_device_name_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - return scnprintf(buf, PAGE_SIZE, "%s\n", cbaf->device_name); -} -static DEVICE_ATTR(wusb_device_name, 0600, cbaf_wusb_device_name_show, NULL); - -static const struct wusb_cbaf_cc_data cbaf_cc_data_defaults = { - .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, - .AssociationTypeId = cpu_to_le16(AR_TYPE_WUSB), - .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, - .AssociationSubTypeId = cpu_to_le16(AR_TYPE_WUSB_ASSOCIATE), - .Length_hdr = WUSB_AR_Length, - .Length = cpu_to_le32(sizeof(struct wusb_cbaf_cc_data)), - .ConnectionContext_hdr = WUSB_AR_ConnectionContext, - .BandGroups_hdr = WUSB_AR_BandGroups, -}; - -static const struct wusb_cbaf_cc_data_fail cbaf_cc_data_fail_defaults = { - .AssociationTypeId_hdr = WUSB_AR_AssociationTypeId, - .AssociationSubTypeId_hdr = WUSB_AR_AssociationSubTypeId, - .Length_hdr = WUSB_AR_Length, - .AssociationStatus_hdr = WUSB_AR_AssociationStatus, -}; - -/* - * Send a new CC to the device. - */ -static int cbaf_cc_upload(struct cbaf *cbaf) -{ - int result; - struct device *dev = &cbaf->usb_iface->dev; - struct wusb_cbaf_cc_data *ccd; - - ccd = cbaf->buffer; - *ccd = cbaf_cc_data_defaults; - ccd->CHID = cbaf->chid; - ccd->CDID = cbaf->cdid; - ccd->CK = cbaf->ck; - ccd->BandGroups = cpu_to_le16(cbaf->host_band_groups); - - dev_dbg(dev, "Trying to upload CC:\n"); - dev_dbg(dev, " CHID %16ph\n", ccd->CHID.data); - dev_dbg(dev, " CDID %16ph\n", ccd->CDID.data); - dev_dbg(dev, " Bandgroups 0x%04x\n", cbaf->host_band_groups); - - result = usb_control_msg( - cbaf->usb_dev, usb_sndctrlpipe(cbaf->usb_dev, 0), - CBAF_REQ_SET_ASSOCIATION_RESPONSE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0x0201, cbaf->usb_iface->cur_altsetting->desc.bInterfaceNumber, - ccd, sizeof(*ccd), USB_CTRL_SET_TIMEOUT); - - return result; -} - -static ssize_t cbaf_wusb_ck_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - ssize_t result; - struct usb_interface *iface = to_usb_interface(dev); - struct cbaf *cbaf = usb_get_intfdata(iface); - - result = sscanf(buf, - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx", - &cbaf->ck.data[0] , &cbaf->ck.data[1], - &cbaf->ck.data[2] , &cbaf->ck.data[3], - &cbaf->ck.data[4] , &cbaf->ck.data[5], - &cbaf->ck.data[6] , &cbaf->ck.data[7], - &cbaf->ck.data[8] , &cbaf->ck.data[9], - &cbaf->ck.data[10], &cbaf->ck.data[11], - &cbaf->ck.data[12], &cbaf->ck.data[13], - &cbaf->ck.data[14], &cbaf->ck.data[15]); - if (result != 16) - return -EINVAL; - - result = cbaf_cc_upload(cbaf); - if (result < 0) - return result; - - return size; -} -static DEVICE_ATTR(wusb_ck, 0600, NULL, cbaf_wusb_ck_store); - -static struct attribute *cbaf_dev_attrs[] = { - &dev_attr_wusb_host_name.attr, - &dev_attr_wusb_host_band_groups.attr, - &dev_attr_wusb_chid.attr, - &dev_attr_wusb_cdid.attr, - &dev_attr_wusb_device_name.attr, - &dev_attr_wusb_device_band_groups.attr, - &dev_attr_wusb_ck.attr, - NULL, -}; - -static const struct attribute_group cbaf_dev_attr_group = { - .name = NULL, /* we want them in the same directory */ - .attrs = cbaf_dev_attrs, -}; - -static int cbaf_probe(struct usb_interface *iface, - const struct usb_device_id *id) -{ - struct cbaf *cbaf; - struct device *dev = &iface->dev; - int result = -ENOMEM; - - cbaf = kzalloc(sizeof(*cbaf), GFP_KERNEL); - if (cbaf == NULL) - goto error_kzalloc; - cbaf->buffer = kmalloc(512, GFP_KERNEL); - if (cbaf->buffer == NULL) - goto error_kmalloc_buffer; - - cbaf->buffer_size = 512; - cbaf->usb_dev = usb_get_dev(interface_to_usbdev(iface)); - cbaf->usb_iface = usb_get_intf(iface); - result = cbaf_check(cbaf); - if (result < 0) { - dev_err(dev, "This device is not WUSB-CBAF compliant and is not supported yet.\n"); - goto error_check; - } - - result = sysfs_create_group(&dev->kobj, &cbaf_dev_attr_group); - if (result < 0) { - dev_err(dev, "Can't register sysfs attr group: %d\n", result); - goto error_create_group; - } - usb_set_intfdata(iface, cbaf); - return 0; - -error_create_group: -error_check: - usb_put_intf(iface); - usb_put_dev(cbaf->usb_dev); - kfree(cbaf->buffer); -error_kmalloc_buffer: - kfree(cbaf); -error_kzalloc: - return result; -} - -static void cbaf_disconnect(struct usb_interface *iface) -{ - struct cbaf *cbaf = usb_get_intfdata(iface); - struct device *dev = &iface->dev; - sysfs_remove_group(&dev->kobj, &cbaf_dev_attr_group); - usb_set_intfdata(iface, NULL); - usb_put_intf(iface); - usb_put_dev(cbaf->usb_dev); - kfree(cbaf->buffer); - /* paranoia: clean up crypto keys */ - kzfree(cbaf); -} - -static const struct usb_device_id cbaf_id_table[] = { - { USB_INTERFACE_INFO(0xef, 0x03, 0x01), }, - { }, -}; -MODULE_DEVICE_TABLE(usb, cbaf_id_table); - -static struct usb_driver cbaf_driver = { - .name = "wusb-cbaf", - .id_table = cbaf_id_table, - .probe = cbaf_probe, - .disconnect = cbaf_disconnect, -}; - -module_usb_driver(cbaf_driver); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Wireless USB Cable Based Association"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wusbcore/crypto.c b/drivers/staging/wusbcore/crypto.c deleted file mode 100644 index d7d55ed19a98..000000000000 --- a/drivers/staging/wusbcore/crypto.c +++ /dev/null @@ -1,441 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Ultra Wide Band - * AES-128 CCM Encryption - * - * Copyright (C) 2007 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * We don't do any encryption here; we use the Linux Kernel's AES-128 - * crypto modules to construct keys and payload blocks in a way - * defined by WUSB1.0[6]. Check the erratas, as typos are are patched - * there. - * - * Thanks a zillion to John Keys for his help and clarifications over - * the designed-by-a-committee text. - * - * So the idea is that there is this basic Pseudo-Random-Function - * defined in WUSB1.0[6.5] which is the core of everything. It works - * by tweaking some blocks, AES crypting them and then xoring - * something else with them (this seems to be called CBC(AES) -- can - * you tell I know jack about crypto?). So we just funnel it into the - * Linux Crypto API. - * - * We leave a crypto test module so we can verify that vectors match, - * every now and then. - * - * Block size: 16 bytes -- AES seems to do things in 'block sizes'. I - * am learning a lot... - * - * Conveniently, some data structures that need to be - * funneled through AES are...16 bytes in size! - */ - -#include <crypto/aes.h> -#include <crypto/algapi.h> -#include <crypto/hash.h> -#include <crypto/skcipher.h> -#include <linux/crypto.h> -#include <linux/module.h> -#include <linux/err.h> -#include <linux/slab.h> -#include <linux/scatterlist.h> -#include "../uwb/uwb.h" -#include "include/wusb.h" - -static int debug_crypto_verify; - -module_param(debug_crypto_verify, int, 0); -MODULE_PARM_DESC(debug_crypto_verify, "verify the key generation algorithms"); - -static void wusb_key_dump(const void *buf, size_t len) -{ - print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_OFFSET, 16, 1, - buf, len, 0); -} - -/* - * Block of data, as understood by AES-CCM - * - * The code assumes this structure is nothing but a 16 byte array - * (packed in a struct to avoid common mess ups that I usually do with - * arrays and enforcing type checking). - */ -struct aes_ccm_block { - u8 data[16]; -} __attribute__((packed)); - -/* - * Counter-mode Blocks (WUSB1.0[6.4]) - * - * According to CCM (or so it seems), for the purpose of calculating - * the MIC, the message is broken in N counter-mode blocks, B0, B1, - * ... BN. - * - * B0 contains flags, the CCM nonce and l(m). - * - * B1 contains l(a), the MAC header, the encryption offset and padding. - * - * If EO is nonzero, additional blocks are built from payload bytes - * until EO is exhausted (FIXME: padding to 16 bytes, I guess). The - * padding is not xmitted. - */ - -/* WUSB1.0[T6.4] */ -struct aes_ccm_b0 { - u8 flags; /* 0x59, per CCM spec */ - struct aes_ccm_nonce ccm_nonce; - __be16 lm; -} __attribute__((packed)); - -/* WUSB1.0[T6.5] */ -struct aes_ccm_b1 { - __be16 la; - u8 mac_header[10]; - __le16 eo; - u8 security_reserved; /* This is always zero */ - u8 padding; /* 0 */ -} __attribute__((packed)); - -/* - * Encryption Blocks (WUSB1.0[6.4.4]) - * - * CCM uses Ax blocks to generate a keystream with which the MIC and - * the message's payload are encoded. A0 always encrypts/decrypts the - * MIC. Ax (x>0) are used for the successive payload blocks. - * - * The x is the counter, and is increased for each block. - */ -struct aes_ccm_a { - u8 flags; /* 0x01, per CCM spec */ - struct aes_ccm_nonce ccm_nonce; - __be16 counter; /* Value of x */ -} __attribute__((packed)); - -/* Scratch space for MAC calculations. */ -struct wusb_mac_scratch { - struct aes_ccm_b0 b0; - struct aes_ccm_b1 b1; - struct aes_ccm_a ax; -}; - -/* - * CC-MAC function WUSB1.0[6.5] - * - * Take a data string and produce the encrypted CBC Counter-mode MIC - * - * Note the names for most function arguments are made to (more or - * less) match those used in the pseudo-function definition given in - * WUSB1.0[6.5]. - * - * @tfm_cbc: CBC(AES) blkcipher handle (initialized) - * - * @tfm_aes: AES cipher handle (initialized) - * - * @mic: buffer for placing the computed MIC (Message Integrity - * Code). This is exactly 8 bytes, and we expect the buffer to - * be at least eight bytes in length. - * - * @key: 128 bit symmetric key - * - * @n: CCM nonce - * - * @a: ASCII string, 14 bytes long (I guess zero padded if needed; - * we use exactly 14 bytes). - * - * @b: data stream to be processed - * - * @blen: size of b... - * - * Still not very clear how this is done, but looks like this: we - * create block B0 (as WUSB1.0[6.5] says), then we AES-crypt it with - * @key. We bytewise xor B0 with B1 (1) and AES-crypt that. Then we - * take the payload and divide it in blocks (16 bytes), xor them with - * the previous crypto result (16 bytes) and crypt it, repeat the next - * block with the output of the previous one, rinse wash. So we use - * the CBC-MAC(AES) shash, that does precisely that. The IV (Initial - * Vector) is 16 bytes and is set to zero, so - * - * (1) Created as 6.5 says, again, using as l(a) 'Blen + 14', and - * using the 14 bytes of @a to fill up - * b1.{mac_header,e0,security_reserved,padding}. - * - * NOTE: The definition of l(a) in WUSB1.0[6.5] vs the definition of - * l(m) is orthogonal, they bear no relationship, so it is not - * in conflict with the parameter's relation that - * WUSB1.0[6.4.2]) defines. - * - * NOTE: WUSB1.0[A.1]: Host Nonce is missing a nibble? (1e); fixed in - * first errata released on 2005/07. - * - * NOTE: we need to clean IV to zero at each invocation to make sure - * we start with a fresh empty Initial Vector, so that the CBC - * works ok. - * - * NOTE: blen is not aligned to a block size, we'll pad zeros, that's - * what sg[4] is for. Maybe there is a smarter way to do this. - */ -static int wusb_ccm_mac(struct crypto_shash *tfm_cbcmac, - struct wusb_mac_scratch *scratch, - void *mic, - const struct aes_ccm_nonce *n, - const struct aes_ccm_label *a, const void *b, - size_t blen) -{ - SHASH_DESC_ON_STACK(desc, tfm_cbcmac); - u8 iv[AES_BLOCK_SIZE]; - - /* - * These checks should be compile time optimized out - * ensure @a fills b1's mac_header and following fields - */ - BUILD_BUG_ON(sizeof(*a) != sizeof(scratch->b1) - sizeof(scratch->b1.la)); - BUILD_BUG_ON(sizeof(scratch->b0) != sizeof(struct aes_ccm_block)); - BUILD_BUG_ON(sizeof(scratch->b1) != sizeof(struct aes_ccm_block)); - BUILD_BUG_ON(sizeof(scratch->ax) != sizeof(struct aes_ccm_block)); - - /* Setup B0 */ - scratch->b0.flags = 0x59; /* Format B0 */ - scratch->b0.ccm_nonce = *n; - scratch->b0.lm = cpu_to_be16(0); /* WUSB1.0[6.5] sez l(m) is 0 */ - - /* Setup B1 - * - * The WUSB spec is anything but clear! WUSB1.0[6.5] - * says that to initialize B1 from A with 'l(a) = blen + - * 14'--after clarification, it means to use A's contents - * for MAC Header, EO, sec reserved and padding. - */ - scratch->b1.la = cpu_to_be16(blen + 14); - memcpy(&scratch->b1.mac_header, a, sizeof(*a)); - - desc->tfm = tfm_cbcmac; - crypto_shash_init(desc); - crypto_shash_update(desc, (u8 *)&scratch->b0, sizeof(scratch->b0) + - sizeof(scratch->b1)); - crypto_shash_finup(desc, b, blen, iv); - - /* Now we crypt the MIC Tag (*iv) with Ax -- values per WUSB1.0[6.5] - * The procedure is to AES crypt the A0 block and XOR the MIC - * Tag against it; we only do the first 8 bytes and place it - * directly in the destination buffer. - */ - scratch->ax.flags = 0x01; /* as per WUSB 1.0 spec */ - scratch->ax.ccm_nonce = *n; - scratch->ax.counter = 0; - - /* reuse the CBC-MAC transform to perform the single block encryption */ - crypto_shash_digest(desc, (u8 *)&scratch->ax, sizeof(scratch->ax), - (u8 *)&scratch->ax); - - crypto_xor_cpy(mic, (u8 *)&scratch->ax, iv, 8); - - return 8; -} - -/* - * WUSB Pseudo Random Function (WUSB1.0[6.5]) - * - * @b: buffer to the source data; cannot be a global or const local - * (will confuse the scatterlists) - */ -ssize_t wusb_prf(void *out, size_t out_size, - const u8 key[16], const struct aes_ccm_nonce *_n, - const struct aes_ccm_label *a, - const void *b, size_t blen, size_t len) -{ - ssize_t result, bytes = 0, bitr; - struct aes_ccm_nonce n = *_n; - struct crypto_shash *tfm_cbcmac; - struct wusb_mac_scratch scratch; - u64 sfn = 0; - __le64 sfn_le; - - tfm_cbcmac = crypto_alloc_shash("cbcmac(aes)", 0, 0); - if (IS_ERR(tfm_cbcmac)) { - result = PTR_ERR(tfm_cbcmac); - printk(KERN_ERR "E: can't load CBCMAC-AES: %d\n", (int)result); - goto error_alloc_cbcmac; - } - - result = crypto_shash_setkey(tfm_cbcmac, key, AES_BLOCK_SIZE); - if (result < 0) { - printk(KERN_ERR "E: can't set CBCMAC-AES key: %d\n", (int)result); - goto error_setkey_cbcmac; - } - - for (bitr = 0; bitr < (len + 63) / 64; bitr++) { - sfn_le = cpu_to_le64(sfn++); - memcpy(&n.sfn, &sfn_le, sizeof(n.sfn)); /* n.sfn++... */ - result = wusb_ccm_mac(tfm_cbcmac, &scratch, out + bytes, - &n, a, b, blen); - if (result < 0) - goto error_ccm_mac; - bytes += result; - } - result = bytes; - -error_ccm_mac: -error_setkey_cbcmac: - crypto_free_shash(tfm_cbcmac); -error_alloc_cbcmac: - return result; -} - -/* WUSB1.0[A.2] test vectors */ -static const u8 stv_hsmic_key[16] = { - 0x4b, 0x79, 0xa3, 0xcf, 0xe5, 0x53, 0x23, 0x9d, - 0xd7, 0xc1, 0x6d, 0x1c, 0x2d, 0xab, 0x6d, 0x3f -}; - -static const struct aes_ccm_nonce stv_hsmic_n = { - .sfn = { 0 }, - .tkid = { 0x76, 0x98, 0x01, }, - .dest_addr = { .data = { 0xbe, 0x00 } }, - .src_addr = { .data = { 0x76, 0x98 } }, -}; - -/* - * Out-of-band MIC Generation verification code - * - */ -static int wusb_oob_mic_verify(void) -{ - int result; - u8 mic[8]; - /* WUSB1.0[A.2] test vectors */ - static const struct usb_handshake stv_hsmic_hs = { - .bMessageNumber = 2, - .bStatus = 00, - .tTKID = { 0x76, 0x98, 0x01 }, - .bReserved = 00, - .CDID = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, - 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, - 0x3c, 0x3d, 0x3e, 0x3f }, - .nonce = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, - 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, - 0x2c, 0x2d, 0x2e, 0x2f }, - .MIC = { 0x75, 0x6a, 0x97, 0x51, 0x0c, 0x8c, - 0x14, 0x7b }, - }; - size_t hs_size; - - result = wusb_oob_mic(mic, stv_hsmic_key, &stv_hsmic_n, &stv_hsmic_hs); - if (result < 0) - printk(KERN_ERR "E: WUSB OOB MIC test: failed: %d\n", result); - else if (memcmp(stv_hsmic_hs.MIC, mic, sizeof(mic))) { - printk(KERN_ERR "E: OOB MIC test: " - "mismatch between MIC result and WUSB1.0[A2]\n"); - hs_size = sizeof(stv_hsmic_hs) - sizeof(stv_hsmic_hs.MIC); - printk(KERN_ERR "E: Handshake2 in: (%zu bytes)\n", hs_size); - wusb_key_dump(&stv_hsmic_hs, hs_size); - printk(KERN_ERR "E: CCM Nonce in: (%zu bytes)\n", - sizeof(stv_hsmic_n)); - wusb_key_dump(&stv_hsmic_n, sizeof(stv_hsmic_n)); - printk(KERN_ERR "E: MIC out:\n"); - wusb_key_dump(mic, sizeof(mic)); - printk(KERN_ERR "E: MIC out (from WUSB1.0[A.2]):\n"); - wusb_key_dump(stv_hsmic_hs.MIC, sizeof(stv_hsmic_hs.MIC)); - result = -EINVAL; - } else - result = 0; - return result; -} - -/* - * Test vectors for Key derivation - * - * These come from WUSB1.0[6.5.1], the vectors in WUSB1.0[A.1] - * (errata corrected in 2005/07). - */ -static const u8 stv_key_a1[16] __attribute__ ((__aligned__(4))) = { - 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, - 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f -}; - -static const struct aes_ccm_nonce stv_keydvt_n_a1 = { - .sfn = { 0 }, - .tkid = { 0x76, 0x98, 0x01, }, - .dest_addr = { .data = { 0xbe, 0x00 } }, - .src_addr = { .data = { 0x76, 0x98 } }, -}; - -static const struct wusb_keydvt_out stv_keydvt_out_a1 = { - .kck = { - 0x4b, 0x79, 0xa3, 0xcf, 0xe5, 0x53, 0x23, 0x9d, - 0xd7, 0xc1, 0x6d, 0x1c, 0x2d, 0xab, 0x6d, 0x3f - }, - .ptk = { - 0xc8, 0x70, 0x62, 0x82, 0xb6, 0x7c, 0xe9, 0x06, - 0x7b, 0xc5, 0x25, 0x69, 0xf2, 0x36, 0x61, 0x2d - } -}; - -/* - * Performa a test to make sure we match the vectors defined in - * WUSB1.0[A.1](Errata2006/12) - */ -static int wusb_key_derive_verify(void) -{ - int result = 0; - struct wusb_keydvt_out keydvt_out; - /* These come from WUSB1.0[A.1] + 2006/12 errata */ - static const struct wusb_keydvt_in stv_keydvt_in_a1 = { - .hnonce = { - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f - }, - .dnonce = { - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f - } - }; - - result = wusb_key_derive(&keydvt_out, stv_key_a1, &stv_keydvt_n_a1, - &stv_keydvt_in_a1); - if (result < 0) - printk(KERN_ERR "E: WUSB key derivation test: " - "derivation failed: %d\n", result); - if (memcmp(&stv_keydvt_out_a1, &keydvt_out, sizeof(keydvt_out))) { - printk(KERN_ERR "E: WUSB key derivation test: " - "mismatch between key derivation result " - "and WUSB1.0[A1] Errata 2006/12\n"); - printk(KERN_ERR "E: keydvt in: key\n"); - wusb_key_dump(stv_key_a1, sizeof(stv_key_a1)); - printk(KERN_ERR "E: keydvt in: nonce\n"); - wusb_key_dump(&stv_keydvt_n_a1, sizeof(stv_keydvt_n_a1)); - printk(KERN_ERR "E: keydvt in: hnonce & dnonce\n"); - wusb_key_dump(&stv_keydvt_in_a1, sizeof(stv_keydvt_in_a1)); - printk(KERN_ERR "E: keydvt out: KCK\n"); - wusb_key_dump(&keydvt_out.kck, sizeof(keydvt_out.kck)); - printk(KERN_ERR "E: keydvt out: PTK\n"); - wusb_key_dump(&keydvt_out.ptk, sizeof(keydvt_out.ptk)); - result = -EINVAL; - } else - result = 0; - return result; -} - -/* - * Initialize crypto system - * - * FIXME: we do nothing now, other than verifying. Later on we'll - * cache the encryption stuff, so that's why we have a separate init. - */ -int wusb_crypto_init(void) -{ - int result; - - if (debug_crypto_verify) { - result = wusb_key_derive_verify(); - if (result < 0) - return result; - return wusb_oob_mic_verify(); - } - return 0; -} - -void wusb_crypto_exit(void) -{ - /* FIXME: free cached crypto transforms */ -} diff --git a/drivers/staging/wusbcore/dev-sysfs.c b/drivers/staging/wusbcore/dev-sysfs.c deleted file mode 100644 index 67b0a4c412b2..000000000000 --- a/drivers/staging/wusbcore/dev-sysfs.c +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB devices - * sysfs bindings - * - * Copyright (C) 2007 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Get them out of the way... - */ - -#include <linux/jiffies.h> -#include <linux/ctype.h> -#include <linux/workqueue.h> -#include "wusbhc.h" - -static ssize_t wusb_disconnect_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct usb_device *usb_dev; - struct wusbhc *wusbhc; - unsigned command; - u8 port_idx; - - if (sscanf(buf, "%u", &command) != 1) - return -EINVAL; - if (command == 0) - return size; - usb_dev = to_usb_device(dev); - wusbhc = wusbhc_get_by_usb_dev(usb_dev); - if (wusbhc == NULL) - return -ENODEV; - - mutex_lock(&wusbhc->mutex); - port_idx = wusb_port_no_to_idx(usb_dev->portnum); - __wusbhc_dev_disable(wusbhc, port_idx); - mutex_unlock(&wusbhc->mutex); - wusbhc_put(wusbhc); - return size; -} -static DEVICE_ATTR_WO(wusb_disconnect); - -static ssize_t wusb_cdid_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - ssize_t result; - struct wusb_dev *wusb_dev; - - wusb_dev = wusb_dev_get_by_usb_dev(to_usb_device(dev)); - if (wusb_dev == NULL) - return -ENODEV; - result = sprintf(buf, "%16ph\n", wusb_dev->cdid.data); - wusb_dev_put(wusb_dev); - return result; -} -static DEVICE_ATTR_RO(wusb_cdid); - -static ssize_t wusb_ck_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - int result; - struct usb_device *usb_dev; - struct wusbhc *wusbhc; - struct wusb_ckhdid ck; - - result = sscanf(buf, - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx\n", - &ck.data[0] , &ck.data[1], - &ck.data[2] , &ck.data[3], - &ck.data[4] , &ck.data[5], - &ck.data[6] , &ck.data[7], - &ck.data[8] , &ck.data[9], - &ck.data[10], &ck.data[11], - &ck.data[12], &ck.data[13], - &ck.data[14], &ck.data[15]); - if (result != 16) - return -EINVAL; - - usb_dev = to_usb_device(dev); - wusbhc = wusbhc_get_by_usb_dev(usb_dev); - if (wusbhc == NULL) - return -ENODEV; - result = wusb_dev_4way_handshake(wusbhc, usb_dev->wusb_dev, &ck); - memzero_explicit(&ck, sizeof(ck)); - wusbhc_put(wusbhc); - return result < 0 ? result : size; -} -static DEVICE_ATTR_WO(wusb_ck); - -static struct attribute *wusb_dev_attrs[] = { - &dev_attr_wusb_disconnect.attr, - &dev_attr_wusb_cdid.attr, - &dev_attr_wusb_ck.attr, - NULL, -}; - -static const struct attribute_group wusb_dev_attr_group = { - .name = NULL, /* we want them in the same directory */ - .attrs = wusb_dev_attrs, -}; - -int wusb_dev_sysfs_add(struct wusbhc *wusbhc, struct usb_device *usb_dev, - struct wusb_dev *wusb_dev) -{ - int result = sysfs_create_group(&usb_dev->dev.kobj, - &wusb_dev_attr_group); - struct device *dev = &usb_dev->dev; - if (result < 0) - dev_err(dev, "Cannot register WUSB-dev attributes: %d\n", - result); - return result; -} - -void wusb_dev_sysfs_rm(struct wusb_dev *wusb_dev) -{ - struct usb_device *usb_dev = wusb_dev->usb_dev; - if (usb_dev) - sysfs_remove_group(&usb_dev->dev.kobj, &wusb_dev_attr_group); -} diff --git a/drivers/staging/wusbcore/devconnect.c b/drivers/staging/wusbcore/devconnect.c deleted file mode 100644 index 1170f8baf608..000000000000 --- a/drivers/staging/wusbcore/devconnect.c +++ /dev/null @@ -1,1085 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB Wire Adapter: Control/Data Streaming Interface (WUSB[8]) - * Device Connect handling - * - * Copyright (C) 2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * FIXME: this file needs to be broken up, it's grown too big - * - * - * WUSB1.0[7.1, 7.5.1, ] - * - * WUSB device connection is kind of messy. Some background: - * - * When a device wants to connect it scans the UWB radio channels - * looking for a WUSB Channel; a WUSB channel is defined by MMCs - * (Micro Managed Commands or something like that) [see - * Design-overview for more on this] . - * - * So, device scans the radio, finds MMCs and thus a host and checks - * when the next DNTS is. It sends a Device Notification Connect - * (DN_Connect); the host picks it up (through nep.c and notif.c, ends - * up in wusb_devconnect_ack(), which creates a wusb_dev structure in - * wusbhc->port[port_number].wusb_dev), assigns an unauth address - * to the device (this means from 0x80 to 0xfe) and sends, in the MMC - * a Connect Ack Information Element (ConnAck IE). - * - * So now the device now has a WUSB address. From now on, we use - * that to talk to it in the RPipes. - * - * ASSUMPTIONS: - * - * - We use the the as device address the port number where it is - * connected (port 0 doesn't exist). For unauth, it is 128 + that. - * - * ROADMAP: - * - * This file contains the logic for doing that--entry points: - * - * wusb_devconnect_ack() Ack a device until _acked() called. - * Called by notif.c:wusb_handle_dn_connect() - * when a DN_Connect is received. - * - * wusb_devconnect_acked() Ack done, release resources. - * - * wusb_handle_dn_alive() Called by notif.c:wusb_handle_dn() - * for processing a DN_Alive pong from a device. - * - * wusb_handle_dn_disconnect()Called by notif.c:wusb_handle_dn() to - * process a disconnect request from a - * device. - * - * __wusb_dev_disable() Called by rh.c:wusbhc_rh_clear_port_feat() when - * disabling a port. - * - * wusb_devconnect_create() Called when creating the host by - * lc.c:wusbhc_create(). - * - * wusb_devconnect_destroy() Cleanup called removing the host. Called - * by lc.c:wusbhc_destroy(). - * - * Each Wireless USB host maintains a list of DN_Connect requests - * (actually we maintain a list of pending Connect Acks, the - * wusbhc->ca_list). - * - * LIFE CYCLE OF port->wusb_dev - * - * Before the @wusbhc structure put()s the reference it owns for - * port->wusb_dev [and clean the wusb_dev pointer], it needs to - * lock @wusbhc->mutex. - */ - -#include <linux/jiffies.h> -#include <linux/ctype.h> -#include <linux/slab.h> -#include <linux/workqueue.h> -#include <linux/export.h> -#include "wusbhc.h" - -static void wusbhc_devconnect_acked_work(struct work_struct *work); - -static void wusb_dev_free(struct wusb_dev *wusb_dev) -{ - kfree(wusb_dev); -} - -static struct wusb_dev *wusb_dev_alloc(struct wusbhc *wusbhc) -{ - struct wusb_dev *wusb_dev; - - wusb_dev = kzalloc(sizeof(*wusb_dev), GFP_KERNEL); - if (wusb_dev == NULL) - goto err; - - wusb_dev->wusbhc = wusbhc; - - INIT_WORK(&wusb_dev->devconnect_acked_work, wusbhc_devconnect_acked_work); - - return wusb_dev; -err: - wusb_dev_free(wusb_dev); - return NULL; -} - - -/* - * Using the Connect-Ack list, fill out the @wusbhc Connect-Ack WUSB IE - * properly so that it can be added to the MMC. - * - * We just get the @wusbhc->ca_list and fill out the first four ones or - * less (per-spec WUSB1.0[7.5, before T7-38). If the ConnectAck WUSB - * IE is not allocated, we alloc it. - * - * @wusbhc->mutex must be taken - */ -static void wusbhc_fill_cack_ie(struct wusbhc *wusbhc) -{ - unsigned cnt; - struct wusb_dev *dev_itr; - struct wuie_connect_ack *cack_ie; - - cack_ie = &wusbhc->cack_ie; - cnt = 0; - list_for_each_entry(dev_itr, &wusbhc->cack_list, cack_node) { - cack_ie->blk[cnt].CDID = dev_itr->cdid; - cack_ie->blk[cnt].bDeviceAddress = dev_itr->addr; - if (++cnt >= WUIE_ELT_MAX) - break; - } - cack_ie->hdr.bLength = sizeof(cack_ie->hdr) - + cnt * sizeof(cack_ie->blk[0]); -} - -/* - * Register a new device that wants to connect - * - * A new device wants to connect, so we add it to the Connect-Ack - * list. We give it an address in the unauthorized range (bit 8 set); - * user space will have to drive authorization further on. - * - * @dev_addr: address to use for the device (which is also the port - * number). - * - * @wusbhc->mutex must be taken - */ -static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc, - struct wusb_dn_connect *dnc, - const char *pr_cdid, u8 port_idx) -{ - struct device *dev = wusbhc->dev; - struct wusb_dev *wusb_dev; - int new_connection = wusb_dn_connect_new_connection(dnc); - u8 dev_addr; - int result; - - /* Is it registered already? */ - list_for_each_entry(wusb_dev, &wusbhc->cack_list, cack_node) - if (!memcmp(&wusb_dev->cdid, &dnc->CDID, - sizeof(wusb_dev->cdid))) - return wusb_dev; - /* We don't have it, create an entry, register it */ - wusb_dev = wusb_dev_alloc(wusbhc); - if (wusb_dev == NULL) - return NULL; - wusb_dev_init(wusb_dev); - wusb_dev->cdid = dnc->CDID; - wusb_dev->port_idx = port_idx; - - /* - * Devices are always available within the cluster reservation - * and since the hardware will take the intersection of the - * per-device availability and the cluster reservation, the - * per-device availability can simply be set to always - * available. - */ - bitmap_fill(wusb_dev->availability.bm, UWB_NUM_MAS); - - /* FIXME: handle reconnects instead of assuming connects are - always new. */ - if (1 && new_connection == 0) - new_connection = 1; - if (new_connection) { - dev_addr = (port_idx + 2) | WUSB_DEV_ADDR_UNAUTH; - - dev_info(dev, "Connecting new WUSB device to address %u, " - "port %u\n", dev_addr, port_idx); - - result = wusb_set_dev_addr(wusbhc, wusb_dev, dev_addr); - if (result < 0) - return NULL; - } - wusb_dev->entry_ts = jiffies; - list_add_tail(&wusb_dev->cack_node, &wusbhc->cack_list); - wusbhc->cack_count++; - wusbhc_fill_cack_ie(wusbhc); - - return wusb_dev; -} - -/* - * Remove a Connect-Ack context entry from the HCs view - * - * @wusbhc->mutex must be taken - */ -static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - list_del_init(&wusb_dev->cack_node); - wusbhc->cack_count--; - wusbhc_fill_cack_ie(wusbhc); -} - -/* - * @wusbhc->mutex must be taken */ -static -void wusbhc_devconnect_acked(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - wusbhc_cack_rm(wusbhc, wusb_dev); - if (wusbhc->cack_count) - wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr); - else - wusbhc_mmcie_rm(wusbhc, &wusbhc->cack_ie.hdr); -} - -static void wusbhc_devconnect_acked_work(struct work_struct *work) -{ - struct wusb_dev *wusb_dev = container_of(work, struct wusb_dev, - devconnect_acked_work); - struct wusbhc *wusbhc = wusb_dev->wusbhc; - - mutex_lock(&wusbhc->mutex); - wusbhc_devconnect_acked(wusbhc, wusb_dev); - mutex_unlock(&wusbhc->mutex); - - wusb_dev_put(wusb_dev); -} - -/* - * Ack a device for connection - * - * FIXME: docs - * - * @pr_cdid: Printable CDID...hex Use @dnc->cdid for the real deal. - * - * So we get the connect ack IE (may have been allocated already), - * find an empty connect block, an empty virtual port, create an - * address with it (see below), make it an unauth addr [bit 7 set] and - * set the MMC. - * - * Addresses: because WUSB hosts have no downstream hubs, we can do a - * 1:1 mapping between 'port number' and device - * address. This simplifies many things, as during this - * initial connect phase the USB stack has no knowledge of - * the device and hasn't assigned an address yet--we know - * USB's choose_address() will use the same heuristics we - * use here, so we can assume which address will be assigned. - * - * USB stack always assigns address 1 to the root hub, so - * to the port number we add 2 (thus virtual port #0 is - * addr #2). - * - * @wusbhc shall be referenced - */ -static -void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc, - const char *pr_cdid) -{ - int result; - struct device *dev = wusbhc->dev; - struct wusb_dev *wusb_dev; - struct wusb_port *port; - unsigned idx; - - mutex_lock(&wusbhc->mutex); - - /* Check we are not handling it already */ - for (idx = 0; idx < wusbhc->ports_max; idx++) { - port = wusb_port_by_idx(wusbhc, idx); - if (port->wusb_dev - && memcmp(&dnc->CDID, &port->wusb_dev->cdid, sizeof(dnc->CDID)) == 0) - goto error_unlock; - } - /* Look up those fake ports we have for a free one */ - for (idx = 0; idx < wusbhc->ports_max; idx++) { - port = wusb_port_by_idx(wusbhc, idx); - if ((port->status & USB_PORT_STAT_POWER) - && !(port->status & USB_PORT_STAT_CONNECTION)) - break; - } - if (idx >= wusbhc->ports_max) { - dev_err(dev, "Host controller can't connect more devices " - "(%u already connected); device %s rejected\n", - wusbhc->ports_max, pr_cdid); - /* NOTE: we could send a WUIE_Disconnect here, but we haven't - * event acked, so the device will eventually timeout the - * connection, right? */ - goto error_unlock; - } - - /* Make sure we are using no crypto on that "virtual port" */ - wusbhc->set_ptk(wusbhc, idx, 0, NULL, 0); - - /* Grab a filled in Connect-Ack context, fill out the - * Connect-Ack Wireless USB IE, set the MMC */ - wusb_dev = wusbhc_cack_add(wusbhc, dnc, pr_cdid, idx); - if (wusb_dev == NULL) - goto error_unlock; - result = wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr); - if (result < 0) - goto error_unlock; - /* Give the device at least 2ms (WUSB1.0[7.5.1p3]), let's do - * three for a good measure */ - msleep(3); - port->wusb_dev = wusb_dev; - port->status |= USB_PORT_STAT_CONNECTION; - port->change |= USB_PORT_STAT_C_CONNECTION; - /* Now the port status changed to connected; hub_wq will - * pick the change up and try to reset the port to bring it to - * the enabled state--so this process returns up to the stack - * and it calls back into wusbhc_rh_port_reset(). - */ -error_unlock: - mutex_unlock(&wusbhc->mutex); - return; - -} - -/* - * Disconnect a Wireless USB device from its fake port - * - * Marks the port as disconnected so that hub_wq can pick up the change - * and drops our knowledge about the device. - * - * Assumes there is a device connected - * - * @port_index: zero based port number - * - * NOTE: @wusbhc->mutex is locked - * - * WARNING: From here it is not very safe to access anything hanging off - * wusb_dev - */ -static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc, - struct wusb_port *port) -{ - struct wusb_dev *wusb_dev = port->wusb_dev; - - port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE - | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET - | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED); - port->change |= USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE; - if (wusb_dev) { - dev_dbg(wusbhc->dev, "disconnecting device from port %d\n", wusb_dev->port_idx); - if (!list_empty(&wusb_dev->cack_node)) - list_del_init(&wusb_dev->cack_node); - /* For the one in cack_add() */ - wusb_dev_put(wusb_dev); - } - port->wusb_dev = NULL; - - /* After a device disconnects, change the GTK (see [WUSB] - * section 6.2.11.2). */ - if (wusbhc->active) - wusbhc_gtk_rekey(wusbhc); - - /* The Wireless USB part has forgotten about the device already; now - * hub_wq's timer will pick up the disconnection and remove the USB - * device from the system - */ -} - -/* - * Refresh the list of keep alives to emit in the MMC - * - * We only publish the first four devices that have a coming timeout - * condition. Then when we are done processing those, we go for the - * next ones. We ignore the ones that have timed out already (they'll - * be purged). - * - * This might cause the first devices to timeout the last devices in - * the port array...FIXME: come up with a better algorithm? - * - * Note we can't do much about MMC's ops errors; we hope next refresh - * will kind of handle it. - * - * NOTE: @wusbhc->mutex is locked - */ -static void __wusbhc_keep_alive(struct wusbhc *wusbhc) -{ - struct device *dev = wusbhc->dev; - unsigned cnt; - struct wusb_dev *wusb_dev; - struct wusb_port *wusb_port; - struct wuie_keep_alive *ie = &wusbhc->keep_alive_ie; - unsigned keep_alives, old_keep_alives; - - old_keep_alives = ie->hdr.bLength - sizeof(ie->hdr); - keep_alives = 0; - for (cnt = 0; - keep_alives < WUIE_ELT_MAX && cnt < wusbhc->ports_max; - cnt++) { - unsigned tt = msecs_to_jiffies(wusbhc->trust_timeout); - - wusb_port = wusb_port_by_idx(wusbhc, cnt); - wusb_dev = wusb_port->wusb_dev; - - if (wusb_dev == NULL) - continue; - if (wusb_dev->usb_dev == NULL) - continue; - - if (time_after(jiffies, wusb_dev->entry_ts + tt)) { - dev_err(dev, "KEEPALIVE: device %u timed out\n", - wusb_dev->addr); - __wusbhc_dev_disconnect(wusbhc, wusb_port); - } else if (time_after(jiffies, wusb_dev->entry_ts + tt/3)) { - /* Approaching timeout cut off, need to refresh */ - ie->bDeviceAddress[keep_alives++] = wusb_dev->addr; - } - } - if (keep_alives & 0x1) /* pad to even number ([WUSB] section 7.5.9) */ - ie->bDeviceAddress[keep_alives++] = 0x7f; - ie->hdr.bLength = sizeof(ie->hdr) + - keep_alives*sizeof(ie->bDeviceAddress[0]); - if (keep_alives > 0) - wusbhc_mmcie_set(wusbhc, 10, 5, &ie->hdr); - else if (old_keep_alives != 0) - wusbhc_mmcie_rm(wusbhc, &ie->hdr); -} - -/* - * Do a run through all devices checking for timeouts - */ -static void wusbhc_keep_alive_run(struct work_struct *ws) -{ - struct delayed_work *dw = to_delayed_work(ws); - struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer); - - mutex_lock(&wusbhc->mutex); - __wusbhc_keep_alive(wusbhc); - mutex_unlock(&wusbhc->mutex); - - queue_delayed_work(wusbd, &wusbhc->keep_alive_timer, - msecs_to_jiffies(wusbhc->trust_timeout / 2)); -} - -/* - * Find the wusb_dev from its device address. - * - * The device can be found directly from the address (see - * wusb_cack_add() for where the device address is set to port_idx - * +2), except when the address is zero. - */ -static struct wusb_dev *wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr) -{ - int p; - - if (addr == 0xff) /* unconnected */ - return NULL; - - if (addr > 0) { - int port = (addr & ~0x80) - 2; - if (port < 0 || port >= wusbhc->ports_max) - return NULL; - return wusb_port_by_idx(wusbhc, port)->wusb_dev; - } - - /* Look for the device with address 0. */ - for (p = 0; p < wusbhc->ports_max; p++) { - struct wusb_dev *wusb_dev = wusb_port_by_idx(wusbhc, p)->wusb_dev; - if (wusb_dev && wusb_dev->addr == addr) - return wusb_dev; - } - return NULL; -} - -/* - * Handle a DN_Alive notification (WUSB1.0[7.6.1]) - * - * This just updates the device activity timestamp and then refreshes - * the keep alive IE. - * - * @wusbhc shall be referenced and unlocked - */ -static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, u8 srcaddr) -{ - struct wusb_dev *wusb_dev; - - mutex_lock(&wusbhc->mutex); - wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr); - if (wusb_dev == NULL) { - dev_dbg(wusbhc->dev, "ignoring DN_Alive from unconnected device %02x\n", - srcaddr); - } else { - wusb_dev->entry_ts = jiffies; - __wusbhc_keep_alive(wusbhc); - } - mutex_unlock(&wusbhc->mutex); -} - -/* - * Handle a DN_Connect notification (WUSB1.0[7.6.1]) - * - * @wusbhc - * @pkt_hdr - * @size: Size of the buffer where the notification resides; if the - * notification data suggests there should be more data than - * available, an error will be signaled and the whole buffer - * consumed. - * - * @wusbhc->mutex shall be held - */ -static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc, - struct wusb_dn_hdr *dn_hdr, - size_t size) -{ - struct device *dev = wusbhc->dev; - struct wusb_dn_connect *dnc; - char pr_cdid[WUSB_CKHDID_STRSIZE]; - static const char *beacon_behaviour[] = { - "reserved", - "self-beacon", - "directed-beacon", - "no-beacon" - }; - - if (size < sizeof(*dnc)) { - dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n", - size, sizeof(*dnc)); - return; - } - - dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr); - sprintf(pr_cdid, "%16ph", dnc->CDID.data); - dev_info(dev, "DN CONNECT: device %s @ %x (%s) wants to %s\n", - pr_cdid, - wusb_dn_connect_prev_dev_addr(dnc), - beacon_behaviour[wusb_dn_connect_beacon_behavior(dnc)], - wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect"); - /* ACK the connect */ - wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid); -} - -/* - * Handle a DN_Disconnect notification (WUSB1.0[7.6.1]) - * - * Device is going down -- do the disconnect. - * - * @wusbhc shall be referenced and unlocked - */ -static void wusbhc_handle_dn_disconnect(struct wusbhc *wusbhc, u8 srcaddr) -{ - struct device *dev = wusbhc->dev; - struct wusb_dev *wusb_dev; - - mutex_lock(&wusbhc->mutex); - wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr); - if (wusb_dev == NULL) { - dev_dbg(dev, "ignoring DN DISCONNECT from unconnected device %02x\n", - srcaddr); - } else { - dev_info(dev, "DN DISCONNECT: device 0x%02x going down\n", - wusb_dev->addr); - __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, - wusb_dev->port_idx)); - } - mutex_unlock(&wusbhc->mutex); -} - -/* - * Handle a Device Notification coming a host - * - * The Device Notification comes from a host (HWA, DWA or WHCI) - * wrapped in a set of headers. Somebody else has peeled off those - * headers for us and we just get one Device Notifications. - * - * Invalid DNs (e.g., too short) are discarded. - * - * @wusbhc shall be referenced - * - * FIXMES: - * - implement priorities as in WUSB1.0[Table 7-55]? - */ -void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr, - struct wusb_dn_hdr *dn_hdr, size_t size) -{ - struct device *dev = wusbhc->dev; - - if (size < sizeof(struct wusb_dn_hdr)) { - dev_err(dev, "DN data shorter than DN header (%d < %d)\n", - (int)size, (int)sizeof(struct wusb_dn_hdr)); - return; - } - switch (dn_hdr->bType) { - case WUSB_DN_CONNECT: - wusbhc_handle_dn_connect(wusbhc, dn_hdr, size); - break; - case WUSB_DN_ALIVE: - wusbhc_handle_dn_alive(wusbhc, srcaddr); - break; - case WUSB_DN_DISCONNECT: - wusbhc_handle_dn_disconnect(wusbhc, srcaddr); - break; - case WUSB_DN_MASAVAILCHANGED: - case WUSB_DN_RWAKE: - case WUSB_DN_SLEEP: - /* FIXME: handle these DNs. */ - break; - case WUSB_DN_EPRDY: - /* The hardware handles these. */ - break; - default: - dev_warn(dev, "unknown DN %u (%d octets) from %u\n", - dn_hdr->bType, (int)size, srcaddr); - } -} -EXPORT_SYMBOL_GPL(wusbhc_handle_dn); - -/* - * Disconnect a WUSB device from a the cluster - * - * @wusbhc - * @port Fake port where the device is (wusbhc index, not USB port number). - * - * In Wireless USB, a disconnect is basically telling the device he is - * being disconnected and forgetting about him. - * - * We send the device a Device Disconnect IE (WUSB1.0[7.5.11]) for 100 - * ms and then keep going. - * - * We don't do much in case of error; we always pretend we disabled - * the port and disconnected the device. If physically the request - * didn't get there (many things can fail in the way there), the stack - * will reject the device's communication attempts. - * - * @wusbhc should be refcounted and locked - */ -void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port_idx) -{ - int result; - struct device *dev = wusbhc->dev; - struct wusb_dev *wusb_dev; - struct wuie_disconnect *ie; - - wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev; - if (wusb_dev == NULL) { - /* reset no device? ignore */ - dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n", - port_idx); - return; - } - __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx)); - - ie = kzalloc(sizeof(*ie), GFP_KERNEL); - if (ie == NULL) - return; - ie->hdr.bLength = sizeof(*ie); - ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT; - ie->bDeviceAddress = wusb_dev->addr; - result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr); - if (result < 0) - dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result); - else { - /* At least 6 MMCs, assuming at least 1 MMC per zone. */ - msleep(7*4); - wusbhc_mmcie_rm(wusbhc, &ie->hdr); - } - kfree(ie); -} - -/* - * Walk over the BOS descriptor, verify and grok it - * - * @usb_dev: referenced - * @wusb_dev: referenced and unlocked - * - * The BOS descriptor is defined at WUSB1.0[7.4.1], and it defines a - * "flexible" way to wrap all kinds of descriptors inside an standard - * descriptor (wonder why they didn't use normal descriptors, - * btw). Not like they lack code. - * - * At the end we go to look for the WUSB Device Capabilities - * (WUSB1.0[7.4.1.1]) that is wrapped in a device capability descriptor - * that is part of the BOS descriptor set. That tells us what does the - * device support (dual role, beacon type, UWB PHY rates). - */ -static int wusb_dev_bos_grok(struct usb_device *usb_dev, - struct wusb_dev *wusb_dev, - struct usb_bos_descriptor *bos, size_t desc_size) -{ - ssize_t result; - struct device *dev = &usb_dev->dev; - void *itr, *top; - - /* Walk over BOS capabilities, verify them */ - itr = (void *)bos + sizeof(*bos); - top = itr + desc_size - sizeof(*bos); - while (itr < top) { - struct usb_dev_cap_header *cap_hdr = itr; - size_t cap_size; - u8 cap_type; - if (top - itr < sizeof(*cap_hdr)) { - dev_err(dev, "Device BUG? premature end of BOS header " - "data [offset 0x%02x]: only %zu bytes left\n", - (int)(itr - (void *)bos), top - itr); - result = -ENOSPC; - goto error_bad_cap; - } - cap_size = cap_hdr->bLength; - cap_type = cap_hdr->bDevCapabilityType; - if (cap_size == 0) - break; - if (cap_size > top - itr) { - dev_err(dev, "Device BUG? premature end of BOS data " - "[offset 0x%02x cap %02x %zu bytes]: " - "only %zu bytes left\n", - (int)(itr - (void *)bos), - cap_type, cap_size, top - itr); - result = -EBADF; - goto error_bad_cap; - } - switch (cap_type) { - case USB_CAP_TYPE_WIRELESS_USB: - if (cap_size != sizeof(*wusb_dev->wusb_cap_descr)) - dev_err(dev, "Device BUG? WUSB Capability " - "descriptor is %zu bytes vs %zu " - "needed\n", cap_size, - sizeof(*wusb_dev->wusb_cap_descr)); - else - wusb_dev->wusb_cap_descr = itr; - break; - default: - dev_err(dev, "BUG? Unknown BOS capability 0x%02x " - "(%zu bytes) at offset 0x%02x\n", cap_type, - cap_size, (int)(itr - (void *)bos)); - } - itr += cap_size; - } - result = 0; -error_bad_cap: - return result; -} - -/* - * Add information from the BOS descriptors to the device - * - * @usb_dev: referenced - * @wusb_dev: referenced and unlocked - * - * So what we do is we alloc a space for the BOS descriptor of 64 - * bytes; read the first four bytes which include the wTotalLength - * field (WUSB1.0[T7-26]) and if it fits in those 64 bytes, read the - * whole thing. If not we realloc to that size. - * - * Then we call the groking function, that will fill up - * wusb_dev->wusb_cap_descr, which is what we'll need later on. - */ -static int wusb_dev_bos_add(struct usb_device *usb_dev, - struct wusb_dev *wusb_dev) -{ - ssize_t result; - struct device *dev = &usb_dev->dev; - struct usb_bos_descriptor *bos; - size_t alloc_size = 32, desc_size = 4; - - bos = kmalloc(alloc_size, GFP_KERNEL); - if (bos == NULL) - return -ENOMEM; - result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size); - if (result < 4) { - dev_err(dev, "Can't get BOS descriptor or too short: %zd\n", - result); - goto error_get_descriptor; - } - desc_size = le16_to_cpu(bos->wTotalLength); - if (desc_size >= alloc_size) { - kfree(bos); - alloc_size = desc_size; - bos = kmalloc(alloc_size, GFP_KERNEL); - if (bos == NULL) - return -ENOMEM; - } - result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size); - if (result < 0 || result != desc_size) { - dev_err(dev, "Can't get BOS descriptor or too short (need " - "%zu bytes): %zd\n", desc_size, result); - goto error_get_descriptor; - } - if (result < sizeof(*bos) - || le16_to_cpu(bos->wTotalLength) != desc_size) { - dev_err(dev, "Can't get BOS descriptor or too short (need " - "%zu bytes): %zd\n", desc_size, result); - goto error_get_descriptor; - } - - result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result); - if (result < 0) - goto error_bad_bos; - wusb_dev->bos = bos; - return 0; - -error_bad_bos: -error_get_descriptor: - kfree(bos); - wusb_dev->wusb_cap_descr = NULL; - return result; -} - -static void wusb_dev_bos_rm(struct wusb_dev *wusb_dev) -{ - kfree(wusb_dev->bos); - wusb_dev->wusb_cap_descr = NULL; -}; - -/* - * USB stack's device addition Notifier Callback - * - * Called from drivers/usb/core/hub.c when a new device is added; we - * use this hook to perform certain WUSB specific setup work on the - * new device. As well, it is the first time we can connect the - * wusb_dev and the usb_dev. So we note it down in wusb_dev and take a - * reference that we'll drop. - * - * First we need to determine if the device is a WUSB device (else we - * ignore it). For that we use the speed setting (USB_SPEED_WIRELESS) - * [FIXME: maybe we'd need something more definitive]. If so, we track - * it's usb_busd and from there, the WUSB HC. - * - * Because all WUSB HCs are contained in a 'struct wusbhc', voila, we - * get the wusbhc for the device. - * - * We have a reference on @usb_dev (as we are called at the end of its - * enumeration). - * - * NOTE: @usb_dev locked - */ -static void wusb_dev_add_ncb(struct usb_device *usb_dev) -{ - int result = 0; - struct wusb_dev *wusb_dev; - struct wusbhc *wusbhc; - struct device *dev = &usb_dev->dev; - u8 port_idx; - - if (usb_dev->wusb == 0 || usb_dev->devnum == 1) - return; /* skip non wusb and wusb RHs */ - - usb_set_device_state(usb_dev, USB_STATE_UNAUTHENTICATED); - - wusbhc = wusbhc_get_by_usb_dev(usb_dev); - if (wusbhc == NULL) - goto error_nodev; - mutex_lock(&wusbhc->mutex); - wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev); - port_idx = wusb_port_no_to_idx(usb_dev->portnum); - mutex_unlock(&wusbhc->mutex); - if (wusb_dev == NULL) - goto error_nodev; - wusb_dev->usb_dev = usb_get_dev(usb_dev); - usb_dev->wusb_dev = wusb_dev_get(wusb_dev); - result = wusb_dev_sec_add(wusbhc, usb_dev, wusb_dev); - if (result < 0) { - dev_err(dev, "Cannot enable security: %d\n", result); - goto error_sec_add; - } - /* Now query the device for it's BOS and attach it to wusb_dev */ - result = wusb_dev_bos_add(usb_dev, wusb_dev); - if (result < 0) { - dev_err(dev, "Cannot get BOS descriptors: %d\n", result); - goto error_bos_add; - } - result = wusb_dev_sysfs_add(wusbhc, usb_dev, wusb_dev); - if (result < 0) - goto error_add_sysfs; -out: - wusb_dev_put(wusb_dev); - wusbhc_put(wusbhc); -error_nodev: - return; - -error_add_sysfs: - wusb_dev_bos_rm(wusb_dev); -error_bos_add: - wusb_dev_sec_rm(wusb_dev); -error_sec_add: - mutex_lock(&wusbhc->mutex); - __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx)); - mutex_unlock(&wusbhc->mutex); - goto out; -} - -/* - * Undo all the steps done at connection by the notifier callback - * - * NOTE: @usb_dev locked - */ -static void wusb_dev_rm_ncb(struct usb_device *usb_dev) -{ - struct wusb_dev *wusb_dev = usb_dev->wusb_dev; - - if (usb_dev->wusb == 0 || usb_dev->devnum == 1) - return; /* skip non wusb and wusb RHs */ - - wusb_dev_sysfs_rm(wusb_dev); - wusb_dev_bos_rm(wusb_dev); - wusb_dev_sec_rm(wusb_dev); - wusb_dev->usb_dev = NULL; - usb_dev->wusb_dev = NULL; - wusb_dev_put(wusb_dev); - usb_put_dev(usb_dev); -} - -/* - * Handle notifications from the USB stack (notifier call back) - * - * This is called when the USB stack does a - * usb_{bus,device}_{add,remove}() so we can do WUSB specific - * handling. It is called with [for the case of - * USB_DEVICE_{ADD,REMOVE} with the usb_dev locked. - */ -int wusb_usb_ncb(struct notifier_block *nb, unsigned long val, - void *priv) -{ - int result = NOTIFY_OK; - - switch (val) { - case USB_DEVICE_ADD: - wusb_dev_add_ncb(priv); - break; - case USB_DEVICE_REMOVE: - wusb_dev_rm_ncb(priv); - break; - case USB_BUS_ADD: - /* ignore (for now) */ - case USB_BUS_REMOVE: - break; - default: - WARN_ON(1); - result = NOTIFY_BAD; - } - return result; -} - -/* - * Return a referenced wusb_dev given a @wusbhc and @usb_dev - */ -struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *wusbhc, - struct usb_device *usb_dev) -{ - struct wusb_dev *wusb_dev; - u8 port_idx; - - port_idx = wusb_port_no_to_idx(usb_dev->portnum); - BUG_ON(port_idx > wusbhc->ports_max); - wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev; - if (wusb_dev != NULL) /* ops, device is gone */ - wusb_dev_get(wusb_dev); - return wusb_dev; -} -EXPORT_SYMBOL_GPL(__wusb_dev_get_by_usb_dev); - -void wusb_dev_destroy(struct kref *_wusb_dev) -{ - struct wusb_dev *wusb_dev = container_of(_wusb_dev, struct wusb_dev, refcnt); - - list_del_init(&wusb_dev->cack_node); - wusb_dev_free(wusb_dev); -} -EXPORT_SYMBOL_GPL(wusb_dev_destroy); - -/* - * Create all the device connect handling infrastructure - * - * This is basically the device info array, Connect Acknowledgement - * (cack) lists, keep-alive timers (and delayed work thread). - */ -int wusbhc_devconnect_create(struct wusbhc *wusbhc) -{ - wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE; - wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr); - INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run); - - wusbhc->cack_ie.hdr.bIEIdentifier = WUIE_ID_CONNECTACK; - wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr); - INIT_LIST_HEAD(&wusbhc->cack_list); - - return 0; -} - -/* - * Release all resources taken by the devconnect stuff - */ -void wusbhc_devconnect_destroy(struct wusbhc *wusbhc) -{ - /* no op */ -} - -/* - * wusbhc_devconnect_start - start accepting device connections - * @wusbhc: the WUSB HC - * - * Sets the Host Info IE to accept all new connections. - * - * FIXME: This also enables the keep alives but this is not necessary - * until there are connected and authenticated devices. - */ -int wusbhc_devconnect_start(struct wusbhc *wusbhc) -{ - struct device *dev = wusbhc->dev; - struct wuie_host_info *hi; - int result; - - hi = kzalloc(sizeof(*hi), GFP_KERNEL); - if (hi == NULL) - return -ENOMEM; - - hi->hdr.bLength = sizeof(*hi); - hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO; - hi->attributes = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL); - hi->CHID = wusbhc->chid; - result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr); - if (result < 0) { - dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result); - goto error_mmcie_set; - } - wusbhc->wuie_host_info = hi; - - queue_delayed_work(wusbd, &wusbhc->keep_alive_timer, - msecs_to_jiffies(wusbhc->trust_timeout / 2)); - - return 0; - -error_mmcie_set: - kfree(hi); - return result; -} - -/* - * wusbhc_devconnect_stop - stop managing connected devices - * @wusbhc: the WUSB HC - * - * Disconnects any devices still connected, stops the keep alives and - * removes the Host Info IE. - */ -void wusbhc_devconnect_stop(struct wusbhc *wusbhc) -{ - int i; - - mutex_lock(&wusbhc->mutex); - for (i = 0; i < wusbhc->ports_max; i++) { - if (wusbhc->port[i].wusb_dev) - __wusbhc_dev_disconnect(wusbhc, &wusbhc->port[i]); - } - mutex_unlock(&wusbhc->mutex); - - cancel_delayed_work_sync(&wusbhc->keep_alive_timer); - wusbhc_mmcie_rm(wusbhc, &wusbhc->wuie_host_info->hdr); - kfree(wusbhc->wuie_host_info); - wusbhc->wuie_host_info = NULL; -} - -/* - * wusb_set_dev_addr - set the WUSB device address used by the host - * @wusbhc: the WUSB HC the device is connect to - * @wusb_dev: the WUSB device - * @addr: new device address - */ -int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, u8 addr) -{ - int result; - - wusb_dev->addr = addr; - result = wusbhc->dev_info_set(wusbhc, wusb_dev); - if (result < 0) - dev_err(wusbhc->dev, "device %d: failed to set device " - "address\n", wusb_dev->port_idx); - else - dev_info(wusbhc->dev, "device %d: %s addr %u\n", - wusb_dev->port_idx, - (addr & WUSB_DEV_ADDR_UNAUTH) ? "unauth" : "auth", - wusb_dev->addr); - - return result; -} diff --git a/drivers/staging/wusbcore/host/Kconfig b/drivers/staging/wusbcore/host/Kconfig deleted file mode 100644 index 9a73f9360a08..000000000000 --- a/drivers/staging/wusbcore/host/Kconfig +++ /dev/null @@ -1,28 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -config USB_WHCI_HCD - tristate "Wireless USB Host Controller Interface (WHCI) driver" - depends on USB_PCI && USB && UWB - select USB_WUSB - select UWB_WHCI - help - A driver for PCI-based Wireless USB Host Controllers that are - compliant with the WHCI specification. - - To compile this driver a module, choose M here: the module - will be called "whci-hcd". - -config USB_HWA_HCD - tristate "Host Wire Adapter (HWA) driver" - depends on USB && UWB - select USB_WUSB - select UWB_HWA - help - This driver enables you to connect Wireless USB devices to - your system using a Host Wire Adaptor USB dongle. This is an - UWB Radio Controller and WUSB Host Controller connected to - your machine via USB (specified in WUSB1.0). - - To compile this driver a module, choose M here: the module - will be called "hwa-hc". - diff --git a/drivers/staging/wusbcore/host/Makefile b/drivers/staging/wusbcore/host/Makefile deleted file mode 100644 index d65ee8a73e21..000000000000 --- a/drivers/staging/wusbcore/host/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_USB_WHCI_HCD) += whci/ -obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o diff --git a/drivers/staging/wusbcore/host/hwa-hc.c b/drivers/staging/wusbcore/host/hwa-hc.c deleted file mode 100644 index 8d959e91fe27..000000000000 --- a/drivers/staging/wusbcore/host/hwa-hc.c +++ /dev/null @@ -1,875 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Host Wire Adapter: - * Driver glue, HWA-specific functions, bridges to WAHC and WUSBHC - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * The HWA driver is a simple layer that forwards requests to the WAHC - * (Wire Adater Host Controller) or WUSBHC (Wireless USB Host - * Controller) layers. - * - * Host Wire Adapter is the 'WUSB 1.0 standard' name for Wireless-USB - * Host Controller that is connected to your system via USB (a USB - * dongle that implements a USB host...). There is also a Device Wired - * Adaptor, DWA (Wireless USB hub) that uses the same mechanism for - * transferring data (it is after all a USB host connected via - * Wireless USB), we have a common layer called Wire Adapter Host - * Controller that does all the hard work. The WUSBHC (Wireless USB - * Host Controller) is the part common to WUSB Host Controllers, the - * HWA and the PCI-based one, that is implemented following the WHCI - * spec. All these layers are implemented in ../wusbcore. - * - * The main functions are hwahc_op_urb_{en,de}queue(), that pass the - * job of converting a URB to a Wire Adapter - * - * Entry points: - * - * hwahc_driver_*() Driver initialization, registration and - * teardown. - * - * hwahc_probe() New device came up, create an instance for - * it [from device enumeration]. - * - * hwahc_disconnect() Remove device instance [from device - * enumeration]. - * - * [__]hwahc_op_*() Host-Wire-Adaptor specific functions for - * starting/stopping/etc (some might be made also - * DWA). - */ -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/module.h> -#include <linux/workqueue.h> -#include <linux/wait.h> -#include <linux/completion.h> -#include "../wa-hc.h" -#include "../wusbhc.h" - -struct hwahc { - struct wusbhc wusbhc; /* has to be 1st */ - struct wahc wa; -}; - -/* - * FIXME should be wusbhc - * - * NOTE: we need to cache the Cluster ID because later...there is no - * way to get it :) - */ -static int __hwahc_set_cluster_id(struct hwahc *hwahc, u8 cluster_id) -{ - int result; - struct wusbhc *wusbhc = &hwahc->wusbhc; - struct wahc *wa = &hwahc->wa; - struct device *dev = &wa->usb_iface->dev; - - result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_SET_CLUSTER_ID, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - cluster_id, - wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) - dev_err(dev, "Cannot set WUSB Cluster ID to 0x%02x: %d\n", - cluster_id, result); - else - wusbhc->cluster_id = cluster_id; - dev_info(dev, "Wireless USB Cluster ID set to 0x%02x\n", cluster_id); - return result; -} - -static int __hwahc_op_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots) -{ - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - - return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_SET_NUM_DNTS, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - interval << 8 | slots, - wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - NULL, 0, USB_CTRL_SET_TIMEOUT); -} - -/* - * Reset a WUSB host controller and wait for it to complete doing it. - * - * @usb_hcd: Pointer to WUSB Host Controller instance. - * - */ -static int hwahc_op_reset(struct usb_hcd *usb_hcd) -{ - int result; - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct device *dev = &hwahc->wa.usb_iface->dev; - - mutex_lock(&wusbhc->mutex); - wa_nep_disarm(&hwahc->wa); - result = __wa_set_feature(&hwahc->wa, WA_RESET); - if (result < 0) { - dev_err(dev, "error commanding HC to reset: %d\n", result); - goto error_unlock; - } - result = __wa_wait_status(&hwahc->wa, WA_STATUS_RESETTING, 0); - if (result < 0) { - dev_err(dev, "error waiting for HC to reset: %d\n", result); - goto error_unlock; - } -error_unlock: - mutex_unlock(&wusbhc->mutex); - return result; -} - -/* - * FIXME: break this function up - */ -static int hwahc_op_start(struct usb_hcd *usb_hcd) -{ - u8 addr; - int result; - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - - result = -ENOSPC; - mutex_lock(&wusbhc->mutex); - addr = wusb_cluster_id_get(); - if (addr == 0) - goto error_cluster_id_get; - result = __hwahc_set_cluster_id(hwahc, addr); - if (result < 0) - goto error_set_cluster_id; - - usb_hcd->uses_new_polling = 1; - set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags); - usb_hcd->state = HC_STATE_RUNNING; - - /* - * prevent USB core from suspending the root hub since - * bus_suspend and bus_resume are not yet supported. - */ - pm_runtime_get_noresume(&usb_hcd->self.root_hub->dev); - - result = 0; -out: - mutex_unlock(&wusbhc->mutex); - return result; - -error_set_cluster_id: - wusb_cluster_id_put(addr); -error_cluster_id_get: - goto out; - -} - -/* - * No need to abort pipes, as when this is called, all the children - * has been disconnected and that has done it [through - * usb_disable_interface() -> usb_disable_endpoint() -> - * hwahc_op_ep_disable() - >rpipe_ep_disable()]. - */ -static void hwahc_op_stop(struct usb_hcd *usb_hcd) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - - mutex_lock(&wusbhc->mutex); - wusb_cluster_id_put(wusbhc->cluster_id); - mutex_unlock(&wusbhc->mutex); -} - -static int hwahc_op_get_frame_number(struct usb_hcd *usb_hcd) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - - /* - * We cannot query the HWA for the WUSB time since that requires sending - * a synchronous URB and this function can be called in_interrupt. - * Instead, query the USB frame number for our parent and use that. - */ - return usb_get_current_frame_number(wa->usb_dev); -} - -static int hwahc_op_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, - gfp_t gfp) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - - return wa_urb_enqueue(&hwahc->wa, urb->ep, urb, gfp); -} - -static int hwahc_op_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, - int status) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - - return wa_urb_dequeue(&hwahc->wa, urb, status); -} - -/* - * Release resources allocated for an endpoint - * - * If there is an associated rpipe to this endpoint, go ahead and put it. - */ -static void hwahc_op_endpoint_disable(struct usb_hcd *usb_hcd, - struct usb_host_endpoint *ep) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - - rpipe_ep_disable(&hwahc->wa, ep); -} - -static int __hwahc_op_wusbhc_start(struct wusbhc *wusbhc) -{ - int result; - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct device *dev = &hwahc->wa.usb_iface->dev; - - result = __wa_set_feature(&hwahc->wa, WA_ENABLE); - if (result < 0) { - dev_err(dev, "error commanding HC to start: %d\n", result); - goto error_stop; - } - result = __wa_wait_status(&hwahc->wa, WA_ENABLE, WA_ENABLE); - if (result < 0) { - dev_err(dev, "error waiting for HC to start: %d\n", result); - goto error_stop; - } - result = wa_nep_arm(&hwahc->wa, GFP_KERNEL); - if (result < 0) { - dev_err(dev, "cannot listen to notifications: %d\n", result); - goto error_stop; - } - /* - * If WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS is set, - * disable transfer notifications. - */ - if (hwahc->wa.quirks & - WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS) { - struct usb_host_interface *cur_altsetting = - hwahc->wa.usb_iface->cur_altsetting; - - result = usb_control_msg(hwahc->wa.usb_dev, - usb_sndctrlpipe(hwahc->wa.usb_dev, 0), - WA_REQ_ALEREON_DISABLE_XFER_NOTIFICATIONS, - USB_DIR_OUT | USB_TYPE_VENDOR | - USB_RECIP_INTERFACE, - WA_REQ_ALEREON_FEATURE_SET, - cur_altsetting->desc.bInterfaceNumber, - NULL, 0, - USB_CTRL_SET_TIMEOUT); - /* - * If we successfully sent the control message, start DTI here - * because no transfer notifications will be received which is - * where DTI is normally started. - */ - if (result == 0) - result = wa_dti_start(&hwahc->wa); - else - result = 0; /* OK. Continue normally. */ - - if (result < 0) { - dev_err(dev, "cannot start DTI: %d\n", result); - goto error_dti_start; - } - } - - return result; - -error_dti_start: - wa_nep_disarm(&hwahc->wa); -error_stop: - __wa_clear_feature(&hwahc->wa, WA_ENABLE); - return result; -} - -static void __hwahc_op_wusbhc_stop(struct wusbhc *wusbhc, int delay) -{ - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - int ret; - - ret = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_CHAN_STOP, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - delay * 1000, - iface_no, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (ret == 0) - msleep(delay); - - wa_nep_disarm(&hwahc->wa); - __wa_stop(&hwahc->wa); -} - -/* - * Set the UWB MAS allocation for the WUSB cluster - * - * @stream_index: stream to use (-1 for cancelling the allocation) - * @mas: mas bitmap to use - */ -static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index, - const struct uwb_mas_bm *mas) -{ - int result; - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - struct device *dev = &wa->usb_iface->dev; - u8 mas_le[UWB_NUM_MAS/8]; - - /* Set the stream index */ - result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_SET_STREAM_IDX, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - stream_index, - wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Cannot set WUSB stream index: %d\n", result); - goto out; - } - uwb_mas_bm_copy_le(mas_le, mas); - /* Set the MAS allocation */ - result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_SET_WUSB_MAS, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - mas_le, 32, USB_CTRL_SET_TIMEOUT); - if (result < 0) - dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result); -out: - return result; -} - -/* - * Add an IE to the host's MMC - * - * @interval: See WUSB1.0[8.5.3.1] - * @repeat_cnt: See WUSB1.0[8.5.3.1] - * @handle: See WUSB1.0[8.5.3.1] - * @wuie: Pointer to the header of the WUSB IE data to add. - * MUST BE allocated in a kmalloc buffer (no stack or - * vmalloc). - * - * NOTE: the format of the WUSB IEs for MMCs are different to the - * normal MBOA MAC IEs (IE Id + Length in MBOA MAC vs. Length + - * Id in WUSB IEs). Standards...you gotta love'em. - */ -static int __hwahc_op_mmcie_add(struct wusbhc *wusbhc, u8 interval, - u8 repeat_cnt, u8 handle, - struct wuie_hdr *wuie) -{ - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - - return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_ADD_MMC_IE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - interval << 8 | repeat_cnt, - handle << 8 | iface_no, - wuie, wuie->bLength, USB_CTRL_SET_TIMEOUT); -} - -/* - * Remove an IE to the host's MMC - * - * @handle: See WUSB1.0[8.5.3.1] - */ -static int __hwahc_op_mmcie_rm(struct wusbhc *wusbhc, u8 handle) -{ - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_REMOVE_MMC_IE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, handle << 8 | iface_no, - NULL, 0, USB_CTRL_SET_TIMEOUT); -} - -/* - * Update device information for a given fake port - * - * @port_idx: Fake port to which device is connected (wusbhc index, not - * USB port number). - */ -static int __hwahc_op_dev_info_set(struct wusbhc *wusbhc, - struct wusb_dev *wusb_dev) -{ - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - struct hwa_dev_info *dev_info; - int ret; - - /* fill out the Device Info buffer and send it */ - dev_info = kzalloc(sizeof(struct hwa_dev_info), GFP_KERNEL); - if (!dev_info) - return -ENOMEM; - uwb_mas_bm_copy_le(dev_info->bmDeviceAvailability, - &wusb_dev->availability); - dev_info->bDeviceAddress = wusb_dev->addr; - - /* - * If the descriptors haven't been read yet, use a default PHY - * rate of 53.3 Mbit/s only. The correct value will be used - * when this will be called again as part of the - * authentication process (which occurs after the descriptors - * have been read). - */ - if (wusb_dev->wusb_cap_descr) - dev_info->wPHYRates = wusb_dev->wusb_cap_descr->wPHYRates; - else - dev_info->wPHYRates = cpu_to_le16(USB_WIRELESS_PHY_53); - - ret = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - WUSB_REQ_SET_DEV_INFO, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, wusb_dev->port_idx << 8 | iface_no, - dev_info, sizeof(struct hwa_dev_info), - USB_CTRL_SET_TIMEOUT); - kfree(dev_info); - return ret; -} - -/* - * Set host's idea of which encryption (and key) method to use when - * talking to ad evice on a given port. - * - * If key is NULL, it means disable encryption for that "virtual port" - * (used when we disconnect). - */ -static int __hwahc_dev_set_key(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, - const void *key, size_t key_size, - u8 key_idx) -{ - int result = -ENOMEM; - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - struct usb_key_descriptor *keyd; - size_t keyd_len; - - keyd_len = sizeof(*keyd) + key_size; - keyd = kzalloc(keyd_len, GFP_KERNEL); - if (keyd == NULL) - return -ENOMEM; - - keyd->bLength = keyd_len; - keyd->bDescriptorType = USB_DT_KEY; - keyd->tTKID[0] = (tkid >> 0) & 0xff; - keyd->tTKID[1] = (tkid >> 8) & 0xff; - keyd->tTKID[2] = (tkid >> 16) & 0xff; - memcpy(keyd->bKeyData, key, key_size); - - result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_SET_DESCRIPTOR, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - USB_DT_KEY << 8 | key_idx, - port_idx << 8 | iface_no, - keyd, keyd_len, USB_CTRL_SET_TIMEOUT); - - kzfree(keyd); /* clear keys etc. */ - return result; -} - -/* - * Set host's idea of which encryption (and key) method to use when - * talking to ad evice on a given port. - * - * If key is NULL, it means disable encryption for that "virtual port" - * (used when we disconnect). - */ -static int __hwahc_op_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, - const void *key, size_t key_size) -{ - int result = -ENOMEM; - struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc); - struct wahc *wa = &hwahc->wa; - u8 iface_no = wa->usb_iface->cur_altsetting->desc.bInterfaceNumber; - u8 encryption_value; - - /* Tell the host which key to use to talk to the device */ - if (key) { - u8 key_idx = wusb_key_index(0, WUSB_KEY_INDEX_TYPE_PTK, - WUSB_KEY_INDEX_ORIGINATOR_HOST); - - result = __hwahc_dev_set_key(wusbhc, port_idx, tkid, - key, key_size, key_idx); - if (result < 0) - goto error_set_key; - encryption_value = wusbhc->ccm1_etd->bEncryptionValue; - } else { - /* FIXME: this should come from wusbhc->etd[UNSECURE].value */ - encryption_value = 0; - } - - /* Set the encryption type for communicating with the device */ - result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_SET_ENCRYPTION, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - encryption_value, port_idx << 8 | iface_no, - NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) - dev_err(wusbhc->dev, "Can't set host's WUSB encryption for " - "port index %u to %s (value %d): %d\n", port_idx, - wusb_et_name(wusbhc->ccm1_etd->bEncryptionType), - wusbhc->ccm1_etd->bEncryptionValue, result); -error_set_key: - return result; -} - -/* - * Set host's GTK key - */ -static int __hwahc_op_set_gtk(struct wusbhc *wusbhc, u32 tkid, - const void *key, size_t key_size) -{ - u8 key_idx = wusb_key_index(0, WUSB_KEY_INDEX_TYPE_GTK, - WUSB_KEY_INDEX_ORIGINATOR_HOST); - - return __hwahc_dev_set_key(wusbhc, 0, tkid, key, key_size, key_idx); -} - -/* - * Get the Wire Adapter class-specific descriptor - * - * NOTE: this descriptor comes with the big bundled configuration - * descriptor that includes the interfaces' and endpoints', so - * we just look for it in the cached copy kept by the USB stack. - * - * NOTE2: We convert LE fields to CPU order. - */ -static int wa_fill_descr(struct wahc *wa) -{ - int result; - struct device *dev = &wa->usb_iface->dev; - char *itr; - struct usb_device *usb_dev = wa->usb_dev; - struct usb_descriptor_header *hdr; - struct usb_wa_descriptor *wa_descr; - size_t itr_size, actconfig_idx; - - actconfig_idx = (usb_dev->actconfig - usb_dev->config) / - sizeof(usb_dev->config[0]); - itr = usb_dev->rawdescriptors[actconfig_idx]; - itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength); - while (itr_size >= sizeof(*hdr)) { - hdr = (struct usb_descriptor_header *) itr; - dev_dbg(dev, "Extra device descriptor: " - "type %02x/%u bytes @ %zu (%zu left)\n", - hdr->bDescriptorType, hdr->bLength, - (itr - usb_dev->rawdescriptors[actconfig_idx]), - itr_size); - if (hdr->bDescriptorType == USB_DT_WIRE_ADAPTER) - goto found; - itr += hdr->bLength; - itr_size -= hdr->bLength; - } - dev_err(dev, "cannot find Wire Adapter Class descriptor\n"); - return -ENODEV; - -found: - result = -EINVAL; - if (hdr->bLength > itr_size) { /* is it available? */ - dev_err(dev, "incomplete Wire Adapter Class descriptor " - "(%zu bytes left, %u needed)\n", - itr_size, hdr->bLength); - goto error; - } - if (hdr->bLength < sizeof(*wa->wa_descr)) { - dev_err(dev, "short Wire Adapter Class descriptor\n"); - goto error; - } - wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; - if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100) - dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", - (le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00) >> 8, - le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff); - result = 0; -error: - return result; -} - -static const struct hc_driver hwahc_hc_driver = { - .description = "hwa-hcd", - .product_desc = "Wireless USB HWA host controller", - .hcd_priv_size = sizeof(struct hwahc) - sizeof(struct usb_hcd), - .irq = NULL, /* FIXME */ - .flags = HCD_USB25, - .reset = hwahc_op_reset, - .start = hwahc_op_start, - .stop = hwahc_op_stop, - .get_frame_number = hwahc_op_get_frame_number, - .urb_enqueue = hwahc_op_urb_enqueue, - .urb_dequeue = hwahc_op_urb_dequeue, - .endpoint_disable = hwahc_op_endpoint_disable, - - .hub_status_data = wusbhc_rh_status_data, - .hub_control = wusbhc_rh_control, - .start_port_reset = wusbhc_rh_start_port_reset, -}; - -static int hwahc_security_create(struct hwahc *hwahc) -{ - int result; - struct wusbhc *wusbhc = &hwahc->wusbhc; - struct usb_device *usb_dev = hwahc->wa.usb_dev; - struct device *dev = &usb_dev->dev; - struct usb_security_descriptor *secd; - struct usb_encryption_descriptor *etd; - void *itr, *top; - size_t itr_size, needed, bytes; - u8 index; - char buf[64]; - - /* Find the host's security descriptors in the config descr bundle */ - index = (usb_dev->actconfig - usb_dev->config) / - sizeof(usb_dev->config[0]); - itr = usb_dev->rawdescriptors[index]; - itr_size = le16_to_cpu(usb_dev->actconfig->desc.wTotalLength); - top = itr + itr_size; - result = __usb_get_extra_descriptor(usb_dev->rawdescriptors[index], - le16_to_cpu(usb_dev->actconfig->desc.wTotalLength), - USB_DT_SECURITY, (void **) &secd, sizeof(*secd)); - if (result == -1) { - dev_warn(dev, "BUG? WUSB host has no security descriptors\n"); - return 0; - } - needed = sizeof(*secd); - if (top - (void *)secd < needed) { - dev_err(dev, "BUG? Not enough data to process security " - "descriptor header (%zu bytes left vs %zu needed)\n", - top - (void *) secd, needed); - return 0; - } - needed = le16_to_cpu(secd->wTotalLength); - if (top - (void *)secd < needed) { - dev_err(dev, "BUG? Not enough data to process security " - "descriptors (%zu bytes left vs %zu needed)\n", - top - (void *) secd, needed); - return 0; - } - /* Walk over the sec descriptors and store CCM1's on wusbhc */ - itr = (void *) secd + sizeof(*secd); - top = (void *) secd + le16_to_cpu(secd->wTotalLength); - index = 0; - bytes = 0; - while (itr < top) { - etd = itr; - if (top - itr < sizeof(*etd)) { - dev_err(dev, "BUG: bad host security descriptor; " - "not enough data (%zu vs %zu left)\n", - top - itr, sizeof(*etd)); - break; - } - if (etd->bLength < sizeof(*etd)) { - dev_err(dev, "BUG: bad host encryption descriptor; " - "descriptor is too short " - "(%zu vs %zu needed)\n", - (size_t)etd->bLength, sizeof(*etd)); - break; - } - itr += etd->bLength; - bytes += snprintf(buf + bytes, sizeof(buf) - bytes, - "%s (0x%02x) ", - wusb_et_name(etd->bEncryptionType), - etd->bEncryptionValue); - wusbhc->ccm1_etd = etd; - } - dev_info(dev, "supported encryption types: %s\n", buf); - if (wusbhc->ccm1_etd == NULL) { - dev_err(dev, "E: host doesn't support CCM-1 crypto\n"); - return 0; - } - /* Pretty print what we support */ - return 0; -} - -static void hwahc_security_release(struct hwahc *hwahc) -{ - /* nothing to do here so far... */ -} - -static int hwahc_create(struct hwahc *hwahc, struct usb_interface *iface, - kernel_ulong_t quirks) -{ - int result; - struct device *dev = &iface->dev; - struct wusbhc *wusbhc = &hwahc->wusbhc; - struct wahc *wa = &hwahc->wa; - struct usb_device *usb_dev = interface_to_usbdev(iface); - - wa->usb_dev = usb_get_dev(usb_dev); /* bind the USB device */ - wa->usb_iface = usb_get_intf(iface); - wusbhc->dev = dev; - /* defer getting the uwb_rc handle until it is needed since it - * may not have been registered by the hwa_rc driver yet. */ - wusbhc->uwb_rc = NULL; - result = wa_fill_descr(wa); /* Get the device descriptor */ - if (result < 0) - goto error_fill_descriptor; - if (wa->wa_descr->bNumPorts > USB_MAXCHILDREN) { - dev_err(dev, "FIXME: USB_MAXCHILDREN too low for WUSB " - "adapter (%u ports)\n", wa->wa_descr->bNumPorts); - wusbhc->ports_max = USB_MAXCHILDREN; - } else { - wusbhc->ports_max = wa->wa_descr->bNumPorts; - } - wusbhc->mmcies_max = wa->wa_descr->bNumMMCIEs; - wusbhc->start = __hwahc_op_wusbhc_start; - wusbhc->stop = __hwahc_op_wusbhc_stop; - wusbhc->mmcie_add = __hwahc_op_mmcie_add; - wusbhc->mmcie_rm = __hwahc_op_mmcie_rm; - wusbhc->dev_info_set = __hwahc_op_dev_info_set; - wusbhc->bwa_set = __hwahc_op_bwa_set; - wusbhc->set_num_dnts = __hwahc_op_set_num_dnts; - wusbhc->set_ptk = __hwahc_op_set_ptk; - wusbhc->set_gtk = __hwahc_op_set_gtk; - result = hwahc_security_create(hwahc); - if (result < 0) { - dev_err(dev, "Can't initialize security: %d\n", result); - goto error_security_create; - } - wa->wusb = wusbhc; /* FIXME: ugly, need to fix */ - result = wusbhc_create(&hwahc->wusbhc); - if (result < 0) { - dev_err(dev, "Can't create WUSB HC structures: %d\n", result); - goto error_wusbhc_create; - } - result = wa_create(&hwahc->wa, iface, quirks); - if (result < 0) - goto error_wa_create; - return 0; - -error_wa_create: - wusbhc_destroy(&hwahc->wusbhc); -error_wusbhc_create: - /* WA Descr fill allocs no resources */ -error_security_create: -error_fill_descriptor: - usb_put_intf(iface); - usb_put_dev(usb_dev); - return result; -} - -static void hwahc_destroy(struct hwahc *hwahc) -{ - struct wusbhc *wusbhc = &hwahc->wusbhc; - - mutex_lock(&wusbhc->mutex); - __wa_destroy(&hwahc->wa); - wusbhc_destroy(&hwahc->wusbhc); - hwahc_security_release(hwahc); - hwahc->wusbhc.dev = NULL; - uwb_rc_put(wusbhc->uwb_rc); - usb_put_intf(hwahc->wa.usb_iface); - usb_put_dev(hwahc->wa.usb_dev); - mutex_unlock(&wusbhc->mutex); -} - -static void hwahc_init(struct hwahc *hwahc) -{ - wa_init(&hwahc->wa); -} - -static int hwahc_probe(struct usb_interface *usb_iface, - const struct usb_device_id *id) -{ - int result; - struct usb_hcd *usb_hcd; - struct wusbhc *wusbhc; - struct hwahc *hwahc; - struct device *dev = &usb_iface->dev; - - result = -ENOMEM; - usb_hcd = usb_create_hcd(&hwahc_hc_driver, &usb_iface->dev, "wusb-hwa"); - if (usb_hcd == NULL) { - dev_err(dev, "unable to allocate instance\n"); - goto error_alloc; - } - usb_hcd->wireless = 1; - usb_hcd->self.sg_tablesize = ~0; - wusbhc = usb_hcd_to_wusbhc(usb_hcd); - hwahc = container_of(wusbhc, struct hwahc, wusbhc); - hwahc_init(hwahc); - result = hwahc_create(hwahc, usb_iface, id->driver_info); - if (result < 0) { - dev_err(dev, "Cannot initialize internals: %d\n", result); - goto error_hwahc_create; - } - result = usb_add_hcd(usb_hcd, 0, 0); - if (result < 0) { - dev_err(dev, "Cannot add HCD: %d\n", result); - goto error_add_hcd; - } - device_wakeup_enable(usb_hcd->self.controller); - result = wusbhc_b_create(&hwahc->wusbhc); - if (result < 0) { - dev_err(dev, "Cannot setup phase B of WUSBHC: %d\n", result); - goto error_wusbhc_b_create; - } - return 0; - -error_wusbhc_b_create: - usb_remove_hcd(usb_hcd); -error_add_hcd: - hwahc_destroy(hwahc); -error_hwahc_create: - usb_put_hcd(usb_hcd); -error_alloc: - return result; -} - -static void hwahc_disconnect(struct usb_interface *usb_iface) -{ - struct usb_hcd *usb_hcd; - struct wusbhc *wusbhc; - struct hwahc *hwahc; - - usb_hcd = usb_get_intfdata(usb_iface); - wusbhc = usb_hcd_to_wusbhc(usb_hcd); - hwahc = container_of(wusbhc, struct hwahc, wusbhc); - - wusbhc_b_destroy(&hwahc->wusbhc); - usb_remove_hcd(usb_hcd); - hwahc_destroy(hwahc); - usb_put_hcd(usb_hcd); -} - -static const struct usb_device_id hwahc_id_table[] = { - /* Alereon 5310 */ - { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5310, 0xe0, 0x02, 0x01), - .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC | - WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS }, - /* Alereon 5611 */ - { USB_DEVICE_AND_INTERFACE_INFO(0x13dc, 0x5611, 0xe0, 0x02, 0x01), - .driver_info = WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC | - WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS }, - /* FIXME: use class labels for this */ - { USB_INTERFACE_INFO(0xe0, 0x02, 0x01), }, - {}, -}; -MODULE_DEVICE_TABLE(usb, hwahc_id_table); - -static struct usb_driver hwahc_driver = { - .name = "hwa-hc", - .probe = hwahc_probe, - .disconnect = hwahc_disconnect, - .id_table = hwahc_id_table, -}; - -module_usb_driver(hwahc_driver); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Host Wired Adapter USB Host Control Driver"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wusbcore/host/whci/Makefile b/drivers/staging/wusbcore/host/whci/Makefile deleted file mode 100644 index 859d20079df6..000000000000 --- a/drivers/staging/wusbcore/host/whci/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 - -obj-$(CONFIG_USB_WHCI_HCD) += whci-hcd.o - -whci-hcd-y := \ - asl.o \ - debug.o \ - hcd.o \ - hw.o \ - init.o \ - int.o \ - pzl.o \ - qset.o \ - wusb.o diff --git a/drivers/staging/wusbcore/host/whci/asl.c b/drivers/staging/wusbcore/host/whci/asl.c deleted file mode 100644 index a2b9a50cfb80..000000000000 --- a/drivers/staging/wusbcore/host/whci/asl.c +++ /dev/null @@ -1,376 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) asynchronous schedule management. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/gfp.h> -#include <linux/dma-mapping.h> -#include <linux/usb.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -static void qset_get_next_prev(struct whc *whc, struct whc_qset *qset, - struct whc_qset **next, struct whc_qset **prev) -{ - struct list_head *n, *p; - - BUG_ON(list_empty(&whc->async_list)); - - n = qset->list_node.next; - if (n == &whc->async_list) - n = n->next; - p = qset->list_node.prev; - if (p == &whc->async_list) - p = p->prev; - - *next = container_of(n, struct whc_qset, list_node); - *prev = container_of(p, struct whc_qset, list_node); - -} - -static void asl_qset_insert_begin(struct whc *whc, struct whc_qset *qset) -{ - list_move(&qset->list_node, &whc->async_list); - qset->in_sw_list = true; -} - -static void asl_qset_insert(struct whc *whc, struct whc_qset *qset) -{ - struct whc_qset *next, *prev; - - qset_clear(whc, qset); - - /* Link into ASL. */ - qset_get_next_prev(whc, qset, &next, &prev); - whc_qset_set_link_ptr(&qset->qh.link, next->qset_dma); - whc_qset_set_link_ptr(&prev->qh.link, qset->qset_dma); - qset->in_hw_list = true; -} - -static void asl_qset_remove(struct whc *whc, struct whc_qset *qset) -{ - struct whc_qset *prev, *next; - - qset_get_next_prev(whc, qset, &next, &prev); - - list_move(&qset->list_node, &whc->async_removed_list); - qset->in_sw_list = false; - - /* - * No more qsets in the ASL? The caller must stop the ASL as - * it's no longer valid. - */ - if (list_empty(&whc->async_list)) - return; - - /* Remove from ASL. */ - whc_qset_set_link_ptr(&prev->qh.link, next->qset_dma); - qset->in_hw_list = false; -} - -/** - * process_qset - process any recently inactivated or halted qTDs in a - * qset. - * - * After inactive qTDs are removed, new qTDs can be added if the - * urb queue still contains URBs. - * - * Returns any additional WUSBCMD bits for the ASL sync command (i.e., - * WUSBCMD_ASYNC_QSET_RM if a halted qset was removed). - */ -static uint32_t process_qset(struct whc *whc, struct whc_qset *qset) -{ - enum whc_update update = 0; - uint32_t status = 0; - - while (qset->ntds) { - struct whc_qtd *td; - - td = &qset->qtd[qset->td_start]; - status = le32_to_cpu(td->status); - - /* - * Nothing to do with a still active qTD. - */ - if (status & QTD_STS_ACTIVE) - break; - - if (status & QTD_STS_HALTED) { - /* Ug, an error. */ - process_halted_qtd(whc, qset, td); - /* A halted qTD always triggers an update - because the qset was either removed or - reactivated. */ - update |= WHC_UPDATE_UPDATED; - goto done; - } - - /* Mmm, a completed qTD. */ - process_inactive_qtd(whc, qset, td); - } - - if (!qset->remove) - update |= qset_add_qtds(whc, qset); - -done: - /* - * Remove this qset from the ASL if requested, but only if has - * no qTDs. - */ - if (qset->remove && qset->ntds == 0) { - asl_qset_remove(whc, qset); - update |= WHC_UPDATE_REMOVED; - } - return update; -} - -void asl_start(struct whc *whc) -{ - struct whc_qset *qset; - - qset = list_first_entry(&whc->async_list, struct whc_qset, list_node); - - le_writeq(qset->qset_dma | QH_LINK_NTDS(8), whc->base + WUSBASYNCLISTADDR); - - whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, WUSBCMD_ASYNC_EN); - whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS, - WUSBSTS_ASYNC_SCHED, WUSBSTS_ASYNC_SCHED, - 1000, "start ASL"); -} - -void asl_stop(struct whc *whc) -{ - whc_write_wusbcmd(whc, WUSBCMD_ASYNC_EN, 0); - whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS, - WUSBSTS_ASYNC_SCHED, 0, - 1000, "stop ASL"); -} - -/** - * asl_update - request an ASL update and wait for the hardware to be synced - * @whc: the WHCI HC - * @wusbcmd: WUSBCMD value to start the update. - * - * If the WUSB HC is inactive (i.e., the ASL is stopped) then the - * update must be skipped as the hardware may not respond to update - * requests. - */ -void asl_update(struct whc *whc, uint32_t wusbcmd) -{ - struct wusbhc *wusbhc = &whc->wusbhc; - long t; - - mutex_lock(&wusbhc->mutex); - if (wusbhc->active) { - whc_write_wusbcmd(whc, wusbcmd, wusbcmd); - t = wait_event_timeout( - whc->async_list_wq, - (le_readl(whc->base + WUSBCMD) & WUSBCMD_ASYNC_UPDATED) == 0, - msecs_to_jiffies(1000)); - if (t == 0) - whc_hw_error(whc, "ASL update timeout"); - } - mutex_unlock(&wusbhc->mutex); -} - -/** - * scan_async_work - scan the ASL for qsets to process. - * - * Process each qset in the ASL in turn and then signal the WHC that - * the ASL has been updated. - * - * Then start, stop or update the asynchronous schedule as required. - */ -void scan_async_work(struct work_struct *work) -{ - struct whc *whc = container_of(work, struct whc, async_work); - struct whc_qset *qset, *t; - enum whc_update update = 0; - - spin_lock_irq(&whc->lock); - - /* - * Transerve the software list backwards so new qsets can be - * safely inserted into the ASL without making it non-circular. - */ - list_for_each_entry_safe_reverse(qset, t, &whc->async_list, list_node) { - if (!qset->in_hw_list) { - asl_qset_insert(whc, qset); - update |= WHC_UPDATE_ADDED; - } - - update |= process_qset(whc, qset); - } - - spin_unlock_irq(&whc->lock); - - if (update) { - uint32_t wusbcmd = WUSBCMD_ASYNC_UPDATED | WUSBCMD_ASYNC_SYNCED_DB; - if (update & WHC_UPDATE_REMOVED) - wusbcmd |= WUSBCMD_ASYNC_QSET_RM; - asl_update(whc, wusbcmd); - } - - /* - * Now that the ASL is updated, complete the removal of any - * removed qsets. - * - * If the qset was to be reset, do so and reinsert it into the - * ASL if it has pending transfers. - */ - spin_lock_irq(&whc->lock); - - list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) { - qset_remove_complete(whc, qset); - if (qset->reset) { - qset_reset(whc, qset); - if (!list_empty(&qset->stds)) { - asl_qset_insert_begin(whc, qset); - queue_work(whc->workqueue, &whc->async_work); - } - } - } - - spin_unlock_irq(&whc->lock); -} - -/** - * asl_urb_enqueue - queue an URB onto the asynchronous list (ASL). - * @whc: the WHCI host controller - * @urb: the URB to enqueue - * @mem_flags: flags for any memory allocations - * - * The qset for the endpoint is obtained and the urb queued on to it. - * - * Work is scheduled to update the hardware's view of the ASL. - */ -int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags) -{ - struct whc_qset *qset; - int err; - unsigned long flags; - - spin_lock_irqsave(&whc->lock, flags); - - err = usb_hcd_link_urb_to_ep(&whc->wusbhc.usb_hcd, urb); - if (err < 0) { - spin_unlock_irqrestore(&whc->lock, flags); - return err; - } - - qset = get_qset(whc, urb, GFP_ATOMIC); - if (qset == NULL) - err = -ENOMEM; - else - err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); - if (!err) { - if (!qset->in_sw_list && !qset->remove) - asl_qset_insert_begin(whc, qset); - } else - usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); - - spin_unlock_irqrestore(&whc->lock, flags); - - if (!err) - queue_work(whc->workqueue, &whc->async_work); - - return err; -} - -/** - * asl_urb_dequeue - remove an URB (qset) from the async list. - * @whc: the WHCI host controller - * @urb: the URB to dequeue - * @status: the current status of the URB - * - * URBs that do yet have qTDs can simply be removed from the software - * queue, otherwise the qset must be removed from the ASL so the qTDs - * can be removed. - */ -int asl_urb_dequeue(struct whc *whc, struct urb *urb, int status) -{ - struct whc_urb *wurb = urb->hcpriv; - struct whc_qset *qset = wurb->qset; - struct whc_std *std, *t; - bool has_qtd = false; - int ret; - unsigned long flags; - - spin_lock_irqsave(&whc->lock, flags); - - ret = usb_hcd_check_unlink_urb(&whc->wusbhc.usb_hcd, urb, status); - if (ret < 0) - goto out; - - list_for_each_entry_safe(std, t, &qset->stds, list_node) { - if (std->urb == urb) { - if (std->qtd) - has_qtd = true; - qset_free_std(whc, std); - } else - std->qtd = NULL; /* so this std is re-added when the qset is */ - } - - if (has_qtd) { - asl_qset_remove(whc, qset); - wurb->status = status; - wurb->is_async = true; - queue_work(whc->workqueue, &wurb->dequeue_work); - } else - qset_remove_urb(whc, qset, urb, status); -out: - spin_unlock_irqrestore(&whc->lock, flags); - - return ret; -} - -/** - * asl_qset_delete - delete a qset from the ASL - */ -void asl_qset_delete(struct whc *whc, struct whc_qset *qset) -{ - qset->remove = 1; - queue_work(whc->workqueue, &whc->async_work); - qset_delete(whc, qset); -} - -/** - * asl_init - initialize the asynchronous schedule list - * - * A dummy qset with no qTDs is added to the ASL to simplify removing - * qsets (no need to stop the ASL when the last qset is removed). - */ -int asl_init(struct whc *whc) -{ - struct whc_qset *qset; - - qset = qset_alloc(whc, GFP_KERNEL); - if (qset == NULL) - return -ENOMEM; - - asl_qset_insert_begin(whc, qset); - asl_qset_insert(whc, qset); - - return 0; -} - -/** - * asl_clean_up - free ASL resources - * - * The ASL is stopped and empty except for the dummy qset. - */ -void asl_clean_up(struct whc *whc) -{ - struct whc_qset *qset; - - if (!list_empty(&whc->async_list)) { - qset = list_first_entry(&whc->async_list, struct whc_qset, list_node); - list_del(&qset->list_node); - qset_free(whc, qset); - } -} diff --git a/drivers/staging/wusbcore/host/whci/debug.c b/drivers/staging/wusbcore/host/whci/debug.c deleted file mode 100644 index 443da6719147..000000000000 --- a/drivers/staging/wusbcore/host/whci/debug.c +++ /dev/null @@ -1,153 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) debug. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include <linux/slab.h> -#include <linux/kernel.h> -#include <linux/debugfs.h> -#include <linux/seq_file.h> -#include <linux/export.h> - -#include "../../wusbhc.h" - -#include "whcd.h" - -struct whc_dbg { - struct dentry *di_f; - struct dentry *asl_f; - struct dentry *pzl_f; -}; - -static void qset_print(struct seq_file *s, struct whc_qset *qset) -{ - static const char *qh_type[] = { - "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", }; - struct whc_std *std; - struct urb *urb = NULL; - int i; - - seq_printf(s, "qset %08x", (u32)qset->qset_dma); - if (&qset->list_node == qset->whc->async_list.prev) { - seq_printf(s, " (dummy)\n"); - } else { - seq_printf(s, " ep%d%s-%s maxpkt: %d\n", - qset->qh.info1 & 0x0f, - (qset->qh.info1 >> 4) & 0x1 ? "in" : "out", - qh_type[(qset->qh.info1 >> 5) & 0x7], - (qset->qh.info1 >> 16) & 0xffff); - } - seq_printf(s, " -> %08x\n", (u32)qset->qh.link); - seq_printf(s, " info: %08x %08x %08x\n", - qset->qh.info1, qset->qh.info2, qset->qh.info3); - seq_printf(s, " sts: %04x errs: %d curwin: %08x\n", - qset->qh.status, qset->qh.err_count, qset->qh.cur_window); - seq_printf(s, " TD: sts: %08x opts: %08x\n", - qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options); - - for (i = 0; i < WHCI_QSET_TD_MAX; i++) { - seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n", - i == qset->td_start ? 'S' : ' ', - i == qset->td_end ? 'E' : ' ', - i, qset->qtd[i].status, qset->qtd[i].options, - (u32)qset->qtd[i].page_list_ptr); - } - seq_printf(s, " ntds: %d\n", qset->ntds); - list_for_each_entry(std, &qset->stds, list_node) { - if (urb != std->urb) { - urb = std->urb; - seq_printf(s, " urb %p transferred: %d bytes\n", urb, - urb->actual_length); - } - if (std->qtd) - seq_printf(s, " sTD[%td]: %zu bytes @ %08x\n", - std->qtd - &qset->qtd[0], - std->len, std->num_pointers ? - (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr); - else - seq_printf(s, " sTD[-]: %zd bytes @ %08x\n", - std->len, std->num_pointers ? - (u32)(std->pl_virt[0].buf_ptr) : (u32)std->dma_addr); - } -} - -static int di_show(struct seq_file *s, void *p) -{ - struct whc *whc = s->private; - int d; - - for (d = 0; d < whc->n_devices; d++) { - struct di_buf_entry *di = &whc->di_buf[d]; - - seq_printf(s, "DI[%d]\n", d); - seq_printf(s, " availability: %*pb\n", - UWB_NUM_MAS, (unsigned long *)di->availability_info); - seq_printf(s, " %c%c key idx: %d dev addr: %d\n", - (di->addr_sec_info & WHC_DI_SECURE) ? 'S' : ' ', - (di->addr_sec_info & WHC_DI_DISABLE) ? 'D' : ' ', - (di->addr_sec_info & WHC_DI_KEY_IDX_MASK) >> 8, - (di->addr_sec_info & WHC_DI_DEV_ADDR_MASK)); - } - return 0; -} -DEFINE_SHOW_ATTRIBUTE(di); - -static int asl_show(struct seq_file *s, void *p) -{ - struct whc *whc = s->private; - struct whc_qset *qset; - - list_for_each_entry(qset, &whc->async_list, list_node) { - qset_print(s, qset); - } - - return 0; -} -DEFINE_SHOW_ATTRIBUTE(asl); - -static int pzl_show(struct seq_file *s, void *p) -{ - struct whc *whc = s->private; - struct whc_qset *qset; - int period; - - for (period = 0; period < 5; period++) { - seq_printf(s, "Period %d\n", period); - list_for_each_entry(qset, &whc->periodic_list[period], list_node) { - qset_print(s, qset); - } - } - return 0; -} -DEFINE_SHOW_ATTRIBUTE(pzl); - -void whc_dbg_init(struct whc *whc) -{ - if (whc->wusbhc.pal.debugfs_dir == NULL) - return; - - whc->dbg = kzalloc(sizeof(struct whc_dbg), GFP_KERNEL); - if (whc->dbg == NULL) - return; - - whc->dbg->di_f = debugfs_create_file("di", 0444, - whc->wusbhc.pal.debugfs_dir, whc, - &di_fops); - whc->dbg->asl_f = debugfs_create_file("asl", 0444, - whc->wusbhc.pal.debugfs_dir, whc, - &asl_fops); - whc->dbg->pzl_f = debugfs_create_file("pzl", 0444, - whc->wusbhc.pal.debugfs_dir, whc, - &pzl_fops); -} - -void whc_dbg_clean_up(struct whc *whc) -{ - if (whc->dbg) { - debugfs_remove(whc->dbg->pzl_f); - debugfs_remove(whc->dbg->asl_f); - debugfs_remove(whc->dbg->di_f); - kfree(whc->dbg); - } -} diff --git a/drivers/staging/wusbcore/host/whci/hcd.c b/drivers/staging/wusbcore/host/whci/hcd.c deleted file mode 100644 index bee1ff2d35be..000000000000 --- a/drivers/staging/wusbcore/host/whci/hcd.c +++ /dev/null @@ -1,356 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) driver. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/module.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -/* - * One time initialization. - * - * Nothing to do here. - */ -static int whc_reset(struct usb_hcd *usb_hcd) -{ - return 0; -} - -/* - * Start the wireless host controller. - * - * Start device notification. - * - * Put hc into run state, set DNTS parameters. - */ -static int whc_start(struct usb_hcd *usb_hcd) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - u8 bcid; - int ret; - - mutex_lock(&wusbhc->mutex); - - le_writel(WUSBINTR_GEN_CMD_DONE - | WUSBINTR_HOST_ERR - | WUSBINTR_ASYNC_SCHED_SYNCED - | WUSBINTR_DNTS_INT - | WUSBINTR_ERR_INT - | WUSBINTR_INT, - whc->base + WUSBINTR); - - /* set cluster ID */ - bcid = wusb_cluster_id_get(); - ret = whc_set_cluster_id(whc, bcid); - if (ret < 0) - goto out; - wusbhc->cluster_id = bcid; - - /* start HC */ - whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN); - - usb_hcd->uses_new_polling = 1; - set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags); - usb_hcd->state = HC_STATE_RUNNING; - -out: - mutex_unlock(&wusbhc->mutex); - return ret; -} - - -/* - * Stop the wireless host controller. - * - * Stop device notification. - * - * Wait for pending transfer to stop? Put hc into stop state? - */ -static void whc_stop(struct usb_hcd *usb_hcd) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - - mutex_lock(&wusbhc->mutex); - - /* stop HC */ - le_writel(0, whc->base + WUSBINTR); - whc_write_wusbcmd(whc, WUSBCMD_RUN, 0); - whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS, - WUSBSTS_HCHALTED, WUSBSTS_HCHALTED, - 100, "HC to halt"); - - wusb_cluster_id_put(wusbhc->cluster_id); - - mutex_unlock(&wusbhc->mutex); -} - -static int whc_get_frame_number(struct usb_hcd *usb_hcd) -{ - /* Frame numbers are not applicable to WUSB. */ - return -ENOSYS; -} - - -/* - * Queue an URB to the ASL or PZL - */ -static int whc_urb_enqueue(struct usb_hcd *usb_hcd, struct urb *urb, - gfp_t mem_flags) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - int ret; - - switch (usb_pipetype(urb->pipe)) { - case PIPE_INTERRUPT: - ret = pzl_urb_enqueue(whc, urb, mem_flags); - break; - case PIPE_ISOCHRONOUS: - dev_err(&whc->umc->dev, "isochronous transfers unsupported\n"); - ret = -ENOTSUPP; - break; - case PIPE_CONTROL: - case PIPE_BULK: - default: - ret = asl_urb_enqueue(whc, urb, mem_flags); - break; - } - - return ret; -} - -/* - * Remove a queued URB from the ASL or PZL. - */ -static int whc_urb_dequeue(struct usb_hcd *usb_hcd, struct urb *urb, int status) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - int ret; - - switch (usb_pipetype(urb->pipe)) { - case PIPE_INTERRUPT: - ret = pzl_urb_dequeue(whc, urb, status); - break; - case PIPE_ISOCHRONOUS: - ret = -ENOTSUPP; - break; - case PIPE_CONTROL: - case PIPE_BULK: - default: - ret = asl_urb_dequeue(whc, urb, status); - break; - } - - return ret; -} - -/* - * Wait for all URBs to the endpoint to be completed, then delete the - * qset. - */ -static void whc_endpoint_disable(struct usb_hcd *usb_hcd, - struct usb_host_endpoint *ep) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - struct whc_qset *qset; - - qset = ep->hcpriv; - if (qset) { - ep->hcpriv = NULL; - if (usb_endpoint_xfer_bulk(&ep->desc) - || usb_endpoint_xfer_control(&ep->desc)) - asl_qset_delete(whc, qset); - else - pzl_qset_delete(whc, qset); - } -} - -static void whc_endpoint_reset(struct usb_hcd *usb_hcd, - struct usb_host_endpoint *ep) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - struct whc_qset *qset; - unsigned long flags; - - spin_lock_irqsave(&whc->lock, flags); - - qset = ep->hcpriv; - if (qset) { - qset->remove = 1; - qset->reset = 1; - - if (usb_endpoint_xfer_bulk(&ep->desc) - || usb_endpoint_xfer_control(&ep->desc)) - queue_work(whc->workqueue, &whc->async_work); - else - queue_work(whc->workqueue, &whc->periodic_work); - } - - spin_unlock_irqrestore(&whc->lock, flags); -} - - -static const struct hc_driver whc_hc_driver = { - .description = "whci-hcd", - .product_desc = "Wireless host controller", - .hcd_priv_size = sizeof(struct whc) - sizeof(struct usb_hcd), - .irq = whc_int_handler, - .flags = HCD_USB2, - - .reset = whc_reset, - .start = whc_start, - .stop = whc_stop, - .get_frame_number = whc_get_frame_number, - .urb_enqueue = whc_urb_enqueue, - .urb_dequeue = whc_urb_dequeue, - .endpoint_disable = whc_endpoint_disable, - .endpoint_reset = whc_endpoint_reset, - - .hub_status_data = wusbhc_rh_status_data, - .hub_control = wusbhc_rh_control, - .start_port_reset = wusbhc_rh_start_port_reset, -}; - -static int whc_probe(struct umc_dev *umc) -{ - int ret; - struct usb_hcd *usb_hcd; - struct wusbhc *wusbhc; - struct whc *whc; - struct device *dev = &umc->dev; - - usb_hcd = usb_create_hcd(&whc_hc_driver, dev, "whci"); - if (usb_hcd == NULL) { - dev_err(dev, "unable to create hcd\n"); - return -ENOMEM; - } - - usb_hcd->wireless = 1; - usb_hcd->self.sg_tablesize = 2048; /* somewhat arbitrary */ - - wusbhc = usb_hcd_to_wusbhc(usb_hcd); - whc = wusbhc_to_whc(wusbhc); - whc->umc = umc; - - ret = whc_init(whc); - if (ret) - goto error_whc_init; - - wusbhc->dev = dev; - wusbhc->uwb_rc = uwb_rc_get_by_grandpa(umc->dev.parent); - if (!wusbhc->uwb_rc) { - ret = -ENODEV; - dev_err(dev, "cannot get radio controller\n"); - goto error_uwb_rc; - } - - if (whc->n_devices > USB_MAXCHILDREN) { - dev_warn(dev, "USB_MAXCHILDREN too low for WUSB adapter (%u ports)\n", - whc->n_devices); - wusbhc->ports_max = USB_MAXCHILDREN; - } else - wusbhc->ports_max = whc->n_devices; - wusbhc->mmcies_max = whc->n_mmc_ies; - wusbhc->start = whc_wusbhc_start; - wusbhc->stop = whc_wusbhc_stop; - wusbhc->mmcie_add = whc_mmcie_add; - wusbhc->mmcie_rm = whc_mmcie_rm; - wusbhc->dev_info_set = whc_dev_info_set; - wusbhc->bwa_set = whc_bwa_set; - wusbhc->set_num_dnts = whc_set_num_dnts; - wusbhc->set_ptk = whc_set_ptk; - wusbhc->set_gtk = whc_set_gtk; - - ret = wusbhc_create(wusbhc); - if (ret) - goto error_wusbhc_create; - - ret = usb_add_hcd(usb_hcd, whc->umc->irq, IRQF_SHARED); - if (ret) { - dev_err(dev, "cannot add HCD: %d\n", ret); - goto error_usb_add_hcd; - } - device_wakeup_enable(usb_hcd->self.controller); - - ret = wusbhc_b_create(wusbhc); - if (ret) { - dev_err(dev, "WUSBHC phase B setup failed: %d\n", ret); - goto error_wusbhc_b_create; - } - - whc_dbg_init(whc); - - return 0; - -error_wusbhc_b_create: - usb_remove_hcd(usb_hcd); -error_usb_add_hcd: - wusbhc_destroy(wusbhc); -error_wusbhc_create: - uwb_rc_put(wusbhc->uwb_rc); -error_uwb_rc: - whc_clean_up(whc); -error_whc_init: - usb_put_hcd(usb_hcd); - return ret; -} - - -static void whc_remove(struct umc_dev *umc) -{ - struct usb_hcd *usb_hcd = dev_get_drvdata(&umc->dev); - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - - if (usb_hcd) { - whc_dbg_clean_up(whc); - wusbhc_b_destroy(wusbhc); - usb_remove_hcd(usb_hcd); - wusbhc_destroy(wusbhc); - uwb_rc_put(wusbhc->uwb_rc); - whc_clean_up(whc); - usb_put_hcd(usb_hcd); - } -} - -static struct umc_driver whci_hc_driver = { - .name = "whci-hcd", - .cap_id = UMC_CAP_ID_WHCI_WUSB_HC, - .probe = whc_probe, - .remove = whc_remove, -}; - -static int __init whci_hc_driver_init(void) -{ - return umc_driver_register(&whci_hc_driver); -} -module_init(whci_hc_driver_init); - -static void __exit whci_hc_driver_exit(void) -{ - umc_driver_unregister(&whci_hc_driver); -} -module_exit(whci_hc_driver_exit); - -/* PCI device ID's that we handle (so it gets loaded) */ -static struct pci_device_id __used whci_hcd_id_table[] = { - { PCI_DEVICE_CLASS(PCI_CLASS_WIRELESS_WHCI, ~0) }, - { /* empty last entry */ } -}; -MODULE_DEVICE_TABLE(pci, whci_hcd_id_table); - -MODULE_DESCRIPTION("WHCI Wireless USB host controller driver"); -MODULE_AUTHOR("Cambridge Silicon Radio Ltd."); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wusbcore/host/whci/hw.c b/drivers/staging/wusbcore/host/whci/hw.c deleted file mode 100644 index e4e8914abf42..000000000000 --- a/drivers/staging/wusbcore/host/whci/hw.c +++ /dev/null @@ -1,93 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) hardware access helpers. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/dma-mapping.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -void whc_write_wusbcmd(struct whc *whc, u32 mask, u32 val) -{ - unsigned long flags; - u32 cmd; - - spin_lock_irqsave(&whc->lock, flags); - - cmd = le_readl(whc->base + WUSBCMD); - cmd = (cmd & ~mask) | val; - le_writel(cmd, whc->base + WUSBCMD); - - spin_unlock_irqrestore(&whc->lock, flags); -} - -/** - * whc_do_gencmd - start a generic command via the WUSBGENCMDSTS register - * @whc: the WHCI HC - * @cmd: command to start. - * @params: parameters for the command (the WUSBGENCMDPARAMS register value). - * @addr: pointer to any data for the command (may be NULL). - * @len: length of the data (if any). - */ -int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len) -{ - unsigned long flags; - dma_addr_t dma_addr; - int t; - int ret = 0; - - mutex_lock(&whc->mutex); - - /* Wait for previous command to complete. */ - t = wait_event_timeout(whc->cmd_wq, - (le_readl(whc->base + WUSBGENCMDSTS) & WUSBGENCMDSTS_ACTIVE) == 0, - WHC_GENCMD_TIMEOUT_MS); - if (t == 0) { - dev_err(&whc->umc->dev, "generic command timeout (%04x/%04x)\n", - le_readl(whc->base + WUSBGENCMDSTS), - le_readl(whc->base + WUSBGENCMDPARAMS)); - ret = -ETIMEDOUT; - goto out; - } - - if (addr) { - memcpy(whc->gen_cmd_buf, addr, len); - dma_addr = whc->gen_cmd_buf_dma; - } else - dma_addr = 0; - - /* Poke registers to start cmd. */ - spin_lock_irqsave(&whc->lock, flags); - - le_writel(params, whc->base + WUSBGENCMDPARAMS); - le_writeq(dma_addr, whc->base + WUSBGENADDR); - - le_writel(WUSBGENCMDSTS_ACTIVE | WUSBGENCMDSTS_IOC | cmd, - whc->base + WUSBGENCMDSTS); - - spin_unlock_irqrestore(&whc->lock, flags); -out: - mutex_unlock(&whc->mutex); - - return ret; -} - -/** - * whc_hw_error - recover from a hardware error - * @whc: the WHCI HC that broke. - * @reason: a description of the failure. - * - * Recover from broken hardware with a full reset. - */ -void whc_hw_error(struct whc *whc, const char *reason) -{ - struct wusbhc *wusbhc = &whc->wusbhc; - - dev_err(&whc->umc->dev, "hardware error: %s\n", reason); - wusbhc_reset_all(wusbhc); -} diff --git a/drivers/staging/wusbcore/host/whci/init.c b/drivers/staging/wusbcore/host/whci/init.c deleted file mode 100644 index 55fd458a8f30..000000000000 --- a/drivers/staging/wusbcore/host/whci/init.c +++ /dev/null @@ -1,177 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) initialization. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/gfp.h> -#include <linux/dma-mapping.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -/* - * Reset the host controller. - */ -static void whc_hw_reset(struct whc *whc) -{ - le_writel(WUSBCMD_WHCRESET, whc->base + WUSBCMD); - whci_wait_for(&whc->umc->dev, whc->base + WUSBCMD, WUSBCMD_WHCRESET, 0, - 100, "reset"); -} - -static void whc_hw_init_di_buf(struct whc *whc) -{ - int d; - - /* Disable all entries in the Device Information buffer. */ - for (d = 0; d < whc->n_devices; d++) - whc->di_buf[d].addr_sec_info = WHC_DI_DISABLE; - - le_writeq(whc->di_buf_dma, whc->base + WUSBDEVICEINFOADDR); -} - -static void whc_hw_init_dn_buf(struct whc *whc) -{ - /* Clear the Device Notification buffer to ensure the V (valid) - * bits are clear. */ - memset(whc->dn_buf, 0, 4096); - - le_writeq(whc->dn_buf_dma, whc->base + WUSBDNTSBUFADDR); -} - -int whc_init(struct whc *whc) -{ - u32 whcsparams; - int ret, i; - resource_size_t start, len; - - spin_lock_init(&whc->lock); - mutex_init(&whc->mutex); - init_waitqueue_head(&whc->cmd_wq); - init_waitqueue_head(&whc->async_list_wq); - init_waitqueue_head(&whc->periodic_list_wq); - whc->workqueue = alloc_ordered_workqueue(dev_name(&whc->umc->dev), 0); - if (whc->workqueue == NULL) { - ret = -ENOMEM; - goto error; - } - INIT_WORK(&whc->dn_work, whc_dn_work); - - INIT_WORK(&whc->async_work, scan_async_work); - INIT_LIST_HEAD(&whc->async_list); - INIT_LIST_HEAD(&whc->async_removed_list); - - INIT_WORK(&whc->periodic_work, scan_periodic_work); - for (i = 0; i < 5; i++) - INIT_LIST_HEAD(&whc->periodic_list[i]); - INIT_LIST_HEAD(&whc->periodic_removed_list); - - /* Map HC registers. */ - start = whc->umc->resource.start; - len = whc->umc->resource.end - start + 1; - if (!request_mem_region(start, len, "whci-hc")) { - dev_err(&whc->umc->dev, "can't request HC region\n"); - ret = -EBUSY; - goto error; - } - whc->base_phys = start; - whc->base = ioremap(start, len); - if (!whc->base) { - dev_err(&whc->umc->dev, "ioremap\n"); - ret = -ENOMEM; - goto error; - } - - whc_hw_reset(whc); - - /* Read maximum number of devices, keys and MMC IEs. */ - whcsparams = le_readl(whc->base + WHCSPARAMS); - whc->n_devices = WHCSPARAMS_TO_N_DEVICES(whcsparams); - whc->n_keys = WHCSPARAMS_TO_N_KEYS(whcsparams); - whc->n_mmc_ies = WHCSPARAMS_TO_N_MMC_IES(whcsparams); - - dev_dbg(&whc->umc->dev, "N_DEVICES = %d, N_KEYS = %d, N_MMC_IES = %d\n", - whc->n_devices, whc->n_keys, whc->n_mmc_ies); - - whc->qset_pool = dma_pool_create("qset", &whc->umc->dev, - sizeof(struct whc_qset), 64, 0); - if (whc->qset_pool == NULL) { - ret = -ENOMEM; - goto error; - } - - ret = asl_init(whc); - if (ret < 0) - goto error; - ret = pzl_init(whc); - if (ret < 0) - goto error; - - /* Allocate and initialize a buffer for generic commands, the - Device Information buffer, and the Device Notification - buffer. */ - - whc->gen_cmd_buf = dma_alloc_coherent(&whc->umc->dev, WHC_GEN_CMD_DATA_LEN, - &whc->gen_cmd_buf_dma, GFP_KERNEL); - if (whc->gen_cmd_buf == NULL) { - ret = -ENOMEM; - goto error; - } - - whc->dn_buf = dma_alloc_coherent(&whc->umc->dev, - sizeof(struct dn_buf_entry) * WHC_N_DN_ENTRIES, - &whc->dn_buf_dma, GFP_KERNEL); - if (!whc->dn_buf) { - ret = -ENOMEM; - goto error; - } - whc_hw_init_dn_buf(whc); - - whc->di_buf = dma_alloc_coherent(&whc->umc->dev, - sizeof(struct di_buf_entry) * whc->n_devices, - &whc->di_buf_dma, GFP_KERNEL); - if (!whc->di_buf) { - ret = -ENOMEM; - goto error; - } - whc_hw_init_di_buf(whc); - - return 0; - -error: - whc_clean_up(whc); - return ret; -} - -void whc_clean_up(struct whc *whc) -{ - resource_size_t len; - - if (whc->di_buf) - dma_free_coherent(&whc->umc->dev, sizeof(struct di_buf_entry) * whc->n_devices, - whc->di_buf, whc->di_buf_dma); - if (whc->dn_buf) - dma_free_coherent(&whc->umc->dev, sizeof(struct dn_buf_entry) * WHC_N_DN_ENTRIES, - whc->dn_buf, whc->dn_buf_dma); - if (whc->gen_cmd_buf) - dma_free_coherent(&whc->umc->dev, WHC_GEN_CMD_DATA_LEN, - whc->gen_cmd_buf, whc->gen_cmd_buf_dma); - - pzl_clean_up(whc); - asl_clean_up(whc); - - dma_pool_destroy(whc->qset_pool); - - len = resource_size(&whc->umc->resource); - if (whc->base) - iounmap(whc->base); - if (whc->base_phys) - release_mem_region(whc->base_phys, len); - - if (whc->workqueue) - destroy_workqueue(whc->workqueue); -} diff --git a/drivers/staging/wusbcore/host/whci/int.c b/drivers/staging/wusbcore/host/whci/int.c deleted file mode 100644 index bdbe35e9366f..000000000000 --- a/drivers/staging/wusbcore/host/whci/int.c +++ /dev/null @@ -1,82 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) interrupt handling. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -static void transfer_done(struct whc *whc) -{ - queue_work(whc->workqueue, &whc->async_work); - queue_work(whc->workqueue, &whc->periodic_work); -} - -irqreturn_t whc_int_handler(struct usb_hcd *hcd) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(hcd); - struct whc *whc = wusbhc_to_whc(wusbhc); - u32 sts; - - sts = le_readl(whc->base + WUSBSTS); - if (!(sts & WUSBSTS_INT_MASK)) - return IRQ_NONE; - le_writel(sts & WUSBSTS_INT_MASK, whc->base + WUSBSTS); - - if (sts & WUSBSTS_GEN_CMD_DONE) - wake_up(&whc->cmd_wq); - - if (sts & WUSBSTS_HOST_ERR) - dev_err(&whc->umc->dev, "FIXME: host system error\n"); - - if (sts & WUSBSTS_ASYNC_SCHED_SYNCED) - wake_up(&whc->async_list_wq); - - if (sts & WUSBSTS_PERIODIC_SCHED_SYNCED) - wake_up(&whc->periodic_list_wq); - - if (sts & WUSBSTS_DNTS_INT) - queue_work(whc->workqueue, &whc->dn_work); - - /* - * A transfer completed (see [WHCI] section 4.7.1.2 for when - * this occurs). - */ - if (sts & (WUSBSTS_INT | WUSBSTS_ERR_INT)) - transfer_done(whc); - - return IRQ_HANDLED; -} - -static int process_dn_buf(struct whc *whc) -{ - struct wusbhc *wusbhc = &whc->wusbhc; - struct dn_buf_entry *dn; - int processed = 0; - - for (dn = whc->dn_buf; dn < whc->dn_buf + WHC_N_DN_ENTRIES; dn++) { - if (dn->status & WHC_DN_STATUS_VALID) { - wusbhc_handle_dn(wusbhc, dn->src_addr, - (struct wusb_dn_hdr *)dn->dn_data, - dn->msg_size); - dn->status &= ~WHC_DN_STATUS_VALID; - processed++; - } - } - return processed; -} - -void whc_dn_work(struct work_struct *work) -{ - struct whc *whc = container_of(work, struct whc, dn_work); - int processed; - - do { - processed = process_dn_buf(whc); - } while (processed); -} diff --git a/drivers/staging/wusbcore/host/whci/pzl.c b/drivers/staging/wusbcore/host/whci/pzl.c deleted file mode 100644 index 6dfc075f5798..000000000000 --- a/drivers/staging/wusbcore/host/whci/pzl.c +++ /dev/null @@ -1,404 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) periodic schedule management. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/gfp.h> -#include <linux/dma-mapping.h> -#include <linux/usb.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -static void update_pzl_pointers(struct whc *whc, int period, u64 addr) -{ - switch (period) { - case 0: - whc_qset_set_link_ptr(&whc->pz_list[0], addr); - whc_qset_set_link_ptr(&whc->pz_list[2], addr); - whc_qset_set_link_ptr(&whc->pz_list[4], addr); - whc_qset_set_link_ptr(&whc->pz_list[6], addr); - whc_qset_set_link_ptr(&whc->pz_list[8], addr); - whc_qset_set_link_ptr(&whc->pz_list[10], addr); - whc_qset_set_link_ptr(&whc->pz_list[12], addr); - whc_qset_set_link_ptr(&whc->pz_list[14], addr); - break; - case 1: - whc_qset_set_link_ptr(&whc->pz_list[1], addr); - whc_qset_set_link_ptr(&whc->pz_list[5], addr); - whc_qset_set_link_ptr(&whc->pz_list[9], addr); - whc_qset_set_link_ptr(&whc->pz_list[13], addr); - break; - case 2: - whc_qset_set_link_ptr(&whc->pz_list[3], addr); - whc_qset_set_link_ptr(&whc->pz_list[11], addr); - break; - case 3: - whc_qset_set_link_ptr(&whc->pz_list[7], addr); - break; - case 4: - whc_qset_set_link_ptr(&whc->pz_list[15], addr); - break; - } -} - -/* - * Return the 'period' to use for this qset. The minimum interval for - * the endpoint is used so whatever urbs are submitted the device is - * polled often enough. - */ -static int qset_get_period(struct whc *whc, struct whc_qset *qset) -{ - uint8_t bInterval = qset->ep->desc.bInterval; - - if (bInterval < 6) - bInterval = 6; - if (bInterval > 10) - bInterval = 10; - return bInterval - 6; -} - -static void qset_insert_in_sw_list(struct whc *whc, struct whc_qset *qset) -{ - int period; - - period = qset_get_period(whc, qset); - - qset_clear(whc, qset); - list_move(&qset->list_node, &whc->periodic_list[period]); - qset->in_sw_list = true; -} - -static void pzl_qset_remove(struct whc *whc, struct whc_qset *qset) -{ - list_move(&qset->list_node, &whc->periodic_removed_list); - qset->in_hw_list = false; - qset->in_sw_list = false; -} - -/** - * pzl_process_qset - process any recently inactivated or halted qTDs - * in a qset. - * - * After inactive qTDs are removed, new qTDs can be added if the - * urb queue still contains URBs. - * - * Returns the schedule updates required. - */ -static enum whc_update pzl_process_qset(struct whc *whc, struct whc_qset *qset) -{ - enum whc_update update = 0; - uint32_t status = 0; - - while (qset->ntds) { - struct whc_qtd *td; - - td = &qset->qtd[qset->td_start]; - status = le32_to_cpu(td->status); - - /* - * Nothing to do with a still active qTD. - */ - if (status & QTD_STS_ACTIVE) - break; - - if (status & QTD_STS_HALTED) { - /* Ug, an error. */ - process_halted_qtd(whc, qset, td); - /* A halted qTD always triggers an update - because the qset was either removed or - reactivated. */ - update |= WHC_UPDATE_UPDATED; - goto done; - } - - /* Mmm, a completed qTD. */ - process_inactive_qtd(whc, qset, td); - } - - if (!qset->remove) - update |= qset_add_qtds(whc, qset); - -done: - /* - * If there are no qTDs in this qset, remove it from the PZL. - */ - if (qset->remove && qset->ntds == 0) { - pzl_qset_remove(whc, qset); - update |= WHC_UPDATE_REMOVED; - } - - return update; -} - -/** - * pzl_start - start the periodic schedule - * @whc: the WHCI host controller - * - * The PZL must be valid (e.g., all entries in the list should have - * the T bit set). - */ -void pzl_start(struct whc *whc) -{ - le_writeq(whc->pz_list_dma, whc->base + WUSBPERIODICLISTBASE); - - whc_write_wusbcmd(whc, WUSBCMD_PERIODIC_EN, WUSBCMD_PERIODIC_EN); - whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS, - WUSBSTS_PERIODIC_SCHED, WUSBSTS_PERIODIC_SCHED, - 1000, "start PZL"); -} - -/** - * pzl_stop - stop the periodic schedule - * @whc: the WHCI host controller - */ -void pzl_stop(struct whc *whc) -{ - whc_write_wusbcmd(whc, WUSBCMD_PERIODIC_EN, 0); - whci_wait_for(&whc->umc->dev, whc->base + WUSBSTS, - WUSBSTS_PERIODIC_SCHED, 0, - 1000, "stop PZL"); -} - -/** - * pzl_update - request a PZL update and wait for the hardware to be synced - * @whc: the WHCI HC - * @wusbcmd: WUSBCMD value to start the update. - * - * If the WUSB HC is inactive (i.e., the PZL is stopped) then the - * update must be skipped as the hardware may not respond to update - * requests. - */ -void pzl_update(struct whc *whc, uint32_t wusbcmd) -{ - struct wusbhc *wusbhc = &whc->wusbhc; - long t; - - mutex_lock(&wusbhc->mutex); - if (wusbhc->active) { - whc_write_wusbcmd(whc, wusbcmd, wusbcmd); - t = wait_event_timeout( - whc->periodic_list_wq, - (le_readl(whc->base + WUSBCMD) & WUSBCMD_PERIODIC_UPDATED) == 0, - msecs_to_jiffies(1000)); - if (t == 0) - whc_hw_error(whc, "PZL update timeout"); - } - mutex_unlock(&wusbhc->mutex); -} - -static void update_pzl_hw_view(struct whc *whc) -{ - struct whc_qset *qset, *t; - int period; - u64 tmp_qh = 0; - - for (period = 0; period < 5; period++) { - list_for_each_entry_safe(qset, t, &whc->periodic_list[period], list_node) { - whc_qset_set_link_ptr(&qset->qh.link, tmp_qh); - tmp_qh = qset->qset_dma; - qset->in_hw_list = true; - } - update_pzl_pointers(whc, period, tmp_qh); - } -} - -/** - * scan_periodic_work - scan the PZL for qsets to process. - * - * Process each qset in the PZL in turn and then signal the WHC that - * the PZL has been updated. - * - * Then start, stop or update the periodic schedule as required. - */ -void scan_periodic_work(struct work_struct *work) -{ - struct whc *whc = container_of(work, struct whc, periodic_work); - struct whc_qset *qset, *t; - enum whc_update update = 0; - int period; - - spin_lock_irq(&whc->lock); - - for (period = 4; period >= 0; period--) { - list_for_each_entry_safe(qset, t, &whc->periodic_list[period], list_node) { - if (!qset->in_hw_list) - update |= WHC_UPDATE_ADDED; - update |= pzl_process_qset(whc, qset); - } - } - - if (update & (WHC_UPDATE_ADDED | WHC_UPDATE_REMOVED)) - update_pzl_hw_view(whc); - - spin_unlock_irq(&whc->lock); - - if (update) { - uint32_t wusbcmd = WUSBCMD_PERIODIC_UPDATED | WUSBCMD_PERIODIC_SYNCED_DB; - if (update & WHC_UPDATE_REMOVED) - wusbcmd |= WUSBCMD_PERIODIC_QSET_RM; - pzl_update(whc, wusbcmd); - } - - /* - * Now that the PZL is updated, complete the removal of any - * removed qsets. - * - * If the qset was to be reset, do so and reinsert it into the - * PZL if it has pending transfers. - */ - spin_lock_irq(&whc->lock); - - list_for_each_entry_safe(qset, t, &whc->periodic_removed_list, list_node) { - qset_remove_complete(whc, qset); - if (qset->reset) { - qset_reset(whc, qset); - if (!list_empty(&qset->stds)) { - qset_insert_in_sw_list(whc, qset); - queue_work(whc->workqueue, &whc->periodic_work); - } - } - } - - spin_unlock_irq(&whc->lock); -} - -/** - * pzl_urb_enqueue - queue an URB onto the periodic list (PZL) - * @whc: the WHCI host controller - * @urb: the URB to enqueue - * @mem_flags: flags for any memory allocations - * - * The qset for the endpoint is obtained and the urb queued on to it. - * - * Work is scheduled to update the hardware's view of the PZL. - */ -int pzl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags) -{ - struct whc_qset *qset; - int err; - unsigned long flags; - - spin_lock_irqsave(&whc->lock, flags); - - err = usb_hcd_link_urb_to_ep(&whc->wusbhc.usb_hcd, urb); - if (err < 0) { - spin_unlock_irqrestore(&whc->lock, flags); - return err; - } - - qset = get_qset(whc, urb, GFP_ATOMIC); - if (qset == NULL) - err = -ENOMEM; - else - err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); - if (!err) { - if (!qset->in_sw_list && !qset->remove) - qset_insert_in_sw_list(whc, qset); - } else - usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); - - spin_unlock_irqrestore(&whc->lock, flags); - - if (!err) - queue_work(whc->workqueue, &whc->periodic_work); - - return err; -} - -/** - * pzl_urb_dequeue - remove an URB (qset) from the periodic list - * @whc: the WHCI host controller - * @urb: the URB to dequeue - * @status: the current status of the URB - * - * URBs that do yet have qTDs can simply be removed from the software - * queue, otherwise the qset must be removed so the qTDs can be safely - * removed. - */ -int pzl_urb_dequeue(struct whc *whc, struct urb *urb, int status) -{ - struct whc_urb *wurb = urb->hcpriv; - struct whc_qset *qset = wurb->qset; - struct whc_std *std, *t; - bool has_qtd = false; - int ret; - unsigned long flags; - - spin_lock_irqsave(&whc->lock, flags); - - ret = usb_hcd_check_unlink_urb(&whc->wusbhc.usb_hcd, urb, status); - if (ret < 0) - goto out; - - list_for_each_entry_safe(std, t, &qset->stds, list_node) { - if (std->urb == urb) { - if (std->qtd) - has_qtd = true; - qset_free_std(whc, std); - } else - std->qtd = NULL; /* so this std is re-added when the qset is */ - } - - if (has_qtd) { - pzl_qset_remove(whc, qset); - update_pzl_hw_view(whc); - wurb->status = status; - wurb->is_async = false; - queue_work(whc->workqueue, &wurb->dequeue_work); - } else - qset_remove_urb(whc, qset, urb, status); -out: - spin_unlock_irqrestore(&whc->lock, flags); - - return ret; -} - -/** - * pzl_qset_delete - delete a qset from the PZL - */ -void pzl_qset_delete(struct whc *whc, struct whc_qset *qset) -{ - qset->remove = 1; - queue_work(whc->workqueue, &whc->periodic_work); - qset_delete(whc, qset); -} - -/** - * pzl_init - initialize the periodic zone list - * @whc: the WHCI host controller - */ -int pzl_init(struct whc *whc) -{ - int i; - - whc->pz_list = dma_alloc_coherent(&whc->umc->dev, sizeof(u64) * 16, - &whc->pz_list_dma, GFP_KERNEL); - if (whc->pz_list == NULL) - return -ENOMEM; - - /* Set T bit on all elements in PZL. */ - for (i = 0; i < 16; i++) - whc->pz_list[i] = cpu_to_le64(QH_LINK_NTDS(8) | QH_LINK_T); - - le_writeq(whc->pz_list_dma, whc->base + WUSBPERIODICLISTBASE); - - return 0; -} - -/** - * pzl_clean_up - free PZL resources - * @whc: the WHCI host controller - * - * The PZL is stopped and empty. - */ -void pzl_clean_up(struct whc *whc) -{ - if (whc->pz_list) - dma_free_coherent(&whc->umc->dev, sizeof(u64) * 16, whc->pz_list, - whc->pz_list_dma); -} diff --git a/drivers/staging/wusbcore/host/whci/qset.c b/drivers/staging/wusbcore/host/whci/qset.c deleted file mode 100644 index 66459b77dc77..000000000000 --- a/drivers/staging/wusbcore/host/whci/qset.c +++ /dev/null @@ -1,831 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) qset management. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> -#include <linux/dma-mapping.h> -#include <linux/slab.h> -#include <linux/usb.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags) -{ - struct whc_qset *qset; - dma_addr_t dma; - - qset = dma_pool_zalloc(whc->qset_pool, mem_flags, &dma); - if (qset == NULL) - return NULL; - - qset->qset_dma = dma; - qset->whc = whc; - - INIT_LIST_HEAD(&qset->list_node); - INIT_LIST_HEAD(&qset->stds); - - return qset; -} - -/** - * qset_fill_qh - fill the static endpoint state in a qset's QHead - * @qset: the qset whose QH needs initializing with static endpoint - * state - * @urb: an urb for a transfer to this endpoint - */ -static void qset_fill_qh(struct whc *whc, struct whc_qset *qset, struct urb *urb) -{ - struct usb_device *usb_dev = urb->dev; - struct wusb_dev *wusb_dev = usb_dev->wusb_dev; - struct usb_wireless_ep_comp_descriptor *epcd; - bool is_out; - uint8_t phy_rate; - - is_out = usb_pipeout(urb->pipe); - - qset->max_packet = le16_to_cpu(urb->ep->desc.wMaxPacketSize); - - epcd = (struct usb_wireless_ep_comp_descriptor *)qset->ep->extra; - if (epcd) { - qset->max_seq = epcd->bMaxSequence; - qset->max_burst = epcd->bMaxBurst; - } else { - qset->max_seq = 2; - qset->max_burst = 1; - } - - /* - * Initial PHY rate is 53.3 Mbit/s for control endpoints or - * the maximum supported by the device for other endpoints - * (unless limited by the user). - */ - if (usb_pipecontrol(urb->pipe)) - phy_rate = UWB_PHY_RATE_53; - else { - uint16_t phy_rates; - - phy_rates = le16_to_cpu(wusb_dev->wusb_cap_descr->wPHYRates); - phy_rate = fls(phy_rates) - 1; - if (phy_rate > whc->wusbhc.phy_rate) - phy_rate = whc->wusbhc.phy_rate; - } - - qset->qh.info1 = cpu_to_le32( - QH_INFO1_EP(usb_pipeendpoint(urb->pipe)) - | (is_out ? QH_INFO1_DIR_OUT : QH_INFO1_DIR_IN) - | usb_pipe_to_qh_type(urb->pipe) - | QH_INFO1_DEV_INFO_IDX(wusb_port_no_to_idx(usb_dev->portnum)) - | QH_INFO1_MAX_PKT_LEN(qset->max_packet) - ); - qset->qh.info2 = cpu_to_le32( - QH_INFO2_BURST(qset->max_burst) - | QH_INFO2_DBP(0) - | QH_INFO2_MAX_COUNT(3) - | QH_INFO2_MAX_RETRY(3) - | QH_INFO2_MAX_SEQ(qset->max_seq - 1) - ); - /* FIXME: where can we obtain these Tx parameters from? Why - * doesn't the chip know what Tx power to use? It knows the Rx - * strength and can presumably guess the Tx power required - * from that? */ - qset->qh.info3 = cpu_to_le32( - QH_INFO3_TX_RATE(phy_rate) - | QH_INFO3_TX_PWR(0) /* 0 == max power */ - ); - - qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1); -} - -/** - * qset_clear - clear fields in a qset so it may be reinserted into a - * schedule. - * - * The sequence number and current window are not cleared (see - * qset_reset()). - */ -void qset_clear(struct whc *whc, struct whc_qset *qset) -{ - qset->td_start = qset->td_end = qset->ntds = 0; - - qset->qh.link = cpu_to_le64(QH_LINK_NTDS(8) | QH_LINK_T); - qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; - qset->qh.err_count = 0; - qset->qh.scratch[0] = 0; - qset->qh.scratch[1] = 0; - qset->qh.scratch[2] = 0; - - memset(&qset->qh.overlay, 0, sizeof(qset->qh.overlay)); - - init_completion(&qset->remove_complete); -} - -/** - * qset_reset - reset endpoint state in a qset. - * - * Clears the sequence number and current window. This qset must not - * be in the ASL or PZL. - */ -void qset_reset(struct whc *whc, struct whc_qset *qset) -{ - qset->reset = 0; - - qset->qh.status &= ~QH_STATUS_SEQ_MASK; - qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1); -} - -/** - * get_qset - get the qset for an async endpoint - * - * A new qset is created if one does not already exist. - */ -struct whc_qset *get_qset(struct whc *whc, struct urb *urb, - gfp_t mem_flags) -{ - struct whc_qset *qset; - - qset = urb->ep->hcpriv; - if (qset == NULL) { - qset = qset_alloc(whc, mem_flags); - if (qset == NULL) - return NULL; - - qset->ep = urb->ep; - urb->ep->hcpriv = qset; - qset_fill_qh(whc, qset, urb); - } - return qset; -} - -void qset_remove_complete(struct whc *whc, struct whc_qset *qset) -{ - qset->remove = 0; - list_del_init(&qset->list_node); - complete(&qset->remove_complete); -} - -/** - * qset_add_qtds - add qTDs for an URB to a qset - * - * Returns true if the list (ASL/PZL) must be updated because (for a - * WHCI 0.95 controller) an activated qTD was pointed to be iCur. - */ -enum whc_update qset_add_qtds(struct whc *whc, struct whc_qset *qset) -{ - struct whc_std *std; - enum whc_update update = 0; - - list_for_each_entry(std, &qset->stds, list_node) { - struct whc_qtd *qtd; - uint32_t status; - - if (qset->ntds >= WHCI_QSET_TD_MAX - || (qset->pause_after_urb && std->urb != qset->pause_after_urb)) - break; - - if (std->qtd) - continue; /* already has a qTD */ - - qtd = std->qtd = &qset->qtd[qset->td_end]; - - /* Fill in setup bytes for control transfers. */ - if (usb_pipecontrol(std->urb->pipe)) - memcpy(qtd->setup, std->urb->setup_packet, 8); - - status = QTD_STS_ACTIVE | QTD_STS_LEN(std->len); - - if (whc_std_last(std) && usb_pipeout(std->urb->pipe)) - status |= QTD_STS_LAST_PKT; - - /* - * For an IN transfer the iAlt field should be set so - * the h/w will automatically advance to the next - * transfer. However, if there are 8 or more TDs - * remaining in this transfer then iAlt cannot be set - * as it could point to somewhere in this transfer. - */ - if (std->ntds_remaining < WHCI_QSET_TD_MAX) { - int ialt; - ialt = (qset->td_end + std->ntds_remaining) % WHCI_QSET_TD_MAX; - status |= QTD_STS_IALT(ialt); - } else if (usb_pipein(std->urb->pipe)) - qset->pause_after_urb = std->urb; - - if (std->num_pointers) - qtd->options = cpu_to_le32(QTD_OPT_IOC); - else - qtd->options = cpu_to_le32(QTD_OPT_IOC | QTD_OPT_SMALL); - qtd->page_list_ptr = cpu_to_le64(std->dma_addr); - - qtd->status = cpu_to_le32(status); - - if (QH_STATUS_TO_ICUR(qset->qh.status) == qset->td_end) - update = WHC_UPDATE_UPDATED; - - if (++qset->td_end >= WHCI_QSET_TD_MAX) - qset->td_end = 0; - qset->ntds++; - } - - return update; -} - -/** - * qset_remove_qtd - remove the first qTD from a qset. - * - * The qTD might be still active (if it's part of a IN URB that - * resulted in a short read) so ensure it's deactivated. - */ -static void qset_remove_qtd(struct whc *whc, struct whc_qset *qset) -{ - qset->qtd[qset->td_start].status = 0; - - if (++qset->td_start >= WHCI_QSET_TD_MAX) - qset->td_start = 0; - qset->ntds--; -} - -static void qset_copy_bounce_to_sg(struct whc *whc, struct whc_std *std) -{ - struct scatterlist *sg; - void *bounce; - size_t remaining, offset; - - bounce = std->bounce_buf; - remaining = std->len; - - sg = std->bounce_sg; - offset = std->bounce_offset; - - while (remaining) { - size_t len; - - len = min(sg->length - offset, remaining); - memcpy(sg_virt(sg) + offset, bounce, len); - - bounce += len; - remaining -= len; - - offset += len; - if (offset >= sg->length) { - sg = sg_next(sg); - offset = 0; - } - } - -} - -/** - * qset_free_std - remove an sTD and free it. - * @whc: the WHCI host controller - * @std: the sTD to remove and free. - */ -void qset_free_std(struct whc *whc, struct whc_std *std) -{ - list_del(&std->list_node); - if (std->bounce_buf) { - bool is_out = usb_pipeout(std->urb->pipe); - dma_addr_t dma_addr; - - if (std->num_pointers) - dma_addr = le64_to_cpu(std->pl_virt[0].buf_ptr); - else - dma_addr = std->dma_addr; - - dma_unmap_single(whc->wusbhc.dev, dma_addr, - std->len, is_out ? DMA_TO_DEVICE : DMA_FROM_DEVICE); - if (!is_out) - qset_copy_bounce_to_sg(whc, std); - kfree(std->bounce_buf); - } - if (std->pl_virt) { - if (!dma_mapping_error(whc->wusbhc.dev, std->dma_addr)) - dma_unmap_single(whc->wusbhc.dev, std->dma_addr, - std->num_pointers * sizeof(struct whc_page_list_entry), - DMA_TO_DEVICE); - kfree(std->pl_virt); - std->pl_virt = NULL; - } - kfree(std); -} - -/** - * qset_remove_qtds - remove an URB's qTDs (and sTDs). - */ -static void qset_remove_qtds(struct whc *whc, struct whc_qset *qset, - struct urb *urb) -{ - struct whc_std *std, *t; - - list_for_each_entry_safe(std, t, &qset->stds, list_node) { - if (std->urb != urb) - break; - if (std->qtd != NULL) - qset_remove_qtd(whc, qset); - qset_free_std(whc, std); - } -} - -/** - * qset_free_stds - free any remaining sTDs for an URB. - */ -static void qset_free_stds(struct whc_qset *qset, struct urb *urb) -{ - struct whc_std *std, *t; - - list_for_each_entry_safe(std, t, &qset->stds, list_node) { - if (std->urb == urb) - qset_free_std(qset->whc, std); - } -} - -static int qset_fill_page_list(struct whc *whc, struct whc_std *std, gfp_t mem_flags) -{ - dma_addr_t dma_addr = std->dma_addr; - dma_addr_t sp, ep; - size_t pl_len; - int p; - - /* Short buffers don't need a page list. */ - if (std->len <= WHCI_PAGE_SIZE) { - std->num_pointers = 0; - return 0; - } - - sp = dma_addr & ~(WHCI_PAGE_SIZE-1); - ep = dma_addr + std->len; - std->num_pointers = DIV_ROUND_UP(ep - sp, WHCI_PAGE_SIZE); - - pl_len = std->num_pointers * sizeof(struct whc_page_list_entry); - std->pl_virt = kmalloc(pl_len, mem_flags); - if (std->pl_virt == NULL) - return -ENOMEM; - std->dma_addr = dma_map_single(whc->wusbhc.dev, std->pl_virt, pl_len, DMA_TO_DEVICE); - if (dma_mapping_error(whc->wusbhc.dev, std->dma_addr)) { - kfree(std->pl_virt); - return -EFAULT; - } - - for (p = 0; p < std->num_pointers; p++) { - std->pl_virt[p].buf_ptr = cpu_to_le64(dma_addr); - dma_addr = (dma_addr + WHCI_PAGE_SIZE) & ~(WHCI_PAGE_SIZE-1); - } - - return 0; -} - -/** - * urb_dequeue_work - executes asl/pzl update and gives back the urb to the system. - */ -static void urb_dequeue_work(struct work_struct *work) -{ - struct whc_urb *wurb = container_of(work, struct whc_urb, dequeue_work); - struct whc_qset *qset = wurb->qset; - struct whc *whc = qset->whc; - unsigned long flags; - - if (wurb->is_async) - asl_update(whc, WUSBCMD_ASYNC_UPDATED - | WUSBCMD_ASYNC_SYNCED_DB - | WUSBCMD_ASYNC_QSET_RM); - else - pzl_update(whc, WUSBCMD_PERIODIC_UPDATED - | WUSBCMD_PERIODIC_SYNCED_DB - | WUSBCMD_PERIODIC_QSET_RM); - - spin_lock_irqsave(&whc->lock, flags); - qset_remove_urb(whc, qset, wurb->urb, wurb->status); - spin_unlock_irqrestore(&whc->lock, flags); -} - -static struct whc_std *qset_new_std(struct whc *whc, struct whc_qset *qset, - struct urb *urb, gfp_t mem_flags) -{ - struct whc_std *std; - - std = kzalloc(sizeof(struct whc_std), mem_flags); - if (std == NULL) - return NULL; - - std->urb = urb; - std->qtd = NULL; - - INIT_LIST_HEAD(&std->list_node); - list_add_tail(&std->list_node, &qset->stds); - - return std; -} - -static int qset_add_urb_sg(struct whc *whc, struct whc_qset *qset, struct urb *urb, - gfp_t mem_flags) -{ - size_t remaining; - struct scatterlist *sg; - int i; - int ntds = 0; - struct whc_std *std = NULL; - struct whc_page_list_entry *new_pl_virt; - dma_addr_t prev_end = 0; - size_t pl_len; - int p = 0; - - remaining = urb->transfer_buffer_length; - - for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { - dma_addr_t dma_addr; - size_t dma_remaining; - dma_addr_t sp, ep; - int num_pointers; - - if (remaining == 0) { - break; - } - - dma_addr = sg_dma_address(sg); - dma_remaining = min_t(size_t, sg_dma_len(sg), remaining); - - while (dma_remaining) { - size_t dma_len; - - /* - * We can use the previous std (if it exists) provided that: - * - the previous one ended on a page boundary. - * - the current one begins on a page boundary. - * - the previous one isn't full. - * - * If a new std is needed but the previous one - * was not a whole number of packets then this - * sg list cannot be mapped onto multiple - * qTDs. Return an error and let the caller - * sort it out. - */ - if (!std - || (prev_end & (WHCI_PAGE_SIZE-1)) - || (dma_addr & (WHCI_PAGE_SIZE-1)) - || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) { - if (std && std->len % qset->max_packet != 0) - return -EINVAL; - std = qset_new_std(whc, qset, urb, mem_flags); - if (std == NULL) { - return -ENOMEM; - } - ntds++; - p = 0; - } - - dma_len = dma_remaining; - - /* - * If the remainder of this element doesn't - * fit in a single qTD, limit the qTD to a - * whole number of packets. This allows the - * remainder to go into the next qTD. - */ - if (std->len + dma_len > QTD_MAX_XFER_SIZE) { - dma_len = (QTD_MAX_XFER_SIZE / qset->max_packet) - * qset->max_packet - std->len; - } - - std->len += dma_len; - std->ntds_remaining = -1; /* filled in later */ - - sp = dma_addr & ~(WHCI_PAGE_SIZE-1); - ep = dma_addr + dma_len; - num_pointers = DIV_ROUND_UP(ep - sp, WHCI_PAGE_SIZE); - std->num_pointers += num_pointers; - - pl_len = std->num_pointers * sizeof(struct whc_page_list_entry); - - new_pl_virt = krealloc(std->pl_virt, pl_len, mem_flags); - if (new_pl_virt == NULL) { - kfree(std->pl_virt); - std->pl_virt = NULL; - return -ENOMEM; - } - std->pl_virt = new_pl_virt; - - for (;p < std->num_pointers; p++) { - std->pl_virt[p].buf_ptr = cpu_to_le64(dma_addr); - dma_addr = (dma_addr + WHCI_PAGE_SIZE) & ~(WHCI_PAGE_SIZE-1); - } - - prev_end = dma_addr = ep; - dma_remaining -= dma_len; - remaining -= dma_len; - } - } - - /* Now the number of stds is know, go back and fill in - std->ntds_remaining. */ - list_for_each_entry(std, &qset->stds, list_node) { - if (std->ntds_remaining == -1) { - pl_len = std->num_pointers * sizeof(struct whc_page_list_entry); - std->dma_addr = dma_map_single(whc->wusbhc.dev, std->pl_virt, - pl_len, DMA_TO_DEVICE); - if (dma_mapping_error(whc->wusbhc.dev, std->dma_addr)) - return -EFAULT; - std->ntds_remaining = ntds--; - } - } - return 0; -} - -/** - * qset_add_urb_sg_linearize - add an urb with sg list, copying the data - * - * If the URB contains an sg list whose elements cannot be directly - * mapped to qTDs then the data must be transferred via bounce - * buffers. - */ -static int qset_add_urb_sg_linearize(struct whc *whc, struct whc_qset *qset, - struct urb *urb, gfp_t mem_flags) -{ - bool is_out = usb_pipeout(urb->pipe); - size_t max_std_len; - size_t remaining; - int ntds = 0; - struct whc_std *std = NULL; - void *bounce = NULL; - struct scatterlist *sg; - int i; - - /* limit maximum bounce buffer to 16 * 3.5 KiB ~= 28 k */ - max_std_len = qset->max_burst * qset->max_packet; - - remaining = urb->transfer_buffer_length; - - for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { - size_t len; - size_t sg_remaining; - void *orig; - - if (remaining == 0) { - break; - } - - sg_remaining = min_t(size_t, remaining, sg->length); - orig = sg_virt(sg); - - while (sg_remaining) { - if (!std || std->len == max_std_len) { - std = qset_new_std(whc, qset, urb, mem_flags); - if (std == NULL) - return -ENOMEM; - std->bounce_buf = kmalloc(max_std_len, mem_flags); - if (std->bounce_buf == NULL) - return -ENOMEM; - std->bounce_sg = sg; - std->bounce_offset = orig - sg_virt(sg); - bounce = std->bounce_buf; - ntds++; - } - - len = min(sg_remaining, max_std_len - std->len); - - if (is_out) - memcpy(bounce, orig, len); - - std->len += len; - std->ntds_remaining = -1; /* filled in later */ - - bounce += len; - orig += len; - sg_remaining -= len; - remaining -= len; - } - } - - /* - * For each of the new sTDs, map the bounce buffers, create - * page lists (if necessary), and fill in std->ntds_remaining. - */ - list_for_each_entry(std, &qset->stds, list_node) { - if (std->ntds_remaining != -1) - continue; - - std->dma_addr = dma_map_single(&whc->umc->dev, std->bounce_buf, std->len, - is_out ? DMA_TO_DEVICE : DMA_FROM_DEVICE); - if (dma_mapping_error(&whc->umc->dev, std->dma_addr)) - return -EFAULT; - - if (qset_fill_page_list(whc, std, mem_flags) < 0) - return -ENOMEM; - - std->ntds_remaining = ntds--; - } - - return 0; -} - -/** - * qset_add_urb - add an urb to the qset's queue. - * - * The URB is chopped into sTDs, one for each qTD that will required. - * At least one qTD (and sTD) is required even if the transfer has no - * data (e.g., for some control transfers). - */ -int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb, - gfp_t mem_flags) -{ - struct whc_urb *wurb; - int remaining = urb->transfer_buffer_length; - u64 transfer_dma = urb->transfer_dma; - int ntds_remaining; - int ret; - - wurb = kzalloc(sizeof(struct whc_urb), mem_flags); - if (wurb == NULL) - goto err_no_mem; - urb->hcpriv = wurb; - wurb->qset = qset; - wurb->urb = urb; - INIT_WORK(&wurb->dequeue_work, urb_dequeue_work); - - if (urb->num_sgs) { - ret = qset_add_urb_sg(whc, qset, urb, mem_flags); - if (ret == -EINVAL) { - qset_free_stds(qset, urb); - ret = qset_add_urb_sg_linearize(whc, qset, urb, mem_flags); - } - if (ret < 0) - goto err_no_mem; - return 0; - } - - ntds_remaining = DIV_ROUND_UP(remaining, QTD_MAX_XFER_SIZE); - if (ntds_remaining == 0) - ntds_remaining = 1; - - while (ntds_remaining) { - struct whc_std *std; - size_t std_len; - - std_len = remaining; - if (std_len > QTD_MAX_XFER_SIZE) - std_len = QTD_MAX_XFER_SIZE; - - std = qset_new_std(whc, qset, urb, mem_flags); - if (std == NULL) - goto err_no_mem; - - std->dma_addr = transfer_dma; - std->len = std_len; - std->ntds_remaining = ntds_remaining; - - if (qset_fill_page_list(whc, std, mem_flags) < 0) - goto err_no_mem; - - ntds_remaining--; - remaining -= std_len; - transfer_dma += std_len; - } - - return 0; - -err_no_mem: - qset_free_stds(qset, urb); - return -ENOMEM; -} - -/** - * qset_remove_urb - remove an URB from the urb queue. - * - * The URB is returned to the USB subsystem. - */ -void qset_remove_urb(struct whc *whc, struct whc_qset *qset, - struct urb *urb, int status) -{ - struct wusbhc *wusbhc = &whc->wusbhc; - struct whc_urb *wurb = urb->hcpriv; - - usb_hcd_unlink_urb_from_ep(&wusbhc->usb_hcd, urb); - /* Drop the lock as urb->complete() may enqueue another urb. */ - spin_unlock(&whc->lock); - wusbhc_giveback_urb(wusbhc, urb, status); - spin_lock(&whc->lock); - - kfree(wurb); -} - -/** - * get_urb_status_from_qtd - get the completed urb status from qTD status - * @urb: completed urb - * @status: qTD status - */ -static int get_urb_status_from_qtd(struct urb *urb, u32 status) -{ - if (status & QTD_STS_HALTED) { - if (status & QTD_STS_DBE) - return usb_pipein(urb->pipe) ? -ENOSR : -ECOMM; - else if (status & QTD_STS_BABBLE) - return -EOVERFLOW; - else if (status & QTD_STS_RCE) - return -ETIME; - return -EPIPE; - } - if (usb_pipein(urb->pipe) - && (urb->transfer_flags & URB_SHORT_NOT_OK) - && urb->actual_length < urb->transfer_buffer_length) - return -EREMOTEIO; - return 0; -} - -/** - * process_inactive_qtd - process an inactive (but not halted) qTD. - * - * Update the urb with the transfer bytes from the qTD, if the urb is - * completely transferred or (in the case of an IN only) the LPF is - * set, then the transfer is complete and the urb should be returned - * to the system. - */ -void process_inactive_qtd(struct whc *whc, struct whc_qset *qset, - struct whc_qtd *qtd) -{ - struct whc_std *std = list_first_entry(&qset->stds, struct whc_std, list_node); - struct urb *urb = std->urb; - uint32_t status; - bool complete; - - status = le32_to_cpu(qtd->status); - - urb->actual_length += std->len - QTD_STS_TO_LEN(status); - - if (usb_pipein(urb->pipe) && (status & QTD_STS_LAST_PKT)) - complete = true; - else - complete = whc_std_last(std); - - qset_remove_qtd(whc, qset); - qset_free_std(whc, std); - - /* - * Transfers for this URB are complete? Then return it to the - * USB subsystem. - */ - if (complete) { - qset_remove_qtds(whc, qset, urb); - qset_remove_urb(whc, qset, urb, get_urb_status_from_qtd(urb, status)); - - /* - * If iAlt isn't valid then the hardware didn't - * advance iCur. Adjust the start and end pointers to - * match iCur. - */ - if (!(status & QTD_STS_IALT_VALID)) - qset->td_start = qset->td_end - = QH_STATUS_TO_ICUR(le16_to_cpu(qset->qh.status)); - qset->pause_after_urb = NULL; - } -} - -/** - * process_halted_qtd - process a qset with a halted qtd - * - * Remove all the qTDs for the failed URB and return the failed URB to - * the USB subsystem. Then remove all other qTDs so the qset can be - * removed. - * - * FIXME: this is the point where rate adaptation can be done. If a - * transfer failed because it exceeded the maximum number of retries - * then it could be reactivated with a slower rate without having to - * remove the qset. - */ -void process_halted_qtd(struct whc *whc, struct whc_qset *qset, - struct whc_qtd *qtd) -{ - struct whc_std *std = list_first_entry(&qset->stds, struct whc_std, list_node); - struct urb *urb = std->urb; - int urb_status; - - urb_status = get_urb_status_from_qtd(urb, le32_to_cpu(qtd->status)); - - qset_remove_qtds(whc, qset, urb); - qset_remove_urb(whc, qset, urb, urb_status); - - list_for_each_entry(std, &qset->stds, list_node) { - if (qset->ntds == 0) - break; - qset_remove_qtd(whc, qset); - std->qtd = NULL; - } - - qset->remove = 1; -} - -void qset_free(struct whc *whc, struct whc_qset *qset) -{ - dma_pool_free(whc->qset_pool, qset, qset->qset_dma); -} - -/** - * qset_delete - wait for a qset to be unused, then free it. - */ -void qset_delete(struct whc *whc, struct whc_qset *qset) -{ - wait_for_completion(&qset->remove_complete); - qset_free(whc, qset); -} diff --git a/drivers/staging/wusbcore/host/whci/whcd.h b/drivers/staging/wusbcore/host/whci/whcd.h deleted file mode 100644 index a442a2589e83..000000000000 --- a/drivers/staging/wusbcore/host/whci/whcd.h +++ /dev/null @@ -1,202 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) private header. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#ifndef __WHCD_H -#define __WHCD_H - -#include <linux/workqueue.h> - -#include "../../../uwb/include/whci.h" -#include "../../../uwb/include/umc.h" -#include "whci-hc.h" - -/* Generic command timeout. */ -#define WHC_GENCMD_TIMEOUT_MS 100 - -struct whc_dbg; - -struct whc { - struct wusbhc wusbhc; - struct umc_dev *umc; - - resource_size_t base_phys; - void __iomem *base; - int irq; - - u8 n_devices; - u8 n_keys; - u8 n_mmc_ies; - - u64 *pz_list; - struct dn_buf_entry *dn_buf; - struct di_buf_entry *di_buf; - dma_addr_t pz_list_dma; - dma_addr_t dn_buf_dma; - dma_addr_t di_buf_dma; - - spinlock_t lock; - struct mutex mutex; - - void * gen_cmd_buf; - dma_addr_t gen_cmd_buf_dma; - wait_queue_head_t cmd_wq; - - struct workqueue_struct *workqueue; - struct work_struct dn_work; - - struct dma_pool *qset_pool; - - struct list_head async_list; - struct list_head async_removed_list; - wait_queue_head_t async_list_wq; - struct work_struct async_work; - - struct list_head periodic_list[5]; - struct list_head periodic_removed_list; - wait_queue_head_t periodic_list_wq; - struct work_struct periodic_work; - - struct whc_dbg *dbg; -}; - -#define wusbhc_to_whc(w) (container_of((w), struct whc, wusbhc)) - -/** - * struct whc_std - a software TD. - * @urb: the URB this sTD is for. - * @offset: start of the URB's data for this TD. - * @len: the length of data in the associated TD. - * @ntds_remaining: number of TDs (starting from this one) in this transfer. - * - * @bounce_buf: a bounce buffer if the std was from an urb with a sg - * list that could not be mapped to qTDs directly. - * @bounce_sg: the first scatterlist element bounce_buf is for. - * @bounce_offset: the offset into bounce_sg for the start of bounce_buf. - * - * Queued URBs may require more TDs than are available in a qset so we - * use a list of these "software TDs" (sTDs) to hold per-TD data. - */ -struct whc_std { - struct urb *urb; - size_t len; - int ntds_remaining; - struct whc_qtd *qtd; - - struct list_head list_node; - int num_pointers; - dma_addr_t dma_addr; - struct whc_page_list_entry *pl_virt; - - void *bounce_buf; - struct scatterlist *bounce_sg; - unsigned bounce_offset; -}; - -/** - * struct whc_urb - per URB host controller structure. - * @urb: the URB this struct is for. - * @qset: the qset associated to the URB. - * @dequeue_work: the work to remove the URB when dequeued. - * @is_async: the URB belongs to async sheduler or not. - * @status: the status to be returned when calling wusbhc_giveback_urb. - */ -struct whc_urb { - struct urb *urb; - struct whc_qset *qset; - struct work_struct dequeue_work; - bool is_async; - int status; -}; - -/** - * whc_std_last - is this sTD the URB's last? - * @std: the sTD to check. - */ -static inline bool whc_std_last(struct whc_std *std) -{ - return std->ntds_remaining <= 1; -} - -enum whc_update { - WHC_UPDATE_ADDED = 0x01, - WHC_UPDATE_REMOVED = 0x02, - WHC_UPDATE_UPDATED = 0x04, -}; - -/* init.c */ -int whc_init(struct whc *whc); -void whc_clean_up(struct whc *whc); - -/* hw.c */ -void whc_write_wusbcmd(struct whc *whc, u32 mask, u32 val); -int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len); -void whc_hw_error(struct whc *whc, const char *reason); - -/* wusb.c */ -int whc_wusbhc_start(struct wusbhc *wusbhc); -void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay); -int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, - u8 handle, struct wuie_hdr *wuie); -int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle); -int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm); -int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev); -int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots); -int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, - const void *ptk, size_t key_size); -int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid, - const void *gtk, size_t key_size); -int whc_set_cluster_id(struct whc *whc, u8 bcid); - -/* int.c */ -irqreturn_t whc_int_handler(struct usb_hcd *hcd); -void whc_dn_work(struct work_struct *work); - -/* asl.c */ -void asl_start(struct whc *whc); -void asl_stop(struct whc *whc); -int asl_init(struct whc *whc); -void asl_clean_up(struct whc *whc); -int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags); -int asl_urb_dequeue(struct whc *whc, struct urb *urb, int status); -void asl_qset_delete(struct whc *whc, struct whc_qset *qset); -void scan_async_work(struct work_struct *work); - -/* pzl.c */ -int pzl_init(struct whc *whc); -void pzl_clean_up(struct whc *whc); -void pzl_start(struct whc *whc); -void pzl_stop(struct whc *whc); -int pzl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags); -int pzl_urb_dequeue(struct whc *whc, struct urb *urb, int status); -void pzl_qset_delete(struct whc *whc, struct whc_qset *qset); -void scan_periodic_work(struct work_struct *work); - -/* qset.c */ -struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags); -void qset_free(struct whc *whc, struct whc_qset *qset); -struct whc_qset *get_qset(struct whc *whc, struct urb *urb, gfp_t mem_flags); -void qset_delete(struct whc *whc, struct whc_qset *qset); -void qset_clear(struct whc *whc, struct whc_qset *qset); -void qset_reset(struct whc *whc, struct whc_qset *qset); -int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb, - gfp_t mem_flags); -void qset_free_std(struct whc *whc, struct whc_std *std); -void qset_remove_urb(struct whc *whc, struct whc_qset *qset, - struct urb *urb, int status); -void process_halted_qtd(struct whc *whc, struct whc_qset *qset, - struct whc_qtd *qtd); -void process_inactive_qtd(struct whc *whc, struct whc_qset *qset, - struct whc_qtd *qtd); -enum whc_update qset_add_qtds(struct whc *whc, struct whc_qset *qset); -void qset_remove_complete(struct whc *whc, struct whc_qset *qset); -void pzl_update(struct whc *whc, uint32_t wusbcmd); -void asl_update(struct whc *whc, uint32_t wusbcmd); - -/* debug.c */ -void whc_dbg_init(struct whc *whc); -void whc_dbg_clean_up(struct whc *whc); - -#endif /* #ifndef __WHCD_H */ diff --git a/drivers/staging/wusbcore/host/whci/whci-hc.h b/drivers/staging/wusbcore/host/whci/whci-hc.h deleted file mode 100644 index 5a86a57a80cc..000000000000 --- a/drivers/staging/wusbcore/host/whci/whci-hc.h +++ /dev/null @@ -1,401 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) data structures. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#ifndef _WHCI_WHCI_HC_H -#define _WHCI_WHCI_HC_H - -#include <linux/list.h> - -/** - * WHCI_PAGE_SIZE - page size use by WHCI - * - * WHCI assumes that host system uses pages of 4096 octets. - */ -#define WHCI_PAGE_SIZE 4096 - - -/** - * QTD_MAX_TXFER_SIZE - max number of bytes to transfer with a single - * qtd. - * - * This is 2^20 - 1. - */ -#define QTD_MAX_XFER_SIZE 1048575 - - -/** - * struct whc_qtd - Queue Element Transfer Descriptors (qTD) - * - * This describes the data for a bulk, control or interrupt transfer. - * - * [WHCI] section 3.2.4 - */ -struct whc_qtd { - __le32 status; /*< remaining transfer len and transfer status */ - __le32 options; - __le64 page_list_ptr; /*< physical pointer to data buffer page list*/ - __u8 setup[8]; /*< setup data for control transfers */ -} __attribute__((packed)); - -#define QTD_STS_ACTIVE (1 << 31) /* enable execution of transaction */ -#define QTD_STS_HALTED (1 << 30) /* transfer halted */ -#define QTD_STS_DBE (1 << 29) /* data buffer error */ -#define QTD_STS_BABBLE (1 << 28) /* babble detected */ -#define QTD_STS_RCE (1 << 27) /* retry count exceeded */ -#define QTD_STS_LAST_PKT (1 << 26) /* set Last Packet Flag in WUSB header */ -#define QTD_STS_INACTIVE (1 << 25) /* queue set is marked inactive */ -#define QTD_STS_IALT_VALID (1 << 23) /* iAlt field is valid */ -#define QTD_STS_IALT(i) (QTD_STS_IALT_VALID | ((i) << 20)) /* iAlt field */ -#define QTD_STS_LEN(l) ((l) << 0) /* transfer length */ -#define QTD_STS_TO_LEN(s) ((s) & 0x000fffff) - -#define QTD_OPT_IOC (1 << 1) /* page_list_ptr points to buffer directly */ -#define QTD_OPT_SMALL (1 << 0) /* interrupt on complete */ - -/** - * struct whc_itd - Isochronous Queue Element Transfer Descriptors (iTD) - * - * This describes the data and other parameters for an isochronous - * transfer. - * - * [WHCI] section 3.2.5 - */ -struct whc_itd { - __le16 presentation_time; /*< presentation time for OUT transfers */ - __u8 num_segments; /*< number of data segments in segment list */ - __u8 status; /*< command execution status */ - __le32 options; /*< misc transfer options */ - __le64 page_list_ptr; /*< physical pointer to data buffer page list */ - __le64 seg_list_ptr; /*< physical pointer to segment list */ -} __attribute__((packed)); - -#define ITD_STS_ACTIVE (1 << 7) /* enable execution of transaction */ -#define ITD_STS_DBE (1 << 5) /* data buffer error */ -#define ITD_STS_BABBLE (1 << 4) /* babble detected */ -#define ITD_STS_INACTIVE (1 << 1) /* queue set is marked inactive */ - -#define ITD_OPT_IOC (1 << 1) /* interrupt on complete */ -#define ITD_OPT_SMALL (1 << 0) /* page_list_ptr points to buffer directly */ - -/** - * Page list entry. - * - * A TD's page list must contain sufficient page list entries for the - * total data length in the TD. - * - * [WHCI] section 3.2.4.3 - */ -struct whc_page_list_entry { - __le64 buf_ptr; /*< physical pointer to buffer */ -} __attribute__((packed)); - -/** - * struct whc_seg_list_entry - Segment list entry. - * - * Describes a portion of the data buffer described in the containing - * qTD's page list. - * - * seg_ptr = qtd->page_list_ptr[qtd->seg_list_ptr[seg].idx].buf_ptr - * + qtd->seg_list_ptr[seg].offset; - * - * Segments can't cross page boundries. - * - * [WHCI] section 3.2.5.5 - */ -struct whc_seg_list_entry { - __le16 len; /*< segment length */ - __u8 idx; /*< index into page list */ - __u8 status; /*< segment status */ - __le16 offset; /*< 12 bit offset into page */ -} __attribute__((packed)); - -/** - * struct whc_qhead - endpoint and status information for a qset. - * - * [WHCI] section 3.2.6 - */ -struct whc_qhead { - __le64 link; /*< next qset in list */ - __le32 info1; - __le32 info2; - __le32 info3; - __le16 status; - __le16 err_count; /*< transaction error count */ - __le32 cur_window; - __le32 scratch[3]; /*< h/w scratch area */ - union { - struct whc_qtd qtd; - struct whc_itd itd; - } overlay; -} __attribute__((packed)); - -#define QH_LINK_PTR_MASK (~0x03Full) -#define QH_LINK_PTR(ptr) ((ptr) & QH_LINK_PTR_MASK) -#define QH_LINK_IQS (1 << 4) /* isochronous queue set */ -#define QH_LINK_NTDS(n) (((n) - 1) << 1) /* number of TDs in queue set */ -#define QH_LINK_T (1 << 0) /* last queue set in periodic schedule list */ - -#define QH_INFO1_EP(e) ((e) << 0) /* endpoint number */ -#define QH_INFO1_DIR_IN (1 << 4) /* IN transfer */ -#define QH_INFO1_DIR_OUT (0 << 4) /* OUT transfer */ -#define QH_INFO1_TR_TYPE_CTRL (0x0 << 5) /* control transfer */ -#define QH_INFO1_TR_TYPE_ISOC (0x1 << 5) /* isochronous transfer */ -#define QH_INFO1_TR_TYPE_BULK (0x2 << 5) /* bulk transfer */ -#define QH_INFO1_TR_TYPE_INT (0x3 << 5) /* interrupt */ -#define QH_INFO1_TR_TYPE_LP_INT (0x7 << 5) /* low power interrupt */ -#define QH_INFO1_DEV_INFO_IDX(i) ((i) << 8) /* index into device info buffer */ -#define QH_INFO1_SET_INACTIVE (1 << 15) /* set inactive after transfer */ -#define QH_INFO1_MAX_PKT_LEN(l) ((l) << 16) /* maximum packet length */ - -#define QH_INFO2_BURST(b) ((b) << 0) /* maximum burst length */ -#define QH_INFO2_DBP(p) ((p) << 5) /* data burst policy (see [WUSB] table 5-7) */ -#define QH_INFO2_MAX_COUNT(c) ((c) << 8) /* max isoc/int pkts per zone */ -#define QH_INFO2_RQS (1 << 15) /* reactivate queue set */ -#define QH_INFO2_MAX_RETRY(r) ((r) << 16) /* maximum transaction retries */ -#define QH_INFO2_MAX_SEQ(s) ((s) << 20) /* maximum sequence number */ -#define QH_INFO3_MAX_DELAY(d) ((d) << 0) /* maximum stream delay in 125 us units (isoc only) */ -#define QH_INFO3_INTERVAL(i) ((i) << 16) /* segment interval in 125 us units (isoc only) */ - -#define QH_INFO3_TX_RATE(r) ((r) << 24) /* PHY rate (see [ECMA-368] section 10.3.1.1) */ -#define QH_INFO3_TX_PWR(p) ((p) << 29) /* transmit power (see [WUSB] section 5.2.1.2) */ - -#define QH_STATUS_FLOW_CTRL (1 << 15) -#define QH_STATUS_ICUR(i) ((i) << 5) -#define QH_STATUS_TO_ICUR(s) (((s) >> 5) & 0x7) -#define QH_STATUS_SEQ_MASK 0x1f - -/** - * usb_pipe_to_qh_type - USB core pipe type to QH transfer type - * - * Returns the QH type field for a USB core pipe type. - */ -static inline unsigned usb_pipe_to_qh_type(unsigned pipe) -{ - static const unsigned type[] = { - [PIPE_ISOCHRONOUS] = QH_INFO1_TR_TYPE_ISOC, - [PIPE_INTERRUPT] = QH_INFO1_TR_TYPE_INT, - [PIPE_CONTROL] = QH_INFO1_TR_TYPE_CTRL, - [PIPE_BULK] = QH_INFO1_TR_TYPE_BULK, - }; - return type[usb_pipetype(pipe)]; -} - -/** - * Maxiumum number of TDs in a qset. - */ -#define WHCI_QSET_TD_MAX 8 - -/** - * struct whc_qset - WUSB data transfers to a specific endpoint - * @qh: the QHead of this qset - * @qtd: up to 8 qTDs (for qsets for control, bulk and interrupt - * transfers) - * @itd: up to 8 iTDs (for qsets for isochronous transfers) - * @qset_dma: DMA address for this qset - * @whc: WHCI HC this qset is for - * @ep: endpoint - * @stds: list of sTDs queued to this qset - * @ntds: number of qTDs queued (not necessarily the same as nTDs - * field in the QH) - * @td_start: index of the first qTD in the list - * @td_end: index of next free qTD in the list (provided - * ntds < WHCI_QSET_TD_MAX) - * - * Queue Sets (qsets) are added to the asynchronous schedule list - * (ASL) or the periodic zone list (PZL). - * - * qsets may contain up to 8 TDs (either qTDs or iTDs as appropriate). - * Each TD may refer to at most 1 MiB of data. If a single transfer - * has > 8MiB of data, TDs can be reused as they are completed since - * the TD list is used as a circular buffer. Similarly, several - * (smaller) transfers may be queued in a qset. - * - * WHCI controllers may cache portions of the qsets in the ASL and - * PZL, requiring the WHCD to inform the WHC that the lists have been - * updated (fields changed or qsets inserted or removed). For safe - * insertion and removal of qsets from the lists the schedule must be - * stopped to avoid races in updating the QH link pointers. - * - * Since the HC is free to execute qsets in any order, all transfers - * to an endpoint should use the same qset to ensure transfers are - * executed in the order they're submitted. - * - * [WHCI] section 3.2.3 - */ -struct whc_qset { - struct whc_qhead qh; - union { - struct whc_qtd qtd[WHCI_QSET_TD_MAX]; - struct whc_itd itd[WHCI_QSET_TD_MAX]; - }; - - /* private data for WHCD */ - dma_addr_t qset_dma; - struct whc *whc; - struct usb_host_endpoint *ep; - struct list_head stds; - int ntds; - int td_start; - int td_end; - struct list_head list_node; - unsigned in_sw_list:1; - unsigned in_hw_list:1; - unsigned remove:1; - unsigned reset:1; - struct urb *pause_after_urb; - struct completion remove_complete; - uint16_t max_packet; - uint8_t max_burst; - uint8_t max_seq; -}; - -static inline void whc_qset_set_link_ptr(u64 *ptr, u64 target) -{ - if (target) - *ptr = (*ptr & ~(QH_LINK_PTR_MASK | QH_LINK_T)) | QH_LINK_PTR(target); - else - *ptr = QH_LINK_T; -} - -/** - * struct di_buf_entry - Device Information (DI) buffer entry. - * - * There's one of these per connected device. - */ -struct di_buf_entry { - __le32 availability_info[8]; /*< MAS availability information, one MAS per bit */ - __le32 addr_sec_info; /*< addressing and security info */ - __le32 reserved[7]; -} __attribute__((packed)); - -#define WHC_DI_SECURE (1 << 31) -#define WHC_DI_DISABLE (1 << 30) -#define WHC_DI_KEY_IDX(k) ((k) << 8) -#define WHC_DI_KEY_IDX_MASK 0x0000ff00 -#define WHC_DI_DEV_ADDR(a) ((a) << 0) -#define WHC_DI_DEV_ADDR_MASK 0x000000ff - -/** - * struct dn_buf_entry - Device Notification (DN) buffer entry. - * - * [WHCI] section 3.2.8 - */ -struct dn_buf_entry { - __u8 msg_size; /*< number of octets of valid DN data */ - __u8 reserved1; - __u8 src_addr; /*< source address */ - __u8 status; /*< buffer entry status */ - __le32 tkid; /*< TKID for source device, valid if secure bit is set */ - __u8 dn_data[56]; /*< up to 56 octets of DN data */ -} __attribute__((packed)); - -#define WHC_DN_STATUS_VALID (1 << 7) /* buffer entry is valid */ -#define WHC_DN_STATUS_SECURE (1 << 6) /* notification received using secure frame */ - -#define WHC_N_DN_ENTRIES (4096 / sizeof(struct dn_buf_entry)) - -/* The Add MMC IE WUSB Generic Command may take up to 256 bytes of - data. [WHCI] section 2.4.7. */ -#define WHC_GEN_CMD_DATA_LEN 256 - -/* - * HC registers. - * - * [WHCI] section 2.4 - */ - -#define WHCIVERSION 0x00 - -#define WHCSPARAMS 0x04 -# define WHCSPARAMS_TO_N_MMC_IES(p) (((p) >> 16) & 0xff) -# define WHCSPARAMS_TO_N_KEYS(p) (((p) >> 8) & 0xff) -# define WHCSPARAMS_TO_N_DEVICES(p) (((p) >> 0) & 0x7f) - -#define WUSBCMD 0x08 -# define WUSBCMD_BCID(b) ((b) << 16) -# define WUSBCMD_BCID_MASK (0xff << 16) -# define WUSBCMD_ASYNC_QSET_RM (1 << 12) -# define WUSBCMD_PERIODIC_QSET_RM (1 << 11) -# define WUSBCMD_WUSBSI(s) ((s) << 8) -# define WUSBCMD_WUSBSI_MASK (0x7 << 8) -# define WUSBCMD_ASYNC_SYNCED_DB (1 << 7) -# define WUSBCMD_PERIODIC_SYNCED_DB (1 << 6) -# define WUSBCMD_ASYNC_UPDATED (1 << 5) -# define WUSBCMD_PERIODIC_UPDATED (1 << 4) -# define WUSBCMD_ASYNC_EN (1 << 3) -# define WUSBCMD_PERIODIC_EN (1 << 2) -# define WUSBCMD_WHCRESET (1 << 1) -# define WUSBCMD_RUN (1 << 0) - -#define WUSBSTS 0x0c -# define WUSBSTS_ASYNC_SCHED (1 << 15) -# define WUSBSTS_PERIODIC_SCHED (1 << 14) -# define WUSBSTS_DNTS_SCHED (1 << 13) -# define WUSBSTS_HCHALTED (1 << 12) -# define WUSBSTS_GEN_CMD_DONE (1 << 9) -# define WUSBSTS_CHAN_TIME_ROLLOVER (1 << 8) -# define WUSBSTS_DNTS_OVERFLOW (1 << 7) -# define WUSBSTS_BPST_ADJUSTMENT_CHANGED (1 << 6) -# define WUSBSTS_HOST_ERR (1 << 5) -# define WUSBSTS_ASYNC_SCHED_SYNCED (1 << 4) -# define WUSBSTS_PERIODIC_SCHED_SYNCED (1 << 3) -# define WUSBSTS_DNTS_INT (1 << 2) -# define WUSBSTS_ERR_INT (1 << 1) -# define WUSBSTS_INT (1 << 0) -# define WUSBSTS_INT_MASK 0x3ff - -#define WUSBINTR 0x10 -# define WUSBINTR_GEN_CMD_DONE (1 << 9) -# define WUSBINTR_CHAN_TIME_ROLLOVER (1 << 8) -# define WUSBINTR_DNTS_OVERFLOW (1 << 7) -# define WUSBINTR_BPST_ADJUSTMENT_CHANGED (1 << 6) -# define WUSBINTR_HOST_ERR (1 << 5) -# define WUSBINTR_ASYNC_SCHED_SYNCED (1 << 4) -# define WUSBINTR_PERIODIC_SCHED_SYNCED (1 << 3) -# define WUSBINTR_DNTS_INT (1 << 2) -# define WUSBINTR_ERR_INT (1 << 1) -# define WUSBINTR_INT (1 << 0) -# define WUSBINTR_ALL 0x3ff - -#define WUSBGENCMDSTS 0x14 -# define WUSBGENCMDSTS_ACTIVE (1 << 31) -# define WUSBGENCMDSTS_ERROR (1 << 24) -# define WUSBGENCMDSTS_IOC (1 << 23) -# define WUSBGENCMDSTS_MMCIE_ADD 0x01 -# define WUSBGENCMDSTS_MMCIE_RM 0x02 -# define WUSBGENCMDSTS_SET_MAS 0x03 -# define WUSBGENCMDSTS_CHAN_STOP 0x04 -# define WUSBGENCMDSTS_RWP_EN 0x05 - -#define WUSBGENCMDPARAMS 0x18 -#define WUSBGENADDR 0x20 -#define WUSBASYNCLISTADDR 0x28 -#define WUSBDNTSBUFADDR 0x30 -#define WUSBDEVICEINFOADDR 0x38 - -#define WUSBSETSECKEYCMD 0x40 -# define WUSBSETSECKEYCMD_SET (1 << 31) -# define WUSBSETSECKEYCMD_ERASE (1 << 30) -# define WUSBSETSECKEYCMD_GTK (1 << 8) -# define WUSBSETSECKEYCMD_IDX(i) ((i) << 0) - -#define WUSBTKID 0x44 -#define WUSBSECKEY 0x48 -#define WUSBPERIODICLISTBASE 0x58 -#define WUSBMASINDEX 0x60 - -#define WUSBDNTSCTRL 0x64 -# define WUSBDNTSCTRL_ACTIVE (1 << 31) -# define WUSBDNTSCTRL_INTERVAL(i) ((i) << 8) -# define WUSBDNTSCTRL_SLOTS(s) ((s) << 0) - -#define WUSBTIME 0x68 -# define WUSBTIME_CHANNEL_TIME_MASK 0x00ffffff - -#define WUSBBPST 0x6c -#define WUSBDIBUPDATED 0x70 - -#endif /* #ifndef _WHCI_WHCI_HC_H */ diff --git a/drivers/staging/wusbcore/host/whci/wusb.c b/drivers/staging/wusbcore/host/whci/wusb.c deleted file mode 100644 index 6d0068ab35e4..000000000000 --- a/drivers/staging/wusbcore/host/whci/wusb.c +++ /dev/null @@ -1,210 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless Host Controller (WHC) WUSB operations. - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> - -#include "../../../uwb/include/umc.h" -#include "../../wusbhc.h" - -#include "whcd.h" - -static int whc_update_di(struct whc *whc, int idx) -{ - int offset = idx / 32; - u32 bit = 1 << (idx % 32); - - le_writel(bit, whc->base + WUSBDIBUPDATED + offset); - - return whci_wait_for(&whc->umc->dev, - whc->base + WUSBDIBUPDATED + offset, bit, 0, - 100, "DI update"); -} - -/* - * WHCI starts MMCs based on there being a valid GTK so these need - * only start/stop the asynchronous and periodic schedules and send a - * channel stop command. - */ - -int whc_wusbhc_start(struct wusbhc *wusbhc) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - - asl_start(whc); - pzl_start(whc); - - return 0; -} - -void whc_wusbhc_stop(struct wusbhc *wusbhc, int delay) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - u32 stop_time, now_time; - int ret; - - pzl_stop(whc); - asl_stop(whc); - - now_time = le_readl(whc->base + WUSBTIME) & WUSBTIME_CHANNEL_TIME_MASK; - stop_time = (now_time + ((delay * 8) << 7)) & 0x00ffffff; - ret = whc_do_gencmd(whc, WUSBGENCMDSTS_CHAN_STOP, stop_time, NULL, 0); - if (ret == 0) - msleep(delay); -} - -int whc_mmcie_add(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, - u8 handle, struct wuie_hdr *wuie) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - u32 params; - - params = (interval << 24) - | (repeat_cnt << 16) - | (wuie->bLength << 8) - | handle; - - return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_ADD, params, wuie, wuie->bLength); -} - -int whc_mmcie_rm(struct wusbhc *wusbhc, u8 handle) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - u32 params; - - params = handle; - - return whc_do_gencmd(whc, WUSBGENCMDSTS_MMCIE_RM, params, NULL, 0); -} - -int whc_bwa_set(struct wusbhc *wusbhc, s8 stream_index, const struct uwb_mas_bm *mas_bm) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - - if (stream_index >= 0) - whc_write_wusbcmd(whc, WUSBCMD_WUSBSI_MASK, WUSBCMD_WUSBSI(stream_index)); - - return whc_do_gencmd(whc, WUSBGENCMDSTS_SET_MAS, 0, (void *)mas_bm, sizeof(*mas_bm)); -} - -int whc_dev_info_set(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - int idx = wusb_dev->port_idx; - struct di_buf_entry *di = &whc->di_buf[idx]; - int ret; - - mutex_lock(&whc->mutex); - - uwb_mas_bm_copy_le(di->availability_info, &wusb_dev->availability); - di->addr_sec_info &= ~(WHC_DI_DISABLE | WHC_DI_DEV_ADDR_MASK); - di->addr_sec_info |= WHC_DI_DEV_ADDR(wusb_dev->addr); - - ret = whc_update_di(whc, idx); - - mutex_unlock(&whc->mutex); - - return ret; -} - -/* - * Set the number of Device Notification Time Slots (DNTS) and enable - * device notifications. - */ -int whc_set_num_dnts(struct wusbhc *wusbhc, u8 interval, u8 slots) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - u32 dntsctrl; - - dntsctrl = WUSBDNTSCTRL_ACTIVE - | WUSBDNTSCTRL_INTERVAL(interval) - | WUSBDNTSCTRL_SLOTS(slots); - - le_writel(dntsctrl, whc->base + WUSBDNTSCTRL); - - return 0; -} - -static int whc_set_key(struct whc *whc, u8 key_index, uint32_t tkid, - const void *key, size_t key_size, bool is_gtk) -{ - uint32_t setkeycmd; - uint32_t seckey[4]; - int i; - int ret; - - memcpy(seckey, key, key_size); - setkeycmd = WUSBSETSECKEYCMD_SET | WUSBSETSECKEYCMD_IDX(key_index); - if (is_gtk) - setkeycmd |= WUSBSETSECKEYCMD_GTK; - - le_writel(tkid, whc->base + WUSBTKID); - for (i = 0; i < 4; i++) - le_writel(seckey[i], whc->base + WUSBSECKEY + 4*i); - le_writel(setkeycmd, whc->base + WUSBSETSECKEYCMD); - - ret = whci_wait_for(&whc->umc->dev, whc->base + WUSBSETSECKEYCMD, - WUSBSETSECKEYCMD_SET, 0, 100, "set key"); - - return ret; -} - -/** - * whc_set_ptk - set the PTK to use for a device. - * - * The index into the key table for this PTK is the same as the - * device's port index. - */ -int whc_set_ptk(struct wusbhc *wusbhc, u8 port_idx, u32 tkid, - const void *ptk, size_t key_size) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - struct di_buf_entry *di = &whc->di_buf[port_idx]; - int ret; - - mutex_lock(&whc->mutex); - - if (ptk) { - ret = whc_set_key(whc, port_idx, tkid, ptk, key_size, false); - if (ret) - goto out; - - di->addr_sec_info &= ~WHC_DI_KEY_IDX_MASK; - di->addr_sec_info |= WHC_DI_SECURE | WHC_DI_KEY_IDX(port_idx); - } else - di->addr_sec_info &= ~WHC_DI_SECURE; - - ret = whc_update_di(whc, port_idx); -out: - mutex_unlock(&whc->mutex); - return ret; -} - -/** - * whc_set_gtk - set the GTK for subsequent broadcast packets - * - * The GTK is stored in the last entry in the key table (the previous - * N_DEVICES entries are for the per-device PTKs). - */ -int whc_set_gtk(struct wusbhc *wusbhc, u32 tkid, - const void *gtk, size_t key_size) -{ - struct whc *whc = wusbhc_to_whc(wusbhc); - int ret; - - mutex_lock(&whc->mutex); - - ret = whc_set_key(whc, whc->n_devices, tkid, gtk, key_size, true); - - mutex_unlock(&whc->mutex); - - return ret; -} - -int whc_set_cluster_id(struct whc *whc, u8 bcid) -{ - whc_write_wusbcmd(whc, WUSBCMD_BCID_MASK, WUSBCMD_BCID(bcid)); - return 0; -} diff --git a/drivers/staging/wusbcore/include/association.h b/drivers/staging/wusbcore/include/association.h deleted file mode 100644 index d7f3cb9b9db5..000000000000 --- a/drivers/staging/wusbcore/include/association.h +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB - Cable Based Association - * - * Copyright (C) 2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * 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 __LINUX_USB_ASSOCIATION_H -#define __LINUX_USB_ASSOCIATION_H - - -/* - * Association attributes - * - * Association Models Supplement to WUSB 1.0 T[3-1] - * - * Each field in the structures has it's ID, it's length and then the - * value. This is the actual definition of the field's ID and its - * length. - */ -struct wusb_am_attr { - __u8 id; - __u8 len; -}; - -/* Different fields defined by the spec */ -#define WUSB_AR_AssociationTypeId { .id = cpu_to_le16(0x0000), .len = cpu_to_le16(2) } -#define WUSB_AR_AssociationSubTypeId { .id = cpu_to_le16(0x0001), .len = cpu_to_le16(2) } -#define WUSB_AR_Length { .id = cpu_to_le16(0x0002), .len = cpu_to_le16(4) } -#define WUSB_AR_AssociationStatus { .id = cpu_to_le16(0x0004), .len = cpu_to_le16(4) } -#define WUSB_AR_LangID { .id = cpu_to_le16(0x0008), .len = cpu_to_le16(2) } -#define WUSB_AR_DeviceFriendlyName { .id = cpu_to_le16(0x000b), .len = cpu_to_le16(64) } /* max */ -#define WUSB_AR_HostFriendlyName { .id = cpu_to_le16(0x000c), .len = cpu_to_le16(64) } /* max */ -#define WUSB_AR_CHID { .id = cpu_to_le16(0x1000), .len = cpu_to_le16(16) } -#define WUSB_AR_CDID { .id = cpu_to_le16(0x1001), .len = cpu_to_le16(16) } -#define WUSB_AR_ConnectionContext { .id = cpu_to_le16(0x1002), .len = cpu_to_le16(48) } -#define WUSB_AR_BandGroups { .id = cpu_to_le16(0x1004), .len = cpu_to_le16(2) } - -/* CBAF Control Requests (AMS1.0[T4-1] */ -enum { - CBAF_REQ_GET_ASSOCIATION_INFORMATION = 0x01, - CBAF_REQ_GET_ASSOCIATION_REQUEST, - CBAF_REQ_SET_ASSOCIATION_RESPONSE -}; - -/* - * CBAF USB-interface defitions - * - * No altsettings, one optional interrupt endpoint. - */ -enum { - CBAF_IFACECLASS = 0xef, - CBAF_IFACESUBCLASS = 0x03, - CBAF_IFACEPROTOCOL = 0x01, -}; - -/* Association Information (AMS1.0[T4-3]) */ -struct wusb_cbaf_assoc_info { - __le16 Length; - __u8 NumAssociationRequests; - __le16 Flags; - __u8 AssociationRequestsArray[]; -} __attribute__((packed)); - -/* Association Request (AMS1.0[T4-4]) */ -struct wusb_cbaf_assoc_request { - __u8 AssociationDataIndex; - __u8 Reserved; - __le16 AssociationTypeId; - __le16 AssociationSubTypeId; - __le32 AssociationTypeInfoSize; -} __attribute__((packed)); - -enum { - AR_TYPE_WUSB = 0x0001, - AR_TYPE_WUSB_RETRIEVE_HOST_INFO = 0x0000, - AR_TYPE_WUSB_ASSOCIATE = 0x0001, -}; - -/* Association Attribute header (AMS1.0[3.8]) */ -struct wusb_cbaf_attr_hdr { - __le16 id; - __le16 len; -} __attribute__((packed)); - -/* Host Info (AMS1.0[T4-7]) (yeah, more headers and fields...) */ -struct wusb_cbaf_host_info { - struct wusb_cbaf_attr_hdr AssociationTypeId_hdr; - __le16 AssociationTypeId; - struct wusb_cbaf_attr_hdr AssociationSubTypeId_hdr; - __le16 AssociationSubTypeId; - struct wusb_cbaf_attr_hdr CHID_hdr; - struct wusb_ckhdid CHID; - struct wusb_cbaf_attr_hdr LangID_hdr; - __le16 LangID; - struct wusb_cbaf_attr_hdr HostFriendlyName_hdr; - __u8 HostFriendlyName[]; -} __attribute__((packed)); - -/* Device Info (AMS1.0[T4-8]) - * - * I still don't get this tag'n'header stuff for each goddamn - * field... - */ -struct wusb_cbaf_device_info { - struct wusb_cbaf_attr_hdr Length_hdr; - __le32 Length; - struct wusb_cbaf_attr_hdr CDID_hdr; - struct wusb_ckhdid CDID; - struct wusb_cbaf_attr_hdr BandGroups_hdr; - __le16 BandGroups; - struct wusb_cbaf_attr_hdr LangID_hdr; - __le16 LangID; - struct wusb_cbaf_attr_hdr DeviceFriendlyName_hdr; - __u8 DeviceFriendlyName[]; -} __attribute__((packed)); - -/* Connection Context; CC_DATA - Success case (AMS1.0[T4-9]) */ -struct wusb_cbaf_cc_data { - struct wusb_cbaf_attr_hdr AssociationTypeId_hdr; - __le16 AssociationTypeId; - struct wusb_cbaf_attr_hdr AssociationSubTypeId_hdr; - __le16 AssociationSubTypeId; - struct wusb_cbaf_attr_hdr Length_hdr; - __le32 Length; - struct wusb_cbaf_attr_hdr ConnectionContext_hdr; - struct wusb_ckhdid CHID; - struct wusb_ckhdid CDID; - struct wusb_ckhdid CK; - struct wusb_cbaf_attr_hdr BandGroups_hdr; - __le16 BandGroups; -} __attribute__((packed)); - -/* CC_DATA - Failure case (AMS1.0[T4-10]) */ -struct wusb_cbaf_cc_data_fail { - struct wusb_cbaf_attr_hdr AssociationTypeId_hdr; - __le16 AssociationTypeId; - struct wusb_cbaf_attr_hdr AssociationSubTypeId_hdr; - __le16 AssociationSubTypeId; - struct wusb_cbaf_attr_hdr Length_hdr; - __le16 Length; - struct wusb_cbaf_attr_hdr AssociationStatus_hdr; - __u32 AssociationStatus; -} __attribute__((packed)); - -#endif /* __LINUX_USB_ASSOCIATION_H */ diff --git a/drivers/staging/wusbcore/include/wusb-wa.h b/drivers/staging/wusbcore/include/wusb-wa.h deleted file mode 100644 index 64a840b5106e..000000000000 --- a/drivers/staging/wusbcore/include/wusb-wa.h +++ /dev/null @@ -1,304 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Wire Adapter constants and structures. - * - * Copyright (C) 2005-2006 Intel Corporation. - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * 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 Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * FIXME: docs - * FIXME: organize properly, group logically - * - * All the event structures are defined in uwb/spec.h, as they are - * common to the WHCI and WUSB radio control interfaces. - * - * References: - * [WUSB] Wireless Universal Serial Bus Specification, revision 1.0, ch8 - */ -#ifndef __LINUX_USB_WUSB_WA_H -#define __LINUX_USB_WUSB_WA_H - -/** - * Radio Command Request for the Radio Control Interface - * - * Radio Control Interface command and event codes are the same as - * WHCI, and listed in include/linux/uwb.h:UWB_RC_{CMD,EVT}_* - */ -enum { - WA_EXEC_RC_CMD = 40, /* Radio Control command Request */ -}; - -/* Wireless Adapter Requests ([WUSB] table 8-51) */ -enum { - WUSB_REQ_ADD_MMC_IE = 20, - WUSB_REQ_REMOVE_MMC_IE = 21, - WUSB_REQ_SET_NUM_DNTS = 22, - WUSB_REQ_SET_CLUSTER_ID = 23, - WUSB_REQ_SET_DEV_INFO = 24, - WUSB_REQ_GET_TIME = 25, - WUSB_REQ_SET_STREAM_IDX = 26, - WUSB_REQ_SET_WUSB_MAS = 27, - WUSB_REQ_CHAN_STOP = 28, -}; - - -/* Wireless Adapter WUSB Channel Time types ([WUSB] table 8-52) */ -enum { - WUSB_TIME_ADJ = 0, - WUSB_TIME_BPST = 1, - WUSB_TIME_WUSB = 2, -}; - -enum { - WA_ENABLE = 0x01, - WA_RESET = 0x02, - RPIPE_PAUSE = 0x1, - RPIPE_STALL = 0x2, -}; - -/* Responses from Get Status request ([WUSB] section 8.3.1.6) */ -enum { - WA_STATUS_ENABLED = 0x01, - WA_STATUS_RESETTING = 0x02 -}; - -enum rpipe_crs { - RPIPE_CRS_CTL = 0x01, - RPIPE_CRS_ISO = 0x02, - RPIPE_CRS_BULK = 0x04, - RPIPE_CRS_INTR = 0x08 -}; - -/** - * RPipe descriptor ([WUSB] section 8.5.2.11) - * - * FIXME: explain rpipes - */ -struct usb_rpipe_descriptor { - u8 bLength; - u8 bDescriptorType; - __le16 wRPipeIndex; - __le16 wRequests; - __le16 wBlocks; /* rw if 0 */ - __le16 wMaxPacketSize; /* rw */ - union { - u8 dwa_bHSHubAddress; /* rw: DWA. */ - u8 hwa_bMaxBurst; /* rw: HWA. */ - }; - union { - u8 dwa_bHSHubPort; /* rw: DWA. */ - u8 hwa_bDeviceInfoIndex; /* rw: HWA. */ - }; - u8 bSpeed; /* rw: xfer rate 'enum uwb_phy_rate' */ - union { - u8 dwa_bDeviceAddress; /* rw: DWA Target device address. */ - u8 hwa_reserved; /* rw: HWA. */ - }; - u8 bEndpointAddress; /* rw: Target EP address */ - u8 bDataSequence; /* ro: Current Data sequence */ - __le32 dwCurrentWindow; /* ro */ - u8 bMaxDataSequence; /* ro?: max supported seq */ - u8 bInterval; /* rw: */ - u8 bOverTheAirInterval; /* rw: */ - u8 bmAttribute; /* ro? */ - u8 bmCharacteristics; /* ro? enum rpipe_attr, supported xsactions */ - u8 bmRetryOptions; /* rw? */ - __le16 wNumTransactionErrors; /* rw */ -} __attribute__ ((packed)); - -/** - * Wire Adapter Notification types ([WUSB] sections 8.4.5 & 8.5.4) - * - * These are the notifications coming on the notification endpoint of - * an HWA and a DWA. - */ -enum wa_notif_type { - DWA_NOTIF_RWAKE = 0x91, - DWA_NOTIF_PORTSTATUS = 0x92, - WA_NOTIF_TRANSFER = 0x93, - HWA_NOTIF_BPST_ADJ = 0x94, - HWA_NOTIF_DN = 0x95, -}; - -/** - * Wire Adapter notification header - * - * Notifications coming from a wire adapter use a common header - * defined in [WUSB] sections 8.4.5 & 8.5.4. - */ -struct wa_notif_hdr { - u8 bLength; - u8 bNotifyType; /* enum wa_notif_type */ -} __packed; - -/** - * HWA DN Received notification [(WUSB] section 8.5.4.2) - * - * The DNData is specified in WUSB1.0[7.6]. For each device - * notification we received, we just need to dispatch it. - * - * @dndata: this is really an array of notifications, but all start - * with the same header. - */ -struct hwa_notif_dn { - struct wa_notif_hdr hdr; - u8 bSourceDeviceAddr; /* from errata 2005/07 */ - u8 bmAttributes; - struct wusb_dn_hdr dndata[]; -} __packed; - -/* [WUSB] section 8.3.3 */ -enum wa_xfer_type { - WA_XFER_TYPE_CTL = 0x80, - WA_XFER_TYPE_BI = 0x81, /* bulk/interrupt */ - WA_XFER_TYPE_ISO = 0x82, - WA_XFER_RESULT = 0x83, - WA_XFER_ABORT = 0x84, - WA_XFER_ISO_PACKET_INFO = 0xA0, - WA_XFER_ISO_PACKET_STATUS = 0xA1, -}; - -/* [WUSB] section 8.3.3 */ -struct wa_xfer_hdr { - u8 bLength; /* 0x18 */ - u8 bRequestType; /* 0x80 WA_REQUEST_TYPE_CTL */ - __le16 wRPipe; /* RPipe index */ - __le32 dwTransferID; /* Host-assigned ID */ - __le32 dwTransferLength; /* Length of data to xfer */ - u8 bTransferSegment; -} __packed; - -struct wa_xfer_ctl { - struct wa_xfer_hdr hdr; - u8 bmAttribute; - __le16 wReserved; - struct usb_ctrlrequest baSetupData; -} __packed; - -struct wa_xfer_bi { - struct wa_xfer_hdr hdr; - u8 bReserved; - __le16 wReserved; -} __packed; - -/* [WUSB] section 8.5.5 */ -struct wa_xfer_hwaiso { - struct wa_xfer_hdr hdr; - u8 bReserved; - __le16 wPresentationTime; - __le32 dwNumOfPackets; -} __packed; - -struct wa_xfer_packet_info_hwaiso { - __le16 wLength; - u8 bPacketType; - u8 bReserved; - __le16 PacketLength[0]; -} __packed; - -struct wa_xfer_packet_status_len_hwaiso { - __le16 PacketLength; - __le16 PacketStatus; -} __packed; - -struct wa_xfer_packet_status_hwaiso { - __le16 wLength; - u8 bPacketType; - u8 bReserved; - struct wa_xfer_packet_status_len_hwaiso PacketStatus[0]; -} __packed; - -/* [WUSB] section 8.3.3.5 */ -struct wa_xfer_abort { - u8 bLength; - u8 bRequestType; - __le16 wRPipe; /* RPipe index */ - __le32 dwTransferID; /* Host-assigned ID */ -} __packed; - -/** - * WA Transfer Complete notification ([WUSB] section 8.3.3.3) - * - */ -struct wa_notif_xfer { - struct wa_notif_hdr hdr; - u8 bEndpoint; - u8 Reserved; -} __packed; - -/** Transfer result basic codes [WUSB] table 8-15 */ -enum { - WA_XFER_STATUS_SUCCESS, - WA_XFER_STATUS_HALTED, - WA_XFER_STATUS_DATA_BUFFER_ERROR, - WA_XFER_STATUS_BABBLE, - WA_XFER_RESERVED, - WA_XFER_STATUS_NOT_FOUND, - WA_XFER_STATUS_INSUFFICIENT_RESOURCE, - WA_XFER_STATUS_TRANSACTION_ERROR, - WA_XFER_STATUS_ABORTED, - WA_XFER_STATUS_RPIPE_NOT_READY, - WA_XFER_INVALID_FORMAT, - WA_XFER_UNEXPECTED_SEGMENT_NUMBER, - WA_XFER_STATUS_RPIPE_TYPE_MISMATCH, -}; - -/** [WUSB] section 8.3.3.4 */ -struct wa_xfer_result { - struct wa_notif_hdr hdr; - __le32 dwTransferID; - __le32 dwTransferLength; - u8 bTransferSegment; - u8 bTransferStatus; - __le32 dwNumOfPackets; -} __packed; - -/** - * Wire Adapter Class Descriptor ([WUSB] section 8.5.2.7). - * - * NOTE: u16 fields are read Little Endian from the hardware. - * - * @bNumPorts is the original max number of devices that the host can - * connect; we might chop this so the stack can handle - * it. In case you need to access it, use wusbhc->ports_max - * if it is a Wireless USB WA. - */ -struct usb_wa_descriptor { - u8 bLength; - u8 bDescriptorType; - __le16 bcdWAVersion; - u8 bNumPorts; /* don't use!! */ - u8 bmAttributes; /* Reserved == 0 */ - __le16 wNumRPipes; - __le16 wRPipeMaxBlock; - u8 bRPipeBlockSize; - u8 bPwrOn2PwrGood; - u8 bNumMMCIEs; - u8 DeviceRemovable; /* FIXME: in DWA this is up to 16 bytes */ -} __packed; - -/** - * HWA Device Information Buffer (WUSB1.0[T8.54]) - */ -struct hwa_dev_info { - u8 bmDeviceAvailability[32]; /* FIXME: ignored for now */ - u8 bDeviceAddress; - __le16 wPHYRates; - u8 bmDeviceAttribute; -} __packed; - -#endif /* #ifndef __LINUX_USB_WUSB_WA_H */ diff --git a/drivers/staging/wusbcore/include/wusb.h b/drivers/staging/wusbcore/include/wusb.h deleted file mode 100644 index 09771d1da7bc..000000000000 --- a/drivers/staging/wusbcore/include/wusb.h +++ /dev/null @@ -1,362 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Standard Definitions - * Event Size Tables - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * 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 Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * - * FIXME: docs - * FIXME: organize properly, group logically - * - * All the event structures are defined in uwb/spec.h, as they are - * common to the WHCI and WUSB radio control interfaces. - */ - -#ifndef __WUSB_H__ -#define __WUSB_H__ - -#include <linux/types.h> -#include <linux/kernel.h> -#include <linux/usb/ch9.h> -#include <linux/param.h> -#include "../../uwb/include/spec.h" - -/** - * WUSB Information Element header - * - * I don't know why, they decided to make it different to the MBOA MAC - * IE Header; beats me. - */ -struct wuie_hdr { - u8 bLength; - u8 bIEIdentifier; -} __attribute__((packed)); - -enum { - WUIE_ID_WCTA = 0x80, - WUIE_ID_CONNECTACK, - WUIE_ID_HOST_INFO, - WUIE_ID_CHANGE_ANNOUNCE, - WUIE_ID_DEVICE_DISCONNECT, - WUIE_ID_HOST_DISCONNECT, - WUIE_ID_KEEP_ALIVE = 0x89, - WUIE_ID_ISOCH_DISCARD, - WUIE_ID_RESET_DEVICE, -}; - -/** - * Maximum number of array elements in a WUSB IE. - * - * WUSB1.0[7.5 before table 7-38] says that in WUSB IEs that - * are "arrays" have to limited to 4 elements. So we define it - * like that to ease up and submit only the neeed size. - */ -#define WUIE_ELT_MAX 4 - -/** - * Wrapper for the data that defines a CHID, a CDID or a CK - * - * WUSB defines that CHIDs, CDIDs and CKs are a 16 byte string of - * data. In order to avoid confusion and enforce types, we wrap it. - * - * Make it packed, as we use it in some hw definitions. - */ -struct wusb_ckhdid { - u8 data[16]; -} __attribute__((packed)); - -static const struct wusb_ckhdid wusb_ckhdid_zero = { .data = { 0 } }; - -#define WUSB_CKHDID_STRSIZE (3 * sizeof(struct wusb_ckhdid) + 1) - -/** - * WUSB IE: Host Information (WUSB1.0[7.5.2]) - * - * Used to provide information about the host to the Wireless USB - * devices in range (CHID can be used as an ASCII string). - */ -struct wuie_host_info { - struct wuie_hdr hdr; - __le16 attributes; - struct wusb_ckhdid CHID; -} __attribute__((packed)); - -/** - * WUSB IE: Connect Ack (WUSB1.0[7.5.1]) - * - * Used to acknowledge device connect requests. See note for - * WUIE_ELT_MAX. - */ -struct wuie_connect_ack { - struct wuie_hdr hdr; - struct { - struct wusb_ckhdid CDID; - u8 bDeviceAddress; /* 0 means unused */ - u8 bReserved; - } blk[WUIE_ELT_MAX]; -} __attribute__((packed)); - -/** - * WUSB IE Host Information Element, Connect Availability - * - * WUSB1.0[7.5.2], bmAttributes description - */ -enum { - WUIE_HI_CAP_RECONNECT = 0, - WUIE_HI_CAP_LIMITED, - WUIE_HI_CAP_RESERVED, - WUIE_HI_CAP_ALL, -}; - -/** - * WUSB IE: Channel Stop (WUSB1.0[7.5.8]) - * - * Tells devices the host is going to stop sending MMCs and will disappear. - */ -struct wuie_channel_stop { - struct wuie_hdr hdr; - u8 attributes; - u8 timestamp[3]; -} __attribute__((packed)); - -/** - * WUSB IE: Keepalive (WUSB1.0[7.5.9]) - * - * Ask device(s) to send keepalives. - */ -struct wuie_keep_alive { - struct wuie_hdr hdr; - u8 bDeviceAddress[WUIE_ELT_MAX]; -} __attribute__((packed)); - -/** - * WUSB IE: Reset device (WUSB1.0[7.5.11]) - * - * Tell device to reset; in all truth, we can fit 4 CDIDs, but we only - * use it for one at the time... - * - * In any case, this request is a wee bit silly: why don't they target - * by address?? - */ -struct wuie_reset { - struct wuie_hdr hdr; - struct wusb_ckhdid CDID; -} __attribute__((packed)); - -/** - * WUSB IE: Disconnect device (WUSB1.0[7.5.11]) - * - * Tell device to disconnect; we can fit 4 addresses, but we only use - * it for one at the time... - */ -struct wuie_disconnect { - struct wuie_hdr hdr; - u8 bDeviceAddress; - u8 padding; -} __attribute__((packed)); - -/** - * WUSB IE: Host disconnect ([WUSB] section 7.5.5) - * - * Tells all connected devices to disconnect. - */ -struct wuie_host_disconnect { - struct wuie_hdr hdr; -} __attribute__((packed)); - -/** - * WUSB Device Notification header (WUSB1.0[7.6]) - */ -struct wusb_dn_hdr { - u8 bType; - u8 notifdata[]; -} __attribute__((packed)); - -/** Device Notification codes (WUSB1.0[Table 7-54]) */ -enum WUSB_DN { - WUSB_DN_CONNECT = 0x01, - WUSB_DN_DISCONNECT = 0x02, - WUSB_DN_EPRDY = 0x03, - WUSB_DN_MASAVAILCHANGED = 0x04, - WUSB_DN_RWAKE = 0x05, - WUSB_DN_SLEEP = 0x06, - WUSB_DN_ALIVE = 0x07, -}; - -/** WUSB Device Notification Connect */ -struct wusb_dn_connect { - struct wusb_dn_hdr hdr; - __le16 attributes; - struct wusb_ckhdid CDID; -} __attribute__((packed)); - -static inline int wusb_dn_connect_prev_dev_addr(const struct wusb_dn_connect *dn) -{ - return le16_to_cpu(dn->attributes) & 0xff; -} - -static inline int wusb_dn_connect_new_connection(const struct wusb_dn_connect *dn) -{ - return (le16_to_cpu(dn->attributes) >> 8) & 0x1; -} - -static inline int wusb_dn_connect_beacon_behavior(const struct wusb_dn_connect *dn) -{ - return (le16_to_cpu(dn->attributes) >> 9) & 0x03; -} - -/** Device is alive (aka: pong) (WUSB1.0[7.6.7]) */ -struct wusb_dn_alive { - struct wusb_dn_hdr hdr; -} __attribute__((packed)); - -/** Device is disconnecting (WUSB1.0[7.6.2]) */ -struct wusb_dn_disconnect { - struct wusb_dn_hdr hdr; -} __attribute__((packed)); - -/* General constants */ -enum { - WUSB_TRUST_TIMEOUT_MS = 4000, /* [WUSB] section 4.15.1 */ -}; - -/* - * WUSB Crypto stuff (WUSB1.0[6]) - */ - -extern const char *wusb_et_name(u8); - -/** - * WUSB key index WUSB1.0[7.3.2.4], for usage when setting keys for - * the host or the device. - */ -static inline u8 wusb_key_index(int index, int type, int originator) -{ - return (originator << 6) | (type << 4) | index; -} - -#define WUSB_KEY_INDEX_TYPE_PTK 0 /* for HWA only */ -#define WUSB_KEY_INDEX_TYPE_ASSOC 1 -#define WUSB_KEY_INDEX_TYPE_GTK 2 -#define WUSB_KEY_INDEX_ORIGINATOR_HOST 0 -#define WUSB_KEY_INDEX_ORIGINATOR_DEVICE 1 -/* bits 0-3 used for the key index. */ -#define WUSB_KEY_INDEX_MAX 15 - -/* A CCM Nonce, defined in WUSB1.0[6.4.1] */ -struct aes_ccm_nonce { - u8 sfn[6]; /* Little Endian */ - u8 tkid[3]; /* LE */ - struct uwb_dev_addr dest_addr; - struct uwb_dev_addr src_addr; -} __attribute__((packed)); - -/* A CCM operation label, defined on WUSB1.0[6.5.x] */ -struct aes_ccm_label { - u8 data[14]; -} __attribute__((packed)); - -/* - * Input to the key derivation sequence defined in - * WUSB1.0[6.5.1]. Rest of the data is in the CCM Nonce passed to the - * PRF function. - */ -struct wusb_keydvt_in { - u8 hnonce[16]; - u8 dnonce[16]; -} __attribute__((packed)); - -/* - * Output from the key derivation sequence defined in - * WUSB1.0[6.5.1]. - */ -struct wusb_keydvt_out { - u8 kck[16]; - u8 ptk[16]; -} __attribute__((packed)); - -/* Pseudo Random Function WUSB1.0[6.5] */ -extern int wusb_crypto_init(void); -extern void wusb_crypto_exit(void); -extern ssize_t wusb_prf(void *out, size_t out_size, - const u8 key[16], const struct aes_ccm_nonce *_n, - const struct aes_ccm_label *a, - const void *b, size_t blen, size_t len); - -static inline int wusb_prf_64(void *out, size_t out_size, const u8 key[16], - const struct aes_ccm_nonce *n, - const struct aes_ccm_label *a, - const void *b, size_t blen) -{ - return wusb_prf(out, out_size, key, n, a, b, blen, 64); -} - -static inline int wusb_prf_128(void *out, size_t out_size, const u8 key[16], - const struct aes_ccm_nonce *n, - const struct aes_ccm_label *a, - const void *b, size_t blen) -{ - return wusb_prf(out, out_size, key, n, a, b, blen, 128); -} - -static inline int wusb_prf_256(void *out, size_t out_size, const u8 key[16], - const struct aes_ccm_nonce *n, - const struct aes_ccm_label *a, - const void *b, size_t blen) -{ - return wusb_prf(out, out_size, key, n, a, b, blen, 256); -} - -/* Key derivation WUSB1.0[6.5.1] */ -static inline int wusb_key_derive(struct wusb_keydvt_out *keydvt_out, - const u8 key[16], - const struct aes_ccm_nonce *n, - const struct wusb_keydvt_in *keydvt_in) -{ - const struct aes_ccm_label a = { .data = "Pair-wise keys" }; - return wusb_prf_256(keydvt_out, sizeof(*keydvt_out), key, n, &a, - keydvt_in, sizeof(*keydvt_in)); -} - -/* - * Out-of-band MIC Generation WUSB1.0[6.5.2] - * - * Compute the MIC over @key, @n and @hs and place it in @mic_out. - * - * @mic_out: Where to place the 8 byte MIC tag - * @key: KCK from the derivation process - * @n: CCM nonce, n->sfn == 0, TKID as established in the - * process. - * @hs: Handshake struct for phase 2 of the 4-way. - * hs->bStatus and hs->bReserved are zero. - * hs->bMessageNumber is 2 (WUSB1.0[7.3.2.5.2] - * hs->dest_addr is the device's USB address padded with 0 - * hs->src_addr is the hosts's UWB device address - * hs->mic is ignored (as we compute that value). - */ -static inline int wusb_oob_mic(u8 mic_out[8], const u8 key[16], - const struct aes_ccm_nonce *n, - const struct usb_handshake *hs) -{ - const struct aes_ccm_label a = { .data = "out-of-bandMIC" }; - return wusb_prf_64(mic_out, 8, key, n, &a, - hs, sizeof(*hs) - sizeof(hs->MIC)); -} - -#endif /* #ifndef __WUSB_H__ */ diff --git a/drivers/staging/wusbcore/mmc.c b/drivers/staging/wusbcore/mmc.c deleted file mode 100644 index 881e1f20d718..000000000000 --- a/drivers/staging/wusbcore/mmc.c +++ /dev/null @@ -1,303 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB Wire Adapter: Control/Data Streaming Interface (WUSB[8]) - * MMC (Microscheduled Management Command) handling - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * WUIEs and MMC IEs...well, they are almost the same at the end. MMC - * IEs are Wireless USB IEs that go into the MMC period...[what is - * that? look in Design-overview.txt]. - * - * - * This is a simple subsystem to keep track of which IEs are being - * sent by the host in the MMC period. - * - * For each WUIE we ask to send, we keep it in an array, so we can - * request its removal later, or replace the content. They are tracked - * by pointer, so be sure to use the same pointer if you want to - * remove it or update the contents. - * - * FIXME: - * - add timers that autoremove intervalled IEs? - */ -#include <linux/slab.h> -#include <linux/export.h> -#include "include/wusb.h" -#include "wusbhc.h" - -/* Initialize the MMCIEs handling mechanism */ -int wusbhc_mmcie_create(struct wusbhc *wusbhc) -{ - u8 mmcies = wusbhc->mmcies_max; - wusbhc->mmcie = kcalloc(mmcies, sizeof(wusbhc->mmcie[0]), GFP_KERNEL); - if (wusbhc->mmcie == NULL) - return -ENOMEM; - mutex_init(&wusbhc->mmcie_mutex); - return 0; -} - -/* Release resources used by the MMCIEs handling mechanism */ -void wusbhc_mmcie_destroy(struct wusbhc *wusbhc) -{ - kfree(wusbhc->mmcie); -} - -/* - * Add or replace an MMC Wireless USB IE. - * - * @interval: See WUSB1.0[8.5.3.1] - * @repeat_cnt: See WUSB1.0[8.5.3.1] - * @handle: See WUSB1.0[8.5.3.1] - * @wuie: Pointer to the header of the WUSB IE data to add. - * MUST BE allocated in a kmalloc buffer (no stack or - * vmalloc). - * THE CALLER ALWAYS OWNS THE POINTER (we don't free it - * on remove, we just forget about it). - * @returns: 0 if ok, < 0 errno code on error. - * - * Goes over the *whole* @wusbhc->mmcie array looking for (a) the - * first free spot and (b) if @wuie is already in the array (aka: - * transmitted in the MMCs) the spot were it is. - * - * If present, we "overwrite it" (update). - * - * - * NOTE: Need special ordering rules -- see below WUSB1.0 Table 7-38. - * The host uses the handle as the 'sort' index. We - * allocate the last one always for the WUIE_ID_HOST_INFO, and - * the rest, first come first serve in inverse order. - * - * Host software must make sure that it adds the other IEs in - * the right order... the host hardware is responsible for - * placing the WCTA IEs in the right place with the other IEs - * set by host software. - * - * NOTE: we can access wusbhc->wa_descr without locking because it is - * read only. - */ -int wusbhc_mmcie_set(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, - struct wuie_hdr *wuie) -{ - int result = -ENOBUFS; - unsigned handle, itr; - - /* Search a handle, taking into account the ordering */ - mutex_lock(&wusbhc->mmcie_mutex); - switch (wuie->bIEIdentifier) { - case WUIE_ID_HOST_INFO: - /* Always last */ - handle = wusbhc->mmcies_max - 1; - break; - case WUIE_ID_ISOCH_DISCARD: - dev_err(wusbhc->dev, "Special ordering case for WUIE ID 0x%x " - "unimplemented\n", wuie->bIEIdentifier); - result = -ENOSYS; - goto error_unlock; - default: - /* search for it or find the last empty slot */ - handle = ~0; - for (itr = 0; itr < wusbhc->mmcies_max - 1; itr++) { - if (wusbhc->mmcie[itr] == wuie) { - handle = itr; - break; - } - if (wusbhc->mmcie[itr] == NULL) - handle = itr; - } - if (handle == ~0) - goto error_unlock; - } - result = (wusbhc->mmcie_add)(wusbhc, interval, repeat_cnt, handle, - wuie); - if (result >= 0) - wusbhc->mmcie[handle] = wuie; -error_unlock: - mutex_unlock(&wusbhc->mmcie_mutex); - return result; -} -EXPORT_SYMBOL_GPL(wusbhc_mmcie_set); - -/* - * Remove an MMC IE previously added with wusbhc_mmcie_set() - * - * @wuie Pointer used to add the WUIE - */ -void wusbhc_mmcie_rm(struct wusbhc *wusbhc, struct wuie_hdr *wuie) -{ - int result; - unsigned handle, itr; - - mutex_lock(&wusbhc->mmcie_mutex); - for (itr = 0; itr < wusbhc->mmcies_max; itr++) { - if (wusbhc->mmcie[itr] == wuie) { - handle = itr; - goto found; - } - } - mutex_unlock(&wusbhc->mmcie_mutex); - return; - -found: - result = (wusbhc->mmcie_rm)(wusbhc, handle); - if (result == 0) - wusbhc->mmcie[itr] = NULL; - mutex_unlock(&wusbhc->mmcie_mutex); -} -EXPORT_SYMBOL_GPL(wusbhc_mmcie_rm); - -static int wusbhc_mmc_start(struct wusbhc *wusbhc) -{ - int ret; - - mutex_lock(&wusbhc->mutex); - ret = wusbhc->start(wusbhc); - if (ret >= 0) - wusbhc->active = 1; - mutex_unlock(&wusbhc->mutex); - - return ret; -} - -static void wusbhc_mmc_stop(struct wusbhc *wusbhc) -{ - mutex_lock(&wusbhc->mutex); - wusbhc->active = 0; - wusbhc->stop(wusbhc, WUSB_CHANNEL_STOP_DELAY_MS); - mutex_unlock(&wusbhc->mutex); -} - -/* - * wusbhc_start - start transmitting MMCs and accepting connections - * @wusbhc: the HC to start - * - * Establishes a cluster reservation, enables device connections, and - * starts MMCs with appropriate DNTS parameters. - */ -int wusbhc_start(struct wusbhc *wusbhc) -{ - int result; - struct device *dev = wusbhc->dev; - - WARN_ON(wusbhc->wuie_host_info != NULL); - BUG_ON(wusbhc->uwb_rc == NULL); - - result = wusbhc_rsv_establish(wusbhc); - if (result < 0) { - dev_err(dev, "cannot establish cluster reservation: %d\n", - result); - goto error_rsv_establish; - } - - result = wusbhc_devconnect_start(wusbhc); - if (result < 0) { - dev_err(dev, "error enabling device connections: %d\n", - result); - goto error_devconnect_start; - } - - result = wusbhc_sec_start(wusbhc); - if (result < 0) { - dev_err(dev, "error starting security in the HC: %d\n", - result); - goto error_sec_start; - } - - result = wusbhc->set_num_dnts(wusbhc, wusbhc->dnts_interval, - wusbhc->dnts_num_slots); - if (result < 0) { - dev_err(dev, "Cannot set DNTS parameters: %d\n", result); - goto error_set_num_dnts; - } - result = wusbhc_mmc_start(wusbhc); - if (result < 0) { - dev_err(dev, "error starting wusbch: %d\n", result); - goto error_wusbhc_start; - } - - return 0; - -error_wusbhc_start: - wusbhc_sec_stop(wusbhc); -error_set_num_dnts: -error_sec_start: - wusbhc_devconnect_stop(wusbhc); -error_devconnect_start: - wusbhc_rsv_terminate(wusbhc); -error_rsv_establish: - return result; -} - -/* - * wusbhc_stop - stop transmitting MMCs - * @wusbhc: the HC to stop - * - * Stops the WUSB channel and removes the cluster reservation. - */ -void wusbhc_stop(struct wusbhc *wusbhc) -{ - wusbhc_mmc_stop(wusbhc); - wusbhc_sec_stop(wusbhc); - wusbhc_devconnect_stop(wusbhc); - wusbhc_rsv_terminate(wusbhc); -} - -/* - * Set/reset/update a new CHID - * - * Depending on the previous state of the MMCs, start, stop or change - * the sent MMC. This effectively switches the host controller on and - * off (radio wise). - */ -int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid) -{ - int result = 0; - - if (memcmp(chid, &wusb_ckhdid_zero, sizeof(*chid)) == 0) - chid = NULL; - - mutex_lock(&wusbhc->mutex); - if (chid) { - if (wusbhc->active) { - mutex_unlock(&wusbhc->mutex); - return -EBUSY; - } - wusbhc->chid = *chid; - } - - /* register with UWB if we haven't already since we are about to start - the radio. */ - if ((chid) && (wusbhc->uwb_rc == NULL)) { - wusbhc->uwb_rc = uwb_rc_get_by_grandpa(wusbhc->dev->parent); - if (wusbhc->uwb_rc == NULL) { - result = -ENODEV; - dev_err(wusbhc->dev, - "Cannot get associated UWB Host Controller\n"); - goto error_rc_get; - } - - result = wusbhc_pal_register(wusbhc); - if (result < 0) { - dev_err(wusbhc->dev, "Cannot register as a UWB PAL\n"); - goto error_pal_register; - } - } - mutex_unlock(&wusbhc->mutex); - - if (chid) - result = uwb_radio_start(&wusbhc->pal); - else if (wusbhc->uwb_rc) - uwb_radio_stop(&wusbhc->pal); - - return result; - -error_pal_register: - uwb_rc_put(wusbhc->uwb_rc); - wusbhc->uwb_rc = NULL; -error_rc_get: - mutex_unlock(&wusbhc->mutex); - - return result; -} -EXPORT_SYMBOL_GPL(wusbhc_chid_set); diff --git a/drivers/staging/wusbcore/pal.c b/drivers/staging/wusbcore/pal.c deleted file mode 100644 index 30f569131471..000000000000 --- a/drivers/staging/wusbcore/pal.c +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Host Controller - * UWB Protocol Adaptation Layer (PAL) glue. - * - * Copyright (C) 2008 Cambridge Silicon Radio Ltd. - */ -#include "wusbhc.h" - -static void wusbhc_channel_changed(struct uwb_pal *pal, int channel) -{ - struct wusbhc *wusbhc = container_of(pal, struct wusbhc, pal); - - dev_dbg(wusbhc->dev, "%s: channel = %d\n", __func__, channel); - if (channel < 0) - wusbhc_stop(wusbhc); - else - wusbhc_start(wusbhc); -} - -/** - * wusbhc_pal_register - register the WUSB HC as a UWB PAL - * @wusbhc: the WUSB HC - */ -int wusbhc_pal_register(struct wusbhc *wusbhc) -{ - uwb_pal_init(&wusbhc->pal); - - wusbhc->pal.name = "wusbhc"; - wusbhc->pal.device = wusbhc->usb_hcd.self.controller; - wusbhc->pal.rc = wusbhc->uwb_rc; - wusbhc->pal.channel_changed = wusbhc_channel_changed; - - return uwb_pal_register(&wusbhc->pal); -} - -/** - * wusbhc_pal_unregister - unregister the WUSB HC as a UWB PAL - * @wusbhc: the WUSB HC - */ -void wusbhc_pal_unregister(struct wusbhc *wusbhc) -{ - if (wusbhc->uwb_rc) - uwb_pal_unregister(&wusbhc->pal); -} diff --git a/drivers/staging/wusbcore/reservation.c b/drivers/staging/wusbcore/reservation.c deleted file mode 100644 index b921faac698b..000000000000 --- a/drivers/staging/wusbcore/reservation.c +++ /dev/null @@ -1,110 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB cluster reservation management - * - * Copyright (C) 2007 Cambridge Silicon Radio Ltd. - */ -#include <linux/kernel.h> - -#include "../uwb/uwb.h" -#include "wusbhc.h" - -/* - * WUSB cluster reservations are multicast reservations with the - * broadcast cluster ID (BCID) as the target DevAddr. - * - * FIXME: consider adjusting the reservation depending on what devices - * are attached. - */ - -static int wusbhc_bwa_set(struct wusbhc *wusbhc, u8 stream, - const struct uwb_mas_bm *mas) -{ - if (mas == NULL) - mas = &uwb_mas_bm_zero; - return wusbhc->bwa_set(wusbhc, stream, mas); -} - -/** - * wusbhc_rsv_complete_cb - WUSB HC reservation complete callback - * @rsv: the reservation - * - * Either set or clear the HC's view of the reservation. - * - * FIXME: when a reservation is denied the HC should be stopped. - */ -static void wusbhc_rsv_complete_cb(struct uwb_rsv *rsv) -{ - struct wusbhc *wusbhc = rsv->pal_priv; - struct device *dev = wusbhc->dev; - struct uwb_mas_bm mas; - - dev_dbg(dev, "%s: state = %d\n", __func__, rsv->state); - switch (rsv->state) { - case UWB_RSV_STATE_O_ESTABLISHED: - uwb_rsv_get_usable_mas(rsv, &mas); - dev_dbg(dev, "established reservation: %*pb\n", - UWB_NUM_MAS, mas.bm); - wusbhc_bwa_set(wusbhc, rsv->stream, &mas); - break; - case UWB_RSV_STATE_NONE: - dev_dbg(dev, "removed reservation\n"); - wusbhc_bwa_set(wusbhc, 0, NULL); - break; - default: - dev_dbg(dev, "unexpected reservation state: %d\n", rsv->state); - break; - } -} - - -/** - * wusbhc_rsv_establish - establish a reservation for the cluster - * @wusbhc: the WUSB HC requesting a bandwidth reservation - */ -int wusbhc_rsv_establish(struct wusbhc *wusbhc) -{ - struct uwb_rc *rc = wusbhc->uwb_rc; - struct uwb_rsv *rsv; - struct uwb_dev_addr bcid; - int ret; - - if (rc == NULL) - return -ENODEV; - - rsv = uwb_rsv_create(rc, wusbhc_rsv_complete_cb, wusbhc); - if (rsv == NULL) - return -ENOMEM; - - bcid.data[0] = wusbhc->cluster_id; - bcid.data[1] = 0; - - rsv->target.type = UWB_RSV_TARGET_DEVADDR; - rsv->target.devaddr = bcid; - rsv->type = UWB_DRP_TYPE_PRIVATE; - rsv->max_mas = 256; /* try to get as much as possible */ - rsv->min_mas = 15; /* one MAS per zone */ - rsv->max_interval = 1; /* max latency is one zone */ - rsv->is_multicast = true; - - ret = uwb_rsv_establish(rsv); - if (ret == 0) - wusbhc->rsv = rsv; - else - uwb_rsv_destroy(rsv); - return ret; -} - - -/** - * wusbhc_rsv_terminate - terminate the cluster reservation - * @wusbhc: the WUSB host whose reservation is to be terminated - */ -void wusbhc_rsv_terminate(struct wusbhc *wusbhc) -{ - if (wusbhc->rsv) { - uwb_rsv_terminate(wusbhc->rsv); - uwb_rsv_destroy(wusbhc->rsv); - wusbhc->rsv = NULL; - } -} diff --git a/drivers/staging/wusbcore/rh.c b/drivers/staging/wusbcore/rh.c deleted file mode 100644 index 20c08cd9dcbf..000000000000 --- a/drivers/staging/wusbcore/rh.c +++ /dev/null @@ -1,426 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Host Controller - * Root Hub operations - * - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * We fake a root hub that has fake ports (as many as simultaneous - * devices the Wireless USB Host Controller can deal with). For each - * port we keep an state in @wusbhc->port[index] identical to the one - * specified in the USB2.0[ch11] spec and some extra device - * information that complements the one in 'struct usb_device' (as - * this lacs a hcpriv pointer). - * - * Note this is common to WHCI and HWA host controllers. - * - * Through here we enable most of the state changes that the USB stack - * will use to connect or disconnect devices. We need to do some - * forced adaptation of Wireless USB device states vs. wired: - * - * USB: WUSB: - * - * Port Powered-off port slot n/a - * Powered-on port slot available - * Disconnected port slot available - * Connected port slot assigned device - * device sent DN_Connect - * device was authenticated - * Enabled device is authenticated, transitioned - * from unauth -> auth -> default address - * -> enabled - * Reset disconnect - * Disable disconnect - * - * This maps the standard USB port states with the WUSB device states - * so we can fake ports without having to modify the USB stack. - * - * FIXME: this process will change in the future - * - * - * ENTRY POINTS - * - * Our entry points into here are, as in hcd.c, the USB stack root hub - * ops defined in the usb_hcd struct: - * - * wusbhc_rh_status_data() Provide hub and port status data bitmap - * - * wusbhc_rh_control() Execution of all the major requests - * you can do to a hub (Set|Clear - * features, get descriptors, status, etc). - * - * wusbhc_rh_[suspend|resume]() That - * - * wusbhc_rh_start_port_reset() ??? unimplemented - */ -#include <linux/slab.h> -#include <linux/export.h> -#include "wusbhc.h" - -/* - * Reset a fake port - * - * Using a Reset Device IE is too heavyweight as it causes the device - * to enter the UnConnected state and leave the cluster, this can mean - * that when the device reconnects it is connected to a different fake - * port. - * - * Instead, reset authenticated devices with a SetAddress(0), followed - * by a SetAddresss(AuthAddr). - * - * For unauthenticated devices just pretend to reset but do nothing. - * If the device initialization continues to fail it will eventually - * time out after TrustTimeout and enter the UnConnected state. - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - * - * Supposedly we are the only thread accesing @wusbhc->port; in any - * case, maybe we should move the mutex locking from - * wusbhc_devconnect_auth() to here. - * - * @port_idx refers to the wusbhc's port index, not the USB port number - */ -static int wusbhc_rh_port_reset(struct wusbhc *wusbhc, u8 port_idx) -{ - int result = 0; - struct wusb_port *port = wusb_port_by_idx(wusbhc, port_idx); - struct wusb_dev *wusb_dev = port->wusb_dev; - - if (wusb_dev == NULL) - return -ENOTCONN; - - port->status |= USB_PORT_STAT_RESET; - port->change |= USB_PORT_STAT_C_RESET; - - if (wusb_dev->addr & WUSB_DEV_ADDR_UNAUTH) - result = 0; - else - result = wusb_dev_update_address(wusbhc, wusb_dev); - - port->status &= ~USB_PORT_STAT_RESET; - port->status |= USB_PORT_STAT_ENABLE; - port->change |= USB_PORT_STAT_C_RESET | USB_PORT_STAT_C_ENABLE; - - return result; -} - -/* - * Return the hub change status bitmap - * - * The bits in the change status bitmap are cleared when a - * ClearPortFeature request is issued (USB2.0[11.12.3,11.12.4]. - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - * - * WARNING!! This gets called from atomic context; we cannot get the - * mutex--the only race condition we can find is some bit - * changing just after we copy it, which shouldn't be too - * big of a problem [and we can't make it an spinlock - * because other parts need to take it and sleep] . - * - * @usb_hcd is refcounted, so it won't disappear under us - * and before killing a host, the polling of the root hub - * would be stopped anyway. - */ -int wusbhc_rh_status_data(struct usb_hcd *usb_hcd, char *_buf) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - size_t cnt, size, bits_set = 0; - - /* WE DON'T LOCK, see comment */ - /* round up to bytes. Hub bit is bit 0 so add 1. */ - size = DIV_ROUND_UP(wusbhc->ports_max + 1, 8); - - /* clear the output buffer. */ - memset(_buf, 0, size); - /* set the bit for each changed port. */ - for (cnt = 0; cnt < wusbhc->ports_max; cnt++) { - - if (wusb_port_by_idx(wusbhc, cnt)->change) { - const int bitpos = cnt+1; - - _buf[bitpos/8] |= (1 << (bitpos % 8)); - bits_set++; - } - } - - return bits_set ? size : 0; -} -EXPORT_SYMBOL_GPL(wusbhc_rh_status_data); - -/* - * Return the hub's descriptor - * - * NOTE: almost cut and paste from ehci-hub.c - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked - */ -static int wusbhc_rh_get_hub_descr(struct wusbhc *wusbhc, u16 wValue, - u16 wIndex, - struct usb_hub_descriptor *descr, - u16 wLength) -{ - u16 temp = 1 + (wusbhc->ports_max / 8); - u8 length = 7 + 2 * temp; - - if (wLength < length) - return -ENOSPC; - descr->bDescLength = 7 + 2 * temp; - descr->bDescriptorType = USB_DT_HUB; /* HUB type */ - descr->bNbrPorts = wusbhc->ports_max; - descr->wHubCharacteristics = cpu_to_le16( - HUB_CHAR_COMMON_LPSM /* All ports power at once */ - | 0x00 /* not part of compound device */ - | HUB_CHAR_NO_OCPM /* No overcurrent protection */ - | 0x00 /* 8 FS think time FIXME ?? */ - | 0x00); /* No port indicators */ - descr->bPwrOn2PwrGood = 0; - descr->bHubContrCurrent = 0; - /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */ - memset(&descr->u.hs.DeviceRemovable[0], 0, temp); - memset(&descr->u.hs.DeviceRemovable[temp], 0xff, temp); - return 0; -} - -/* - * Clear a hub feature - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - * - * Nothing to do, so no locking needed ;) - */ -static int wusbhc_rh_clear_hub_feat(struct wusbhc *wusbhc, u16 feature) -{ - int result; - - switch (feature) { - case C_HUB_LOCAL_POWER: - /* FIXME: maybe plug bit 0 to the power input status, - * if any? - * see wusbhc_rh_get_hub_status() */ - case C_HUB_OVER_CURRENT: - result = 0; - break; - default: - result = -EPIPE; - } - return result; -} - -/* - * Return hub status (it is always zero...) - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - * - * Nothing to do, so no locking needed ;) - */ -static int wusbhc_rh_get_hub_status(struct wusbhc *wusbhc, u32 *buf, - u16 wLength) -{ - /* FIXME: maybe plug bit 0 to the power input status (if any)? */ - *buf = 0; - return 0; -} - -/* - * Set a port feature - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - */ -static int wusbhc_rh_set_port_feat(struct wusbhc *wusbhc, u16 feature, - u8 selector, u8 port_idx) -{ - struct device *dev = wusbhc->dev; - - if (port_idx > wusbhc->ports_max) - return -EINVAL; - - switch (feature) { - /* According to USB2.0[11.24.2.13]p2, these features - * are not required to be implemented. */ - case USB_PORT_FEAT_C_OVER_CURRENT: - case USB_PORT_FEAT_C_ENABLE: - case USB_PORT_FEAT_C_SUSPEND: - case USB_PORT_FEAT_C_CONNECTION: - case USB_PORT_FEAT_C_RESET: - return 0; - case USB_PORT_FEAT_POWER: - /* No such thing, but we fake it works */ - mutex_lock(&wusbhc->mutex); - wusb_port_by_idx(wusbhc, port_idx)->status |= USB_PORT_STAT_POWER; - mutex_unlock(&wusbhc->mutex); - return 0; - case USB_PORT_FEAT_RESET: - return wusbhc_rh_port_reset(wusbhc, port_idx); - case USB_PORT_FEAT_ENABLE: - case USB_PORT_FEAT_SUSPEND: - dev_err(dev, "(port_idx %d) set feat %d/%d UNIMPLEMENTED\n", - port_idx, feature, selector); - return -ENOSYS; - default: - dev_err(dev, "(port_idx %d) set feat %d/%d UNKNOWN\n", - port_idx, feature, selector); - return -EPIPE; - } - - return 0; -} - -/* - * Clear a port feature... - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - */ -static int wusbhc_rh_clear_port_feat(struct wusbhc *wusbhc, u16 feature, - u8 selector, u8 port_idx) -{ - int result = 0; - struct device *dev = wusbhc->dev; - - if (port_idx > wusbhc->ports_max) - return -EINVAL; - - mutex_lock(&wusbhc->mutex); - switch (feature) { - case USB_PORT_FEAT_POWER: /* fake port always on */ - /* According to USB2.0[11.24.2.7.1.4], no need to implement? */ - case USB_PORT_FEAT_C_OVER_CURRENT: - break; - case USB_PORT_FEAT_C_RESET: - wusb_port_by_idx(wusbhc, port_idx)->change &= ~USB_PORT_STAT_C_RESET; - break; - case USB_PORT_FEAT_C_CONNECTION: - wusb_port_by_idx(wusbhc, port_idx)->change &= ~USB_PORT_STAT_C_CONNECTION; - break; - case USB_PORT_FEAT_ENABLE: - __wusbhc_dev_disable(wusbhc, port_idx); - break; - case USB_PORT_FEAT_C_ENABLE: - wusb_port_by_idx(wusbhc, port_idx)->change &= ~USB_PORT_STAT_C_ENABLE; - break; - case USB_PORT_FEAT_SUSPEND: - case USB_PORT_FEAT_C_SUSPEND: - dev_err(dev, "(port_idx %d) Clear feat %d/%d UNIMPLEMENTED\n", - port_idx, feature, selector); - result = -ENOSYS; - break; - default: - dev_err(dev, "(port_idx %d) Clear feat %d/%d UNKNOWN\n", - port_idx, feature, selector); - result = -EPIPE; - break; - } - mutex_unlock(&wusbhc->mutex); - - return result; -} - -/* - * Return the port's status - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - */ -static int wusbhc_rh_get_port_status(struct wusbhc *wusbhc, u16 port_idx, - u32 *_buf, u16 wLength) -{ - __le16 *buf = (__le16 *)_buf; - - if (port_idx > wusbhc->ports_max) - return -EINVAL; - - mutex_lock(&wusbhc->mutex); - buf[0] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->status); - buf[1] = cpu_to_le16(wusb_port_by_idx(wusbhc, port_idx)->change); - mutex_unlock(&wusbhc->mutex); - - return 0; -} - -/* - * Entry point for Root Hub operations - * - * @wusbhc is assumed referenced and @wusbhc->mutex unlocked. - */ -int wusbhc_rh_control(struct usb_hcd *usb_hcd, u16 reqntype, u16 wValue, - u16 wIndex, char *buf, u16 wLength) -{ - int result = -ENOSYS; - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - - switch (reqntype) { - case GetHubDescriptor: - result = wusbhc_rh_get_hub_descr( - wusbhc, wValue, wIndex, - (struct usb_hub_descriptor *) buf, wLength); - break; - case ClearHubFeature: - result = wusbhc_rh_clear_hub_feat(wusbhc, wValue); - break; - case GetHubStatus: - result = wusbhc_rh_get_hub_status(wusbhc, (u32 *)buf, wLength); - break; - - case SetPortFeature: - result = wusbhc_rh_set_port_feat(wusbhc, wValue, wIndex >> 8, - (wIndex & 0xff) - 1); - break; - case ClearPortFeature: - result = wusbhc_rh_clear_port_feat(wusbhc, wValue, wIndex >> 8, - (wIndex & 0xff) - 1); - break; - case GetPortStatus: - result = wusbhc_rh_get_port_status(wusbhc, wIndex - 1, - (u32 *)buf, wLength); - break; - - case SetHubFeature: - default: - dev_err(wusbhc->dev, "%s (%p [%p], %x, %x, %x, %p, %x) " - "UNIMPLEMENTED\n", __func__, usb_hcd, wusbhc, reqntype, - wValue, wIndex, buf, wLength); - /* dump_stack(); */ - result = -ENOSYS; - } - return result; -} -EXPORT_SYMBOL_GPL(wusbhc_rh_control); - -int wusbhc_rh_start_port_reset(struct usb_hcd *usb_hcd, unsigned port_idx) -{ - struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); - dev_err(wusbhc->dev, "%s (%p [%p], port_idx %u) UNIMPLEMENTED\n", - __func__, usb_hcd, wusbhc, port_idx); - WARN_ON(1); - return -ENOSYS; -} -EXPORT_SYMBOL_GPL(wusbhc_rh_start_port_reset); - -static void wusb_port_init(struct wusb_port *port) -{ - port->status |= USB_PORT_STAT_HIGH_SPEED; -} - -/* - * Alloc fake port specific fields and status. - */ -int wusbhc_rh_create(struct wusbhc *wusbhc) -{ - int result = -ENOMEM; - size_t port_size, itr; - port_size = wusbhc->ports_max * sizeof(wusbhc->port[0]); - wusbhc->port = kzalloc(port_size, GFP_KERNEL); - if (wusbhc->port == NULL) - goto error_port_alloc; - for (itr = 0; itr < wusbhc->ports_max; itr++) - wusb_port_init(&wusbhc->port[itr]); - result = 0; -error_port_alloc: - return result; -} - -void wusbhc_rh_destroy(struct wusbhc *wusbhc) -{ - kfree(wusbhc->port); -} diff --git a/drivers/staging/wusbcore/security.c b/drivers/staging/wusbcore/security.c deleted file mode 100644 index 14ac8c98ac9e..000000000000 --- a/drivers/staging/wusbcore/security.c +++ /dev/null @@ -1,599 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Host Controller - * Security support: encryption enablement, etc - * - * Copyright (C) 2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ -#include <linux/types.h> -#include <linux/slab.h> -#include <linux/usb/ch9.h> -#include <linux/random.h> -#include <linux/export.h> -#include "wusbhc.h" -#include <asm/unaligned.h> - -static void wusbhc_gtk_rekey_work(struct work_struct *work); - -int wusbhc_sec_create(struct wusbhc *wusbhc) -{ - /* - * WQ is singlethread because we need to serialize rekey operations. - * Use a separate workqueue for security operations instead of the - * wusbd workqueue because security operations may need to communicate - * directly with downstream wireless devices using synchronous URBs. - * If a device is not responding, this could block other host - * controller operations. - */ - wusbhc->wq_security = create_singlethread_workqueue("wusbd_security"); - if (wusbhc->wq_security == NULL) { - pr_err("WUSB-core: Cannot create wusbd_security workqueue\n"); - return -ENOMEM; - } - - wusbhc->gtk.descr.bLength = sizeof(wusbhc->gtk.descr) + - sizeof(wusbhc->gtk.data); - wusbhc->gtk.descr.bDescriptorType = USB_DT_KEY; - wusbhc->gtk.descr.bReserved = 0; - wusbhc->gtk_index = 0; - - INIT_WORK(&wusbhc->gtk_rekey_work, wusbhc_gtk_rekey_work); - - return 0; -} - - -/* Called when the HC is destroyed */ -void wusbhc_sec_destroy(struct wusbhc *wusbhc) -{ - destroy_workqueue(wusbhc->wq_security); -} - - -/** - * wusbhc_next_tkid - generate a new, currently unused, TKID - * @wusbhc: the WUSB host controller - * @wusb_dev: the device whose PTK the TKID is for - * (or NULL for a TKID for a GTK) - * - * The generated TKID consists of two parts: the device's authenticated - * address (or 0 or a GTK); and an incrementing number. This ensures - * that TKIDs cannot be shared between devices and by the time the - * incrementing number wraps around the older TKIDs will no longer be - * in use (a maximum of two keys may be active at any one time). - */ -static u32 wusbhc_next_tkid(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - u32 *tkid; - u32 addr; - - if (wusb_dev == NULL) { - tkid = &wusbhc->gtk_tkid; - addr = 0; - } else { - tkid = &wusb_port_by_idx(wusbhc, wusb_dev->port_idx)->ptk_tkid; - addr = wusb_dev->addr & 0x7f; - } - - *tkid = (addr << 8) | ((*tkid + 1) & 0xff); - - return *tkid; -} - -static void wusbhc_generate_gtk(struct wusbhc *wusbhc) -{ - const size_t key_size = sizeof(wusbhc->gtk.data); - u32 tkid; - - tkid = wusbhc_next_tkid(wusbhc, NULL); - - wusbhc->gtk.descr.tTKID[0] = (tkid >> 0) & 0xff; - wusbhc->gtk.descr.tTKID[1] = (tkid >> 8) & 0xff; - wusbhc->gtk.descr.tTKID[2] = (tkid >> 16) & 0xff; - - get_random_bytes(wusbhc->gtk.descr.bKeyData, key_size); -} - -/** - * wusbhc_sec_start - start the security management process - * @wusbhc: the WUSB host controller - * - * Generate and set an initial GTK on the host controller. - * - * Called when the HC is started. - */ -int wusbhc_sec_start(struct wusbhc *wusbhc) -{ - const size_t key_size = sizeof(wusbhc->gtk.data); - int result; - - wusbhc_generate_gtk(wusbhc); - - result = wusbhc->set_gtk(wusbhc, wusbhc->gtk_tkid, - &wusbhc->gtk.descr.bKeyData, key_size); - if (result < 0) - dev_err(wusbhc->dev, "cannot set GTK for the host: %d\n", - result); - - return result; -} - -/** - * wusbhc_sec_stop - stop the security management process - * @wusbhc: the WUSB host controller - * - * Wait for any pending GTK rekeys to stop. - */ -void wusbhc_sec_stop(struct wusbhc *wusbhc) -{ - cancel_work_sync(&wusbhc->gtk_rekey_work); -} - - -/** @returns encryption type name */ -const char *wusb_et_name(u8 x) -{ - switch (x) { - case USB_ENC_TYPE_UNSECURE: return "unsecure"; - case USB_ENC_TYPE_WIRED: return "wired"; - case USB_ENC_TYPE_CCM_1: return "CCM-1"; - case USB_ENC_TYPE_RSA_1: return "RSA-1"; - default: return "unknown"; - } -} -EXPORT_SYMBOL_GPL(wusb_et_name); - -/* - * Set the device encryption method - * - * We tell the device which encryption method to use; we do this when - * setting up the device's security. - */ -static int wusb_dev_set_encryption(struct usb_device *usb_dev, int value) -{ - int result; - struct device *dev = &usb_dev->dev; - struct wusb_dev *wusb_dev = usb_dev->wusb_dev; - - if (value) { - value = wusb_dev->ccm1_etd.bEncryptionValue; - } else { - /* FIXME: should be wusb_dev->etd[UNSECURE].bEncryptionValue */ - value = 0; - } - /* Set device's */ - result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_ENCRYPTION, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - value, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) - dev_err(dev, "Can't set device's WUSB encryption to " - "%s (value %d): %d\n", - wusb_et_name(wusb_dev->ccm1_etd.bEncryptionType), - wusb_dev->ccm1_etd.bEncryptionValue, result); - return result; -} - -/* - * Set the GTK to be used by a device. - * - * The device must be authenticated. - */ -static int wusb_dev_set_gtk(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - struct usb_device *usb_dev = wusb_dev->usb_dev; - u8 key_index = wusb_key_index(wusbhc->gtk_index, - WUSB_KEY_INDEX_TYPE_GTK, WUSB_KEY_INDEX_ORIGINATOR_HOST); - - return usb_control_msg( - usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_DESCRIPTOR, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - USB_DT_KEY << 8 | key_index, 0, - &wusbhc->gtk.descr, wusbhc->gtk.descr.bLength, - USB_CTRL_SET_TIMEOUT); -} - - -/* FIXME: prototype for adding security */ -int wusb_dev_sec_add(struct wusbhc *wusbhc, - struct usb_device *usb_dev, struct wusb_dev *wusb_dev) -{ - int result, bytes, secd_size; - struct device *dev = &usb_dev->dev; - struct usb_security_descriptor *secd, *new_secd; - const struct usb_encryption_descriptor *etd, *ccm1_etd = NULL; - const void *itr, *top; - char buf[64]; - - secd = kmalloc(sizeof(*secd), GFP_KERNEL); - if (secd == NULL) { - result = -ENOMEM; - goto out; - } - - result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, - 0, secd, sizeof(*secd)); - if (result < (int)sizeof(*secd)) { - dev_err(dev, "Can't read security descriptor or " - "not enough data: %d\n", result); - goto out; - } - secd_size = le16_to_cpu(secd->wTotalLength); - new_secd = krealloc(secd, secd_size, GFP_KERNEL); - if (new_secd == NULL) { - dev_err(dev, - "Can't allocate space for security descriptors\n"); - result = -ENOMEM; - goto out; - } - secd = new_secd; - result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, - 0, secd, secd_size); - if (result < secd_size) { - dev_err(dev, "Can't read security descriptor or " - "not enough data: %d\n", result); - goto out; - } - bytes = 0; - itr = &secd[1]; - top = (void *)secd + result; - while (itr < top) { - etd = itr; - if (top - itr < sizeof(*etd)) { - dev_err(dev, "BUG: bad device security descriptor; " - "not enough data (%zu vs %zu bytes left)\n", - top - itr, sizeof(*etd)); - break; - } - if (etd->bLength < sizeof(*etd)) { - dev_err(dev, "BUG: bad device encryption descriptor; " - "descriptor is too short " - "(%u vs %zu needed)\n", - etd->bLength, sizeof(*etd)); - break; - } - itr += etd->bLength; - bytes += snprintf(buf + bytes, sizeof(buf) - bytes, - "%s (0x%02x/%02x) ", - wusb_et_name(etd->bEncryptionType), - etd->bEncryptionValue, etd->bAuthKeyIndex); - if (etd->bEncryptionType == USB_ENC_TYPE_CCM_1) - ccm1_etd = etd; - } - /* This code only supports CCM1 as of now. */ - /* FIXME: user has to choose which sec mode to use? - * In theory we want CCM */ - if (ccm1_etd == NULL) { - dev_err(dev, "WUSB device doesn't support CCM1 encryption, " - "can't use!\n"); - result = -EINVAL; - goto out; - } - wusb_dev->ccm1_etd = *ccm1_etd; - dev_dbg(dev, "supported encryption: %s; using %s (0x%02x/%02x)\n", - buf, wusb_et_name(ccm1_etd->bEncryptionType), - ccm1_etd->bEncryptionValue, ccm1_etd->bAuthKeyIndex); - result = 0; -out: - kfree(secd); - return result; -} - -void wusb_dev_sec_rm(struct wusb_dev *wusb_dev) -{ - /* Nothing so far */ -} - -/** - * Update the address of an unauthenticated WUSB device - * - * Once we have successfully authenticated, we take it to addr0 state - * and then to a normal address. - * - * Before the device's address (as known by it) was usb_dev->devnum | - * 0x80 (unauthenticated address). With this we update it to usb_dev->devnum. - */ -int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev) -{ - int result = -ENOMEM; - struct usb_device *usb_dev = wusb_dev->usb_dev; - struct device *dev = &usb_dev->dev; - u8 new_address = wusb_dev->addr & 0x7F; - - /* Set address 0 */ - result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_ADDRESS, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "auth failed: can't set address 0: %d\n", - result); - goto error_addr0; - } - result = wusb_set_dev_addr(wusbhc, wusb_dev, 0); - if (result < 0) - goto error_addr0; - usb_set_device_state(usb_dev, USB_STATE_DEFAULT); - usb_ep0_reinit(usb_dev); - - /* Set new (authenticated) address. */ - result = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_ADDRESS, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - new_address, 0, NULL, 0, - USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "auth failed: can't set address %u: %d\n", - new_address, result); - goto error_addr; - } - result = wusb_set_dev_addr(wusbhc, wusb_dev, new_address); - if (result < 0) - goto error_addr; - usb_set_device_state(usb_dev, USB_STATE_ADDRESS); - usb_ep0_reinit(usb_dev); - usb_dev->authenticated = 1; -error_addr: -error_addr0: - return result; -} - -/* - * - * - */ -/* FIXME: split and cleanup */ -int wusb_dev_4way_handshake(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, - struct wusb_ckhdid *ck) -{ - int result = -ENOMEM; - struct usb_device *usb_dev = wusb_dev->usb_dev; - struct device *dev = &usb_dev->dev; - u32 tkid; - struct usb_handshake *hs; - struct aes_ccm_nonce ccm_n; - u8 mic[8]; - struct wusb_keydvt_in keydvt_in; - struct wusb_keydvt_out keydvt_out; - - hs = kcalloc(3, sizeof(hs[0]), GFP_KERNEL); - if (!hs) - goto error_kzalloc; - - /* We need to turn encryption before beginning the 4way - * hshake (WUSB1.0[.3.2.2]) */ - result = wusb_dev_set_encryption(usb_dev, 1); - if (result < 0) - goto error_dev_set_encryption; - - tkid = wusbhc_next_tkid(wusbhc, wusb_dev); - - hs[0].bMessageNumber = 1; - hs[0].bStatus = 0; - put_unaligned_le32(tkid, hs[0].tTKID); - hs[0].bReserved = 0; - memcpy(hs[0].CDID, &wusb_dev->cdid, sizeof(hs[0].CDID)); - get_random_bytes(&hs[0].nonce, sizeof(hs[0].nonce)); - memset(hs[0].MIC, 0, sizeof(hs[0].MIC)); /* Per WUSB1.0[T7-22] */ - - result = usb_control_msg( - usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_HANDSHAKE, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - 1, 0, &hs[0], sizeof(hs[0]), USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Handshake1: request failed: %d\n", result); - goto error_hs1; - } - - /* Handshake 2, from the device -- need to verify fields */ - result = usb_control_msg( - usb_dev, usb_rcvctrlpipe(usb_dev, 0), - USB_REQ_GET_HANDSHAKE, - USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - 2, 0, &hs[1], sizeof(hs[1]), USB_CTRL_GET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Handshake2: request failed: %d\n", result); - goto error_hs2; - } - - result = -EINVAL; - if (hs[1].bMessageNumber != 2) { - dev_err(dev, "Handshake2 failed: bad message number %u\n", - hs[1].bMessageNumber); - goto error_hs2; - } - if (hs[1].bStatus != 0) { - dev_err(dev, "Handshake2 failed: bad status %u\n", - hs[1].bStatus); - goto error_hs2; - } - if (memcmp(hs[0].tTKID, hs[1].tTKID, sizeof(hs[0].tTKID))) { - dev_err(dev, "Handshake2 failed: TKID mismatch " - "(#1 0x%02x%02x%02x vs #2 0x%02x%02x%02x)\n", - hs[0].tTKID[0], hs[0].tTKID[1], hs[0].tTKID[2], - hs[1].tTKID[0], hs[1].tTKID[1], hs[1].tTKID[2]); - goto error_hs2; - } - if (memcmp(hs[0].CDID, hs[1].CDID, sizeof(hs[0].CDID))) { - dev_err(dev, "Handshake2 failed: CDID mismatch\n"); - goto error_hs2; - } - - /* Setup the CCM nonce */ - memset(&ccm_n.sfn, 0, sizeof(ccm_n.sfn)); /* Per WUSB1.0[6.5.2] */ - put_unaligned_le32(tkid, ccm_n.tkid); - ccm_n.src_addr = wusbhc->uwb_rc->uwb_dev.dev_addr; - ccm_n.dest_addr.data[0] = wusb_dev->addr; - ccm_n.dest_addr.data[1] = 0; - - /* Derive the KCK and PTK from CK, the CCM, H and D nonces */ - memcpy(keydvt_in.hnonce, hs[0].nonce, sizeof(keydvt_in.hnonce)); - memcpy(keydvt_in.dnonce, hs[1].nonce, sizeof(keydvt_in.dnonce)); - result = wusb_key_derive(&keydvt_out, ck->data, &ccm_n, &keydvt_in); - if (result < 0) { - dev_err(dev, "Handshake2 failed: cannot derive keys: %d\n", - result); - goto error_hs2; - } - - /* Compute MIC and verify it */ - result = wusb_oob_mic(mic, keydvt_out.kck, &ccm_n, &hs[1]); - if (result < 0) { - dev_err(dev, "Handshake2 failed: cannot compute MIC: %d\n", - result); - goto error_hs2; - } - - if (memcmp(hs[1].MIC, mic, sizeof(hs[1].MIC))) { - dev_err(dev, "Handshake2 failed: MIC mismatch\n"); - goto error_hs2; - } - - /* Send Handshake3 */ - hs[2].bMessageNumber = 3; - hs[2].bStatus = 0; - put_unaligned_le32(tkid, hs[2].tTKID); - hs[2].bReserved = 0; - memcpy(hs[2].CDID, &wusb_dev->cdid, sizeof(hs[2].CDID)); - memcpy(hs[2].nonce, hs[0].nonce, sizeof(hs[2].nonce)); - result = wusb_oob_mic(hs[2].MIC, keydvt_out.kck, &ccm_n, &hs[2]); - if (result < 0) { - dev_err(dev, "Handshake3 failed: cannot compute MIC: %d\n", - result); - goto error_hs2; - } - - result = usb_control_msg( - usb_dev, usb_sndctrlpipe(usb_dev, 0), - USB_REQ_SET_HANDSHAKE, - USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE, - 3, 0, &hs[2], sizeof(hs[2]), USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "Handshake3: request failed: %d\n", result); - goto error_hs3; - } - - result = wusbhc->set_ptk(wusbhc, wusb_dev->port_idx, tkid, - keydvt_out.ptk, sizeof(keydvt_out.ptk)); - if (result < 0) - goto error_wusbhc_set_ptk; - - result = wusb_dev_set_gtk(wusbhc, wusb_dev); - if (result < 0) { - dev_err(dev, "Set GTK for device: request failed: %d\n", - result); - goto error_wusbhc_set_gtk; - } - - /* Update the device's address from unauth to auth */ - if (usb_dev->authenticated == 0) { - result = wusb_dev_update_address(wusbhc, wusb_dev); - if (result < 0) - goto error_dev_update_address; - } - result = 0; - dev_info(dev, "device authenticated\n"); - -error_dev_update_address: -error_wusbhc_set_gtk: -error_wusbhc_set_ptk: -error_hs3: -error_hs2: -error_hs1: - memset(hs, 0, 3*sizeof(hs[0])); - memzero_explicit(&keydvt_out, sizeof(keydvt_out)); - memzero_explicit(&keydvt_in, sizeof(keydvt_in)); - memzero_explicit(&ccm_n, sizeof(ccm_n)); - memzero_explicit(mic, sizeof(mic)); - if (result < 0) - wusb_dev_set_encryption(usb_dev, 0); -error_dev_set_encryption: - kfree(hs); -error_kzalloc: - return result; -} - -/* - * Once all connected and authenticated devices have received the new - * GTK, switch the host to using it. - */ -static void wusbhc_gtk_rekey_work(struct work_struct *work) -{ - struct wusbhc *wusbhc = container_of(work, - struct wusbhc, gtk_rekey_work); - size_t key_size = sizeof(wusbhc->gtk.data); - int port_idx; - struct wusb_dev *wusb_dev, *wusb_dev_next; - LIST_HEAD(rekey_list); - - mutex_lock(&wusbhc->mutex); - /* generate the new key */ - wusbhc_generate_gtk(wusbhc); - /* roll the gtk index. */ - wusbhc->gtk_index = (wusbhc->gtk_index + 1) % (WUSB_KEY_INDEX_MAX + 1); - /* - * Save all connected devices on a list while holding wusbhc->mutex and - * take a reference to each one. Then submit the set key request to - * them after releasing the lock in order to avoid a deadlock. - */ - for (port_idx = 0; port_idx < wusbhc->ports_max; port_idx++) { - wusb_dev = wusbhc->port[port_idx].wusb_dev; - if (!wusb_dev || !wusb_dev->usb_dev - || !wusb_dev->usb_dev->authenticated) - continue; - - wusb_dev_get(wusb_dev); - list_add_tail(&wusb_dev->rekey_node, &rekey_list); - } - mutex_unlock(&wusbhc->mutex); - - /* Submit the rekey requests without holding wusbhc->mutex. */ - list_for_each_entry_safe(wusb_dev, wusb_dev_next, &rekey_list, - rekey_node) { - list_del_init(&wusb_dev->rekey_node); - dev_dbg(&wusb_dev->usb_dev->dev, - "%s: rekey device at port %d\n", - __func__, wusb_dev->port_idx); - - if (wusb_dev_set_gtk(wusbhc, wusb_dev) < 0) { - dev_err(&wusb_dev->usb_dev->dev, - "%s: rekey device at port %d failed\n", - __func__, wusb_dev->port_idx); - } - wusb_dev_put(wusb_dev); - } - - /* Switch the host controller to use the new GTK. */ - mutex_lock(&wusbhc->mutex); - wusbhc->set_gtk(wusbhc, wusbhc->gtk_tkid, - &wusbhc->gtk.descr.bKeyData, key_size); - mutex_unlock(&wusbhc->mutex); -} - -/** - * wusbhc_gtk_rekey - generate and distribute a new GTK - * @wusbhc: the WUSB host controller - * - * Generate a new GTK and distribute it to all connected and - * authenticated devices. When all devices have the new GTK, the host - * starts using it. - * - * This must be called after every device disconnect (see [WUSB] - * section 6.2.11.2). - */ -void wusbhc_gtk_rekey(struct wusbhc *wusbhc) -{ - /* - * We need to submit a URB to the downstream WUSB devices in order to - * change the group key. This can't be done while holding the - * wusbhc->mutex since that is also taken in the urb_enqueue routine - * and will cause a deadlock. Instead, queue a work item to do - * it when the lock is not held - */ - queue_work(wusbhc->wq_security, &wusbhc->gtk_rekey_work); -} diff --git a/drivers/staging/wusbcore/wa-hc.c b/drivers/staging/wusbcore/wa-hc.c deleted file mode 100644 index 6827075fb8a1..000000000000 --- a/drivers/staging/wusbcore/wa-hc.c +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wire Adapter Host Controller Driver - * Common items to HWA and DWA based HCDs - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - */ -#include <linux/slab.h> -#include <linux/module.h> -#include "wusbhc.h" -#include "wa-hc.h" - -/** - * Assumes - * - * wa->usb_dev and wa->usb_iface initialized and refcounted, - * wa->wa_descr initialized. - */ -int wa_create(struct wahc *wa, struct usb_interface *iface, - kernel_ulong_t quirks) -{ - int result; - struct device *dev = &iface->dev; - - if (iface->cur_altsetting->desc.bNumEndpoints < 3) - return -ENODEV; - - result = wa_rpipes_create(wa); - if (result < 0) - goto error_rpipes_create; - wa->quirks = quirks; - /* Fill up Data Transfer EP pointers */ - wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; - wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; - wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd); - wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL); - if (wa->dti_buf == NULL) { - result = -ENOMEM; - goto error_dti_buf_alloc; - } - result = wa_nep_create(wa, iface); - if (result < 0) { - dev_err(dev, "WA-CDS: can't initialize notif endpoint: %d\n", - result); - goto error_nep_create; - } - return 0; - -error_nep_create: - kfree(wa->dti_buf); -error_dti_buf_alloc: - wa_rpipes_destroy(wa); -error_rpipes_create: - return result; -} -EXPORT_SYMBOL_GPL(wa_create); - - -void __wa_destroy(struct wahc *wa) -{ - if (wa->dti_urb) { - usb_kill_urb(wa->dti_urb); - usb_put_urb(wa->dti_urb); - } - kfree(wa->dti_buf); - wa_nep_destroy(wa); - wa_rpipes_destroy(wa); -} -EXPORT_SYMBOL_GPL(__wa_destroy); - -/** - * wa_reset_all - reset the WA device - * @wa: the WA to be reset - * - * For HWAs the radio controller and all other PALs are also reset. - */ -void wa_reset_all(struct wahc *wa) -{ - /* FIXME: assuming HWA. */ - wusbhc_reset_all(wa->wusb); -} - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Wireless USB Wire Adapter core"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wusbcore/wa-hc.h b/drivers/staging/wusbcore/wa-hc.h deleted file mode 100644 index 5a38465724c2..000000000000 --- a/drivers/staging/wusbcore/wa-hc.h +++ /dev/null @@ -1,467 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * HWA Host Controller Driver - * Wire Adapter Control/Data Streaming Iface (WUSB1.0[8]) - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This driver implements a USB Host Controller (struct usb_hcd) for a - * Wireless USB Host Controller based on the Wireless USB 1.0 - * Host-Wire-Adapter specification (in layman terms, a USB-dongle that - * implements a Wireless USB host). - * - * Check out the Design-overview.txt file in the source documentation - * for other details on the implementation. - * - * Main blocks: - * - * driver glue with the driver API, workqueue daemon - * - * lc RC instance life cycle management (create, destroy...) - * - * hcd glue with the USB API Host Controller Interface API. - * - * nep Notification EndPoint management: collect notifications - * and queue them with the workqueue daemon. - * - * Handle notifications as coming from the NEP. Sends them - * off others to their respective modules (eg: connect, - * disconnect and reset go to devconnect). - * - * rpipe Remote Pipe management; rpipe is what we use to write - * to an endpoint on a WUSB device that is connected to a - * HWA RC. - * - * xfer Transfer management -- this is all the code that gets a - * buffer and pushes it to a device (or viceversa). * - * - * Some day a lot of this code will be shared between this driver and - * the drivers for DWA (xfer, rpipe). - * - * All starts at driver.c:hwahc_probe(), when one of this guys is - * connected. hwahc_disconnect() stops it. - * - * During operation, the main driver is devices connecting or - * disconnecting. They cause the HWA RC to send notifications into - * nep.c:hwahc_nep_cb() that will dispatch them to - * notif.c:wa_notif_dispatch(). From there they will fan to cause - * device connects, disconnects, etc. - * - * Note much of the activity is difficult to follow. For example a - * device connect goes to devconnect, which will cause the "fake" root - * hub port to show a connect and stop there. Then hub_wq will notice - * and call into the rh.c:hwahc_rc_port_reset() code to authenticate - * the device (and this might require user intervention) and enable - * the port. - * - * We also have a timer workqueue going from devconnect.c that - * schedules in hwahc_devconnect_create(). - * - * The rest of the traffic is in the usual entry points of a USB HCD, - * which are hooked up in driver.c:hwahc_rc_driver, and defined in - * hcd.c. - */ - -#ifndef __HWAHC_INTERNAL_H__ -#define __HWAHC_INTERNAL_H__ - -#include <linux/completion.h> -#include <linux/usb.h> -#include <linux/mutex.h> -#include <linux/spinlock.h> -#include "../uwb/uwb.h" -#include "include/wusb.h" -#include "include/wusb-wa.h" - -struct wusbhc; -struct wahc; -extern void wa_urb_enqueue_run(struct work_struct *ws); -extern void wa_process_errored_transfers_run(struct work_struct *ws); - -/** - * RPipe instance - * - * @descr's fields are kept in LE, as we need to send it back and - * forth. - * - * @wa is referenced when set - * - * @segs_available is the number of requests segments that still can - * be submitted to the controller without overloading - * it. It is initialized to descr->wRequests when - * aiming. - * - * A rpipe supports a max of descr->wRequests at the same time; before - * submitting seg_lock has to be taken. If segs_avail > 0, then we can - * submit; if not, we have to queue them. - */ -struct wa_rpipe { - struct kref refcnt; - struct usb_rpipe_descriptor descr; - struct usb_host_endpoint *ep; - struct wahc *wa; - spinlock_t seg_lock; - struct list_head seg_list; - struct list_head list_node; - atomic_t segs_available; - u8 buffer[1]; /* For reads/writes on USB */ -}; - - -enum wa_dti_state { - WA_DTI_TRANSFER_RESULT_PENDING, - WA_DTI_ISOC_PACKET_STATUS_PENDING, - WA_DTI_BUF_IN_DATA_PENDING -}; - -enum wa_quirks { - /* - * The Alereon HWA expects the data frames in isochronous transfer - * requests to be concatenated and not sent as separate packets. - */ - WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC = 0x01, - /* - * The Alereon HWA can be instructed to not send transfer notifications - * as an optimization. - */ - WUSB_QUIRK_ALEREON_HWA_DISABLE_XFER_NOTIFICATIONS = 0x02, -}; - -enum wa_vendor_specific_requests { - WA_REQ_ALEREON_DISABLE_XFER_NOTIFICATIONS = 0x4C, - WA_REQ_ALEREON_FEATURE_SET = 0x01, - WA_REQ_ALEREON_FEATURE_CLEAR = 0x00, -}; - -#define WA_MAX_BUF_IN_URBS 4 -/** - * Instance of a HWA Host Controller - * - * Except where a more specific lock/mutex applies or atomic, all - * fields protected by @mutex. - * - * @wa_descr Can be accessed without locking because it is in - * the same area where the device descriptors were - * read, so it is guaranteed to exist unmodified while - * the device exists. - * - * Endianess has been converted to CPU's. - * - * @nep_* can be accessed without locking as its processing is - * serialized; we submit a NEP URB and it comes to - * hwahc_nep_cb(), which won't issue another URB until it is - * done processing it. - * - * @xfer_list: - * - * List of active transfers to verify existence from a xfer id - * gotten from the xfer result message. Can't use urb->list because - * it goes by endpoint, and we don't know the endpoint at the time - * when we get the xfer result message. We can't really rely on the - * pointer (will have to change for 64 bits) as the xfer id is 32 bits. - * - * @xfer_delayed_list: List of transfers that need to be started - * (with a workqueue, because they were - * submitted from an atomic context). - * - * FIXME: this needs to be layered up: a wusbhc layer (for sharing - * commonalities with WHCI), a wa layer (for sharing - * commonalities with DWA-RC). - */ -struct wahc { - struct usb_device *usb_dev; - struct usb_interface *usb_iface; - - /* HC to deliver notifications */ - union { - struct wusbhc *wusb; - struct dwahc *dwa; - }; - - const struct usb_endpoint_descriptor *dto_epd, *dti_epd; - const struct usb_wa_descriptor *wa_descr; - - struct urb *nep_urb; /* Notification EndPoint [lockless] */ - struct edc nep_edc; - void *nep_buffer; - size_t nep_buffer_size; - - atomic_t notifs_queued; - - u16 rpipes; - unsigned long *rpipe_bm; /* rpipe usage bitmap */ - struct list_head rpipe_delayed_list; /* delayed RPIPES. */ - spinlock_t rpipe_lock; /* protect rpipe_bm and delayed list */ - struct mutex rpipe_mutex; /* assigning resources to endpoints */ - - /* - * dti_state is used to track the state of the dti_urb. When dti_state - * is WA_DTI_ISOC_PACKET_STATUS_PENDING, dti_isoc_xfer_in_progress and - * dti_isoc_xfer_seg identify which xfer the incoming isoc packet - * status refers to. - */ - enum wa_dti_state dti_state; - u32 dti_isoc_xfer_in_progress; - u8 dti_isoc_xfer_seg; - struct urb *dti_urb; /* URB for reading xfer results */ - /* URBs for reading data in */ - struct urb buf_in_urbs[WA_MAX_BUF_IN_URBS]; - int active_buf_in_urbs; /* number of buf_in_urbs active. */ - struct edc dti_edc; /* DTI error density counter */ - void *dti_buf; - size_t dti_buf_size; - - unsigned long dto_in_use; /* protect dto endoint serialization */ - - s32 status; /* For reading status */ - - struct list_head xfer_list; - struct list_head xfer_delayed_list; - struct list_head xfer_errored_list; - /* - * lock for the above xfer lists. Can be taken while a xfer->lock is - * held but not in the reverse order. - */ - spinlock_t xfer_list_lock; - struct work_struct xfer_enqueue_work; - struct work_struct xfer_error_work; - atomic_t xfer_id_count; - - kernel_ulong_t quirks; -}; - - -extern int wa_create(struct wahc *wa, struct usb_interface *iface, - kernel_ulong_t); -extern void __wa_destroy(struct wahc *wa); -extern int wa_dti_start(struct wahc *wa); -void wa_reset_all(struct wahc *wa); - - -/* Miscellaneous constants */ -enum { - /** Max number of EPROTO errors we tolerate on the NEP in a - * period of time */ - HWAHC_EPROTO_MAX = 16, - /** Period of time for EPROTO errors (in jiffies) */ - HWAHC_EPROTO_PERIOD = 4 * HZ, -}; - - -/* Notification endpoint handling */ -extern int wa_nep_create(struct wahc *, struct usb_interface *); -extern void wa_nep_destroy(struct wahc *); - -static inline int wa_nep_arm(struct wahc *wa, gfp_t gfp_mask) -{ - struct urb *urb = wa->nep_urb; - urb->transfer_buffer = wa->nep_buffer; - urb->transfer_buffer_length = wa->nep_buffer_size; - return usb_submit_urb(urb, gfp_mask); -} - -static inline void wa_nep_disarm(struct wahc *wa) -{ - usb_kill_urb(wa->nep_urb); -} - - -/* RPipes */ -static inline void wa_rpipe_init(struct wahc *wa) -{ - INIT_LIST_HEAD(&wa->rpipe_delayed_list); - spin_lock_init(&wa->rpipe_lock); - mutex_init(&wa->rpipe_mutex); -} - -static inline void wa_init(struct wahc *wa) -{ - int index; - - edc_init(&wa->nep_edc); - atomic_set(&wa->notifs_queued, 0); - wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING; - wa_rpipe_init(wa); - edc_init(&wa->dti_edc); - INIT_LIST_HEAD(&wa->xfer_list); - INIT_LIST_HEAD(&wa->xfer_delayed_list); - INIT_LIST_HEAD(&wa->xfer_errored_list); - spin_lock_init(&wa->xfer_list_lock); - INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run); - INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run); - wa->dto_in_use = 0; - atomic_set(&wa->xfer_id_count, 1); - /* init the buf in URBs */ - for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index) - usb_init_urb(&(wa->buf_in_urbs[index])); - wa->active_buf_in_urbs = 0; -} - -/** - * Destroy a pipe (when refcount drops to zero) - * - * Assumes it has been moved to the "QUIESCING" state. - */ -struct wa_xfer; -extern void rpipe_destroy(struct kref *_rpipe); -static inline -void __rpipe_get(struct wa_rpipe *rpipe) -{ - kref_get(&rpipe->refcnt); -} -extern int rpipe_get_by_ep(struct wahc *, struct usb_host_endpoint *, - struct urb *, gfp_t); -static inline void rpipe_put(struct wa_rpipe *rpipe) -{ - kref_put(&rpipe->refcnt, rpipe_destroy); - -} -extern void rpipe_ep_disable(struct wahc *, struct usb_host_endpoint *); -extern void rpipe_clear_feature_stalled(struct wahc *, - struct usb_host_endpoint *); -extern int wa_rpipes_create(struct wahc *); -extern void wa_rpipes_destroy(struct wahc *); -static inline void rpipe_avail_dec(struct wa_rpipe *rpipe) -{ - atomic_dec(&rpipe->segs_available); -} - -/** - * Returns true if the rpipe is ready to submit more segments. - */ -static inline int rpipe_avail_inc(struct wa_rpipe *rpipe) -{ - return atomic_inc_return(&rpipe->segs_available) > 0 - && !list_empty(&rpipe->seg_list); -} - - -/* Transferring data */ -extern int wa_urb_enqueue(struct wahc *, struct usb_host_endpoint *, - struct urb *, gfp_t); -extern int wa_urb_dequeue(struct wahc *, struct urb *, int); -extern void wa_handle_notif_xfer(struct wahc *, struct wa_notif_hdr *); - - -/* Misc - * - * FIXME: Refcounting for the actual @hwahc object is not correct; I - * mean, this should be refcounting on the HCD underneath, but - * it is not. In any case, the semantics for HCD refcounting - * are *weird*...on refcount reaching zero it just frees - * it...no RC specific function is called...unless I miss - * something. - * - * FIXME: has to go away in favour of a 'struct' hcd based solution - */ -static inline struct wahc *wa_get(struct wahc *wa) -{ - usb_get_intf(wa->usb_iface); - return wa; -} - -static inline void wa_put(struct wahc *wa) -{ - usb_put_intf(wa->usb_iface); -} - - -static inline int __wa_feature(struct wahc *wa, unsigned op, u16 feature) -{ - return usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - op ? USB_REQ_SET_FEATURE : USB_REQ_CLEAR_FEATURE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - feature, - wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - NULL, 0, USB_CTRL_SET_TIMEOUT); -} - - -static inline int __wa_set_feature(struct wahc *wa, u16 feature) -{ - return __wa_feature(wa, 1, feature); -} - - -static inline int __wa_clear_feature(struct wahc *wa, u16 feature) -{ - return __wa_feature(wa, 0, feature); -} - - -/** - * Return the status of a Wire Adapter - * - * @wa: Wire Adapter instance - * @returns < 0 errno code on error, or status bitmap as described - * in WUSB1.0[8.3.1.6]. - * - * NOTE: need malloc, some arches don't take USB from the stack - */ -static inline -s32 __wa_get_status(struct wahc *wa) -{ - s32 result; - result = usb_control_msg( - wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), - USB_REQ_GET_STATUS, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber, - &wa->status, sizeof(wa->status), USB_CTRL_GET_TIMEOUT); - if (result >= 0) - result = wa->status; - return result; -} - - -/** - * Waits until the Wire Adapter's status matches @mask/@value - * - * @wa: Wire Adapter instance. - * @returns < 0 errno code on error, otherwise status. - * - * Loop until the WAs status matches the mask and value (status & mask - * == value). Timeout if it doesn't happen. - * - * FIXME: is there an official specification on how long status - * changes can take? - */ -static inline s32 __wa_wait_status(struct wahc *wa, u32 mask, u32 value) -{ - s32 result; - unsigned loops = 10; - do { - msleep(50); - result = __wa_get_status(wa); - if ((result & mask) == value) - break; - if (loops-- == 0) { - result = -ETIMEDOUT; - break; - } - } while (result >= 0); - return result; -} - - -/** Command @hwahc to stop, @returns 0 if ok, < 0 errno code on error */ -static inline int __wa_stop(struct wahc *wa) -{ - int result; - struct device *dev = &wa->usb_iface->dev; - - result = __wa_clear_feature(wa, WA_ENABLE); - if (result < 0 && result != -ENODEV) { - dev_err(dev, "error commanding HC to stop: %d\n", result); - goto out; - } - result = __wa_wait_status(wa, WA_ENABLE, 0); - if (result < 0 && result != -ENODEV) - dev_err(dev, "error waiting for HC to stop: %d\n", result); -out: - return 0; -} - - -#endif /* #ifndef __HWAHC_INTERNAL_H__ */ diff --git a/drivers/staging/wusbcore/wa-nep.c b/drivers/staging/wusbcore/wa-nep.c deleted file mode 100644 index 5f0656db5482..000000000000 --- a/drivers/staging/wusbcore/wa-nep.c +++ /dev/null @@ -1,289 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB Wire Adapter: Control/Data Streaming Interface (WUSB[8]) - * Notification EndPoint support - * - * Copyright (C) 2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This part takes care of getting the notification from the hw - * only and dispatching through wusbwad into - * wa_notif_dispatch. Handling is done there. - * - * WA notifications are limited in size; most of them are three or - * four bytes long, and the longest is the HWA Device Notification, - * which would not exceed 38 bytes (DNs are limited in payload to 32 - * bytes plus 3 bytes header (WUSB1.0[7.6p2]), plus 3 bytes HWA - * header (WUSB1.0[8.5.4.2]). - * - * It is not clear if more than one Device Notification can be packed - * in a HWA Notification, I assume no because of the wording in - * WUSB1.0[8.5.4.2]. In any case, the bigger any notification could - * get is 256 bytes (as the bLength field is a byte). - * - * So what we do is we have this buffer and read into it; when a - * notification arrives we schedule work to a specific, single thread - * workqueue (so notifications are serialized) and copy the - * notification data. After scheduling the work, we rearm the read from - * the notification endpoint. - * - * Entry points here are: - * - * wa_nep_[create|destroy]() To initialize/release this subsystem - * - * wa_nep_cb() Callback for the notification - * endpoint; when data is ready, this - * does the dispatching. - */ -#include <linux/workqueue.h> -#include <linux/ctype.h> -#include <linux/slab.h> - -#include "wa-hc.h" -#include "wusbhc.h" - -/* Structure for queueing notifications to the workqueue */ -struct wa_notif_work { - struct work_struct work; - struct wahc *wa; - size_t size; - u8 data[]; -}; - -/* - * Process incoming notifications from the WA's Notification EndPoint - * [the wuswad daemon, basically] - * - * @_nw: Pointer to a descriptor which has the pointer to the - * @wa, the size of the buffer and the work queue - * structure (so we can free all when done). - * @returns 0 if ok, < 0 errno code on error. - * - * All notifications follow the same format; they need to start with a - * 'struct wa_notif_hdr' header, so it is easy to parse through - * them. We just break the buffer in individual notifications (the - * standard doesn't say if it can be done or is forbidden, so we are - * cautious) and dispatch each. - * - * So the handling layers are is: - * - * WA specific notification (from NEP) - * Device Notification Received -> wa_handle_notif_dn() - * WUSB Device notification generic handling - * BPST Adjustment -> wa_handle_notif_bpst_adj() - * ... -> ... - * - * @wa has to be referenced - */ -static void wa_notif_dispatch(struct work_struct *ws) -{ - void *itr; - u8 missing = 0; - struct wa_notif_work *nw = container_of(ws, struct wa_notif_work, - work); - struct wahc *wa = nw->wa; - struct wa_notif_hdr *notif_hdr; - size_t size; - - struct device *dev = &wa->usb_iface->dev; - -#if 0 - /* FIXME: need to check for this??? */ - if (usb_hcd->state == HC_STATE_QUIESCING) /* Going down? */ - goto out; /* screw it */ -#endif - atomic_dec(&wa->notifs_queued); /* Throttling ctl */ - size = nw->size; - itr = nw->data; - - while (size) { - if (size < sizeof(*notif_hdr)) { - missing = sizeof(*notif_hdr) - size; - goto exhausted_buffer; - } - notif_hdr = itr; - if (size < notif_hdr->bLength) - goto exhausted_buffer; - itr += notif_hdr->bLength; - size -= notif_hdr->bLength; - /* Dispatch the notification [don't use itr or size!] */ - switch (notif_hdr->bNotifyType) { - case HWA_NOTIF_DN: { - struct hwa_notif_dn *hwa_dn; - hwa_dn = container_of(notif_hdr, struct hwa_notif_dn, - hdr); - wusbhc_handle_dn(wa->wusb, hwa_dn->bSourceDeviceAddr, - hwa_dn->dndata, - notif_hdr->bLength - sizeof(*hwa_dn)); - break; - } - case WA_NOTIF_TRANSFER: - wa_handle_notif_xfer(wa, notif_hdr); - break; - case HWA_NOTIF_BPST_ADJ: - break; /* no action needed for BPST ADJ. */ - case DWA_NOTIF_RWAKE: - case DWA_NOTIF_PORTSTATUS: - /* FIXME: unimplemented WA NOTIFs */ - /* fallthru */ - default: - dev_err(dev, "HWA: unknown notification 0x%x, " - "%zu bytes; discarding\n", - notif_hdr->bNotifyType, - (size_t)notif_hdr->bLength); - break; - } - } -out: - wa_put(wa); - kfree(nw); - return; - - /* THIS SHOULD NOT HAPPEN - * - * Buffer exahusted with partial data remaining; just warn and - * discard the data, as this should not happen. - */ -exhausted_buffer: - dev_warn(dev, "HWA: device sent short notification, " - "%d bytes missing; discarding %d bytes.\n", - missing, (int)size); - goto out; -} - -/* - * Deliver incoming WA notifications to the wusbwa workqueue - * - * @wa: Pointer the Wire Adapter Controller Data Streaming - * instance (part of an 'struct usb_hcd'). - * @size: Size of the received buffer - * @returns 0 if ok, < 0 errno code on error. - * - * The input buffer is @wa->nep_buffer, with @size bytes - * (guaranteed to fit in the allocated space, - * @wa->nep_buffer_size). - */ -static int wa_nep_queue(struct wahc *wa, size_t size) -{ - int result = 0; - struct device *dev = &wa->usb_iface->dev; - struct wa_notif_work *nw; - - /* dev_fnstart(dev, "(wa %p, size %zu)\n", wa, size); */ - BUG_ON(size > wa->nep_buffer_size); - if (size == 0) - goto out; - if (atomic_read(&wa->notifs_queued) > 200) { - if (printk_ratelimit()) - dev_err(dev, "Too many notifications queued, " - "throttling back\n"); - goto out; - } - nw = kzalloc(sizeof(*nw) + size, GFP_ATOMIC); - if (nw == NULL) { - if (printk_ratelimit()) - dev_err(dev, "No memory to queue notification\n"); - result = -ENOMEM; - goto out; - } - INIT_WORK(&nw->work, wa_notif_dispatch); - nw->wa = wa_get(wa); - nw->size = size; - memcpy(nw->data, wa->nep_buffer, size); - atomic_inc(&wa->notifs_queued); /* Throttling ctl */ - queue_work(wusbd, &nw->work); -out: - /* dev_fnend(dev, "(wa %p, size %zu) = result\n", wa, size, result); */ - return result; -} - -/* - * Callback for the notification event endpoint - * - * Check's that everything is fine and then passes the data to be - * queued to the workqueue. - */ -static void wa_nep_cb(struct urb *urb) -{ - int result; - struct wahc *wa = urb->context; - struct device *dev = &wa->usb_iface->dev; - - switch (result = urb->status) { - case 0: - result = wa_nep_queue(wa, urb->actual_length); - if (result < 0) - dev_err(dev, "NEP: unable to process notification(s): " - "%d\n", result); - break; - case -ECONNRESET: /* Not an error, but a controlled situation; */ - case -ENOENT: /* (we killed the URB)...so, no broadcast */ - case -ESHUTDOWN: - dev_dbg(dev, "NEP: going down %d\n", urb->status); - goto out; - default: /* On general errors, we retry unless it gets ugly */ - if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)) { - dev_err(dev, "NEP: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - goto out; - } - dev_err(dev, "NEP: URB error %d\n", urb->status); - } - result = wa_nep_arm(wa, GFP_ATOMIC); - if (result < 0) { - dev_err(dev, "NEP: cannot submit URB: %d\n", result); - wa_reset_all(wa); - } -out: - return; -} - -/* - * Initialize @wa's notification and event's endpoint stuff - * - * This includes the allocating the read buffer, the context ID - * allocation bitmap, the URB and submitting the URB. - */ -int wa_nep_create(struct wahc *wa, struct usb_interface *iface) -{ - int result; - struct usb_endpoint_descriptor *epd; - struct usb_device *usb_dev = interface_to_usbdev(iface); - struct device *dev = &iface->dev; - - edc_init(&wa->nep_edc); - epd = &iface->cur_altsetting->endpoint[0].desc; - wa->nep_buffer_size = 1024; - wa->nep_buffer = kmalloc(wa->nep_buffer_size, GFP_KERNEL); - if (!wa->nep_buffer) - goto error_nep_buffer; - wa->nep_urb = usb_alloc_urb(0, GFP_KERNEL); - if (wa->nep_urb == NULL) - goto error_urb_alloc; - usb_fill_int_urb(wa->nep_urb, usb_dev, - usb_rcvintpipe(usb_dev, epd->bEndpointAddress), - wa->nep_buffer, wa->nep_buffer_size, - wa_nep_cb, wa, epd->bInterval); - result = wa_nep_arm(wa, GFP_KERNEL); - if (result < 0) { - dev_err(dev, "Cannot submit notification URB: %d\n", result); - goto error_nep_arm; - } - return 0; - -error_nep_arm: - usb_free_urb(wa->nep_urb); -error_urb_alloc: - kfree(wa->nep_buffer); -error_nep_buffer: - return -ENOMEM; -} - -void wa_nep_destroy(struct wahc *wa) -{ - wa_nep_disarm(wa); - usb_free_urb(wa->nep_urb); - kfree(wa->nep_buffer); -} diff --git a/drivers/staging/wusbcore/wa-rpipe.c b/drivers/staging/wusbcore/wa-rpipe.c deleted file mode 100644 index a5734cbcd5ad..000000000000 --- a/drivers/staging/wusbcore/wa-rpipe.c +++ /dev/null @@ -1,539 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB Wire Adapter - * rpipe management - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * FIXME: docs - * - * RPIPE - * - * Targeted at different downstream endpoints - * - * Descriptor: use to config the remote pipe. - * - * The number of blocks could be dynamic (wBlocks in descriptor is - * 0)--need to schedule them then. - * - * Each bit in wa->rpipe_bm represents if an rpipe is being used or - * not. Rpipes are represented with a 'struct wa_rpipe' that is - * attached to the hcpriv member of a 'struct usb_host_endpoint'. - * - * When you need to xfer data to an endpoint, you get an rpipe for it - * with wa_ep_rpipe_get(), which gives you a reference to the rpipe - * and keeps a single one (the first one) with the endpoint. When you - * are done transferring, you drop that reference. At the end the - * rpipe is always allocated and bound to the endpoint. There it might - * be recycled when not used. - * - * Addresses: - * - * We use a 1:1 mapping mechanism between port address (0 based - * index, actually) and the address. The USB stack knows about this. - * - * USB Stack port number 4 (1 based) - * WUSB code port index 3 (0 based) - * USB Address 5 (2 based -- 0 is for default, 1 for root hub) - * - * Now, because we don't use the concept as default address exactly - * like the (wired) USB code does, we need to kind of skip it. So we - * never take addresses from the urb->pipe, but from the - * urb->dev->devnum, to make sure that we always have the right - * destination address. - */ -#include <linux/atomic.h> -#include <linux/bitmap.h> -#include <linux/slab.h> -#include <linux/export.h> - -#include "wusbhc.h" -#include "wa-hc.h" - -static int __rpipe_get_descr(struct wahc *wa, - struct usb_rpipe_descriptor *descr, u16 index) -{ - ssize_t result; - struct device *dev = &wa->usb_iface->dev; - - /* Get the RPIPE descriptor -- we cannot use the usb_get_descriptor() - * function because the arguments are different. - */ - result = usb_control_msg( - wa->usb_dev, usb_rcvctrlpipe(wa->usb_dev, 0), - USB_REQ_GET_DESCRIPTOR, - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_RPIPE, - USB_DT_RPIPE<<8, index, descr, sizeof(*descr), - USB_CTRL_GET_TIMEOUT); - if (result < 0) { - dev_err(dev, "rpipe %u: get descriptor failed: %d\n", - index, (int)result); - goto error; - } - if (result < sizeof(*descr)) { - dev_err(dev, "rpipe %u: got short descriptor " - "(%zd vs %zd bytes needed)\n", - index, result, sizeof(*descr)); - result = -EINVAL; - goto error; - } - result = 0; - -error: - return result; -} - -/* - * - * The descriptor is assumed to be properly initialized (ie: you got - * it through __rpipe_get_descr()). - */ -static int __rpipe_set_descr(struct wahc *wa, - struct usb_rpipe_descriptor *descr, u16 index) -{ - ssize_t result; - struct device *dev = &wa->usb_iface->dev; - - /* we cannot use the usb_get_descriptor() function because the - * arguments are different. - */ - result = usb_control_msg( - wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_SET_DESCRIPTOR, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, - USB_DT_RPIPE<<8, index, descr, sizeof(*descr), - USB_CTRL_SET_TIMEOUT); - if (result < 0) { - dev_err(dev, "rpipe %u: set descriptor failed: %d\n", - index, (int)result); - goto error; - } - if (result < sizeof(*descr)) { - dev_err(dev, "rpipe %u: sent short descriptor " - "(%zd vs %zd bytes required)\n", - index, result, sizeof(*descr)); - result = -EINVAL; - goto error; - } - result = 0; - -error: - return result; - -} - -static void rpipe_init(struct wa_rpipe *rpipe) -{ - kref_init(&rpipe->refcnt); - spin_lock_init(&rpipe->seg_lock); - INIT_LIST_HEAD(&rpipe->seg_list); - INIT_LIST_HEAD(&rpipe->list_node); -} - -static unsigned rpipe_get_idx(struct wahc *wa, unsigned rpipe_idx) -{ - unsigned long flags; - - spin_lock_irqsave(&wa->rpipe_lock, flags); - rpipe_idx = find_next_zero_bit(wa->rpipe_bm, wa->rpipes, rpipe_idx); - if (rpipe_idx < wa->rpipes) - set_bit(rpipe_idx, wa->rpipe_bm); - spin_unlock_irqrestore(&wa->rpipe_lock, flags); - - return rpipe_idx; -} - -static void rpipe_put_idx(struct wahc *wa, unsigned rpipe_idx) -{ - unsigned long flags; - - spin_lock_irqsave(&wa->rpipe_lock, flags); - clear_bit(rpipe_idx, wa->rpipe_bm); - spin_unlock_irqrestore(&wa->rpipe_lock, flags); -} - -void rpipe_destroy(struct kref *_rpipe) -{ - struct wa_rpipe *rpipe = container_of(_rpipe, struct wa_rpipe, refcnt); - u8 index = le16_to_cpu(rpipe->descr.wRPipeIndex); - - if (rpipe->ep) - rpipe->ep->hcpriv = NULL; - rpipe_put_idx(rpipe->wa, index); - wa_put(rpipe->wa); - kfree(rpipe); -} -EXPORT_SYMBOL_GPL(rpipe_destroy); - -/* - * Locate an idle rpipe, create an structure for it and return it - * - * @wa is referenced and unlocked - * @crs enum rpipe_attr, required endpoint characteristics - * - * The rpipe can be used only sequentially (not in parallel). - * - * The rpipe is moved into the "ready" state. - */ -static int rpipe_get_idle(struct wa_rpipe **prpipe, struct wahc *wa, u8 crs, - gfp_t gfp) -{ - int result; - unsigned rpipe_idx; - struct wa_rpipe *rpipe; - struct device *dev = &wa->usb_iface->dev; - - rpipe = kzalloc(sizeof(*rpipe), gfp); - if (rpipe == NULL) - return -ENOMEM; - rpipe_init(rpipe); - - /* Look for an idle pipe */ - for (rpipe_idx = 0; rpipe_idx < wa->rpipes; rpipe_idx++) { - rpipe_idx = rpipe_get_idx(wa, rpipe_idx); - if (rpipe_idx >= wa->rpipes) /* no more pipes :( */ - break; - result = __rpipe_get_descr(wa, &rpipe->descr, rpipe_idx); - if (result < 0) - dev_err(dev, "Can't get descriptor for rpipe %u: %d\n", - rpipe_idx, result); - else if ((rpipe->descr.bmCharacteristics & crs) != 0) - goto found; - rpipe_put_idx(wa, rpipe_idx); - } - *prpipe = NULL; - kfree(rpipe); - return -ENXIO; - -found: - set_bit(rpipe_idx, wa->rpipe_bm); - rpipe->wa = wa_get(wa); - *prpipe = rpipe; - return 0; -} - -static int __rpipe_reset(struct wahc *wa, unsigned index) -{ - int result; - struct device *dev = &wa->usb_iface->dev; - - result = usb_control_msg( - wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_RPIPE_RESET, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, - 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); - if (result < 0) - dev_err(dev, "rpipe %u: reset failed: %d\n", - index, result); - return result; -} - -/* - * Fake companion descriptor for ep0 - * - * See WUSB1.0[7.4.4], most of this is zero for bulk/int/ctl - */ -static struct usb_wireless_ep_comp_descriptor epc0 = { - .bLength = sizeof(epc0), - .bDescriptorType = USB_DT_WIRELESS_ENDPOINT_COMP, - .bMaxBurst = 1, - .bMaxSequence = 2, -}; - -/* - * Look for EP companion descriptor - * - * Get there, look for Inara in the endpoint's extra descriptors - */ -static struct usb_wireless_ep_comp_descriptor *rpipe_epc_find( - struct device *dev, struct usb_host_endpoint *ep) -{ - void *itr; - size_t itr_size; - struct usb_descriptor_header *hdr; - struct usb_wireless_ep_comp_descriptor *epcd; - - if (ep->desc.bEndpointAddress == 0) { - epcd = &epc0; - goto out; - } - itr = ep->extra; - itr_size = ep->extralen; - epcd = NULL; - while (itr_size > 0) { - if (itr_size < sizeof(*hdr)) { - dev_err(dev, "HW Bug? ep 0x%02x: extra descriptors " - "at offset %zu: only %zu bytes left\n", - ep->desc.bEndpointAddress, - itr - (void *) ep->extra, itr_size); - break; - } - hdr = itr; - if (hdr->bDescriptorType == USB_DT_WIRELESS_ENDPOINT_COMP) { - epcd = itr; - break; - } - if (hdr->bLength > itr_size) { - dev_err(dev, "HW Bug? ep 0x%02x: extra descriptor " - "at offset %zu (type 0x%02x) " - "length %d but only %zu bytes left\n", - ep->desc.bEndpointAddress, - itr - (void *) ep->extra, hdr->bDescriptorType, - hdr->bLength, itr_size); - break; - } - itr += hdr->bLength; - itr_size -= hdr->bLength; - } -out: - return epcd; -} - -/* - * Aim an rpipe to its device & endpoint destination - * - * Make sure we change the address to unauthenticated if the device - * is WUSB and it is not authenticated. - */ -static int rpipe_aim(struct wa_rpipe *rpipe, struct wahc *wa, - struct usb_host_endpoint *ep, struct urb *urb, gfp_t gfp) -{ - int result = -ENOMSG; /* better code for lack of companion? */ - struct device *dev = &wa->usb_iface->dev; - struct usb_device *usb_dev = urb->dev; - struct usb_wireless_ep_comp_descriptor *epcd; - u32 ack_window, epcd_max_sequence; - u8 unauth; - - epcd = rpipe_epc_find(dev, ep); - if (epcd == NULL) { - dev_err(dev, "ep 0x%02x: can't find companion descriptor\n", - ep->desc.bEndpointAddress); - goto error; - } - unauth = usb_dev->wusb && !usb_dev->authenticated ? 0x80 : 0; - __rpipe_reset(wa, le16_to_cpu(rpipe->descr.wRPipeIndex)); - atomic_set(&rpipe->segs_available, - le16_to_cpu(rpipe->descr.wRequests)); - /* FIXME: block allocation system; request with queuing and timeout */ - /* FIXME: compute so seg_size > ep->maxpktsize */ - rpipe->descr.wBlocks = cpu_to_le16(16); /* given */ - /* ep0 maxpktsize is 0x200 (WUSB1.0[4.8.1]) */ - if (usb_endpoint_xfer_isoc(&ep->desc)) - rpipe->descr.wMaxPacketSize = epcd->wOverTheAirPacketSize; - else - rpipe->descr.wMaxPacketSize = ep->desc.wMaxPacketSize; - - rpipe->descr.hwa_bMaxBurst = max(min_t(unsigned int, - epcd->bMaxBurst, 16U), 1U); - rpipe->descr.hwa_bDeviceInfoIndex = - wusb_port_no_to_idx(urb->dev->portnum); - /* FIXME: use maximum speed as supported or recommended by device */ - rpipe->descr.bSpeed = usb_pipeendpoint(urb->pipe) == 0 ? - UWB_PHY_RATE_53 : UWB_PHY_RATE_200; - - dev_dbg(dev, "addr %u (0x%02x) rpipe #%u ep# %u speed %d\n", - urb->dev->devnum, urb->dev->devnum | unauth, - le16_to_cpu(rpipe->descr.wRPipeIndex), - usb_pipeendpoint(urb->pipe), rpipe->descr.bSpeed); - - rpipe->descr.hwa_reserved = 0; - - rpipe->descr.bEndpointAddress = ep->desc.bEndpointAddress; - /* FIXME: bDataSequence */ - rpipe->descr.bDataSequence = 0; - - /* start with base window of hwa_bMaxBurst bits starting at 0. */ - ack_window = 0xFFFFFFFF >> (32 - rpipe->descr.hwa_bMaxBurst); - rpipe->descr.dwCurrentWindow = cpu_to_le32(ack_window); - epcd_max_sequence = max(min_t(unsigned int, - epcd->bMaxSequence, 32U), 2U); - rpipe->descr.bMaxDataSequence = epcd_max_sequence - 1; - rpipe->descr.bInterval = ep->desc.bInterval; - if (usb_endpoint_xfer_isoc(&ep->desc)) - rpipe->descr.bOverTheAirInterval = epcd->bOverTheAirInterval; - else - rpipe->descr.bOverTheAirInterval = 0; /* 0 if not isoc */ - /* FIXME: xmit power & preamble blah blah */ - rpipe->descr.bmAttribute = (ep->desc.bmAttributes & - USB_ENDPOINT_XFERTYPE_MASK); - /* rpipe->descr.bmCharacteristics RO */ - rpipe->descr.bmRetryOptions = (wa->wusb->retry_count & 0xF); - /* FIXME: use for assessing link quality? */ - rpipe->descr.wNumTransactionErrors = 0; - result = __rpipe_set_descr(wa, &rpipe->descr, - le16_to_cpu(rpipe->descr.wRPipeIndex)); - if (result < 0) { - dev_err(dev, "Cannot aim rpipe: %d\n", result); - goto error; - } - result = 0; -error: - return result; -} - -/* - * Check an aimed rpipe to make sure it points to where we want - * - * We use bit 19 of the Linux USB pipe bitmap for unauth vs auth - * space; when it is like that, we or 0x80 to make an unauth address. - */ -static int rpipe_check_aim(const struct wa_rpipe *rpipe, const struct wahc *wa, - const struct usb_host_endpoint *ep, - const struct urb *urb, gfp_t gfp) -{ - int result = 0; - struct device *dev = &wa->usb_iface->dev; - u8 portnum = wusb_port_no_to_idx(urb->dev->portnum); - -#define AIM_CHECK(rdf, val, text) \ - do { \ - if (rpipe->descr.rdf != (val)) { \ - dev_err(dev, \ - "rpipe aim discrepancy: " #rdf " " text "\n", \ - rpipe->descr.rdf, (val)); \ - result = -EINVAL; \ - WARN_ON(1); \ - } \ - } while (0) - AIM_CHECK(hwa_bDeviceInfoIndex, portnum, "(%u vs %u)"); - AIM_CHECK(bSpeed, usb_pipeendpoint(urb->pipe) == 0 ? - UWB_PHY_RATE_53 : UWB_PHY_RATE_200, - "(%u vs %u)"); - AIM_CHECK(bEndpointAddress, ep->desc.bEndpointAddress, "(%u vs %u)"); - AIM_CHECK(bInterval, ep->desc.bInterval, "(%u vs %u)"); - AIM_CHECK(bmAttribute, ep->desc.bmAttributes & 0x03, "(%u vs %u)"); -#undef AIM_CHECK - return result; -} - -#ifndef CONFIG_BUG -#define CONFIG_BUG 0 -#endif - -/* - * Make sure there is an rpipe allocated for an endpoint - * - * If already allocated, we just refcount it; if not, we get an - * idle one, aim it to the right location and take it. - * - * Attaches to ep->hcpriv and rpipe->ep to ep. - */ -int rpipe_get_by_ep(struct wahc *wa, struct usb_host_endpoint *ep, - struct urb *urb, gfp_t gfp) -{ - int result = 0; - struct device *dev = &wa->usb_iface->dev; - struct wa_rpipe *rpipe; - u8 eptype; - - mutex_lock(&wa->rpipe_mutex); - rpipe = ep->hcpriv; - if (rpipe != NULL) { - if (CONFIG_BUG == 1) { - result = rpipe_check_aim(rpipe, wa, ep, urb, gfp); - if (result < 0) - goto error; - } - __rpipe_get(rpipe); - dev_dbg(dev, "ep 0x%02x: reusing rpipe %u\n", - ep->desc.bEndpointAddress, - le16_to_cpu(rpipe->descr.wRPipeIndex)); - } else { - /* hmm, assign idle rpipe, aim it */ - result = -ENOBUFS; - eptype = ep->desc.bmAttributes & 0x03; - result = rpipe_get_idle(&rpipe, wa, 1 << eptype, gfp); - if (result < 0) - goto error; - result = rpipe_aim(rpipe, wa, ep, urb, gfp); - if (result < 0) { - rpipe_put(rpipe); - goto error; - } - ep->hcpriv = rpipe; - rpipe->ep = ep; - __rpipe_get(rpipe); /* for caching into ep->hcpriv */ - dev_dbg(dev, "ep 0x%02x: using rpipe %u\n", - ep->desc.bEndpointAddress, - le16_to_cpu(rpipe->descr.wRPipeIndex)); - } -error: - mutex_unlock(&wa->rpipe_mutex); - return result; -} - -/* - * Allocate the bitmap for each rpipe. - */ -int wa_rpipes_create(struct wahc *wa) -{ - wa->rpipes = le16_to_cpu(wa->wa_descr->wNumRPipes); - wa->rpipe_bm = bitmap_zalloc(wa->rpipes, GFP_KERNEL); - if (wa->rpipe_bm == NULL) - return -ENOMEM; - return 0; -} - -void wa_rpipes_destroy(struct wahc *wa) -{ - struct device *dev = &wa->usb_iface->dev; - - if (!bitmap_empty(wa->rpipe_bm, wa->rpipes)) { - WARN_ON(1); - dev_err(dev, "BUG: pipes not released on exit: %*pb\n", - wa->rpipes, wa->rpipe_bm); - } - bitmap_free(wa->rpipe_bm); -} - -/* - * Release resources allocated for an endpoint - * - * If there is an associated rpipe to this endpoint, Abort any pending - * transfers and put it. If the rpipe ends up being destroyed, - * __rpipe_destroy() will cleanup ep->hcpriv. - * - * This is called before calling hcd->stop(), so you don't need to do - * anything else in there. - */ -void rpipe_ep_disable(struct wahc *wa, struct usb_host_endpoint *ep) -{ - struct wa_rpipe *rpipe; - - mutex_lock(&wa->rpipe_mutex); - rpipe = ep->hcpriv; - if (rpipe != NULL) { - u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); - - usb_control_msg( - wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_RPIPE_ABORT, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, - 0, index, NULL, 0, USB_CTRL_SET_TIMEOUT); - rpipe_put(rpipe); - } - mutex_unlock(&wa->rpipe_mutex); -} -EXPORT_SYMBOL_GPL(rpipe_ep_disable); - -/* Clear the stalled status of an RPIPE. */ -void rpipe_clear_feature_stalled(struct wahc *wa, struct usb_host_endpoint *ep) -{ - struct wa_rpipe *rpipe; - - mutex_lock(&wa->rpipe_mutex); - rpipe = ep->hcpriv; - if (rpipe != NULL) { - u16 index = le16_to_cpu(rpipe->descr.wRPipeIndex); - - usb_control_msg( - wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0), - USB_REQ_CLEAR_FEATURE, - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_RPIPE, - RPIPE_STALL, index, NULL, 0, USB_CTRL_SET_TIMEOUT); - } - mutex_unlock(&wa->rpipe_mutex); -} -EXPORT_SYMBOL_GPL(rpipe_clear_feature_stalled); diff --git a/drivers/staging/wusbcore/wa-xfer.c b/drivers/staging/wusbcore/wa-xfer.c deleted file mode 100644 index abf88cea37bb..000000000000 --- a/drivers/staging/wusbcore/wa-xfer.c +++ /dev/null @@ -1,2927 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WUSB Wire Adapter - * Data transfer and URB enqueing - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * How transfers work: get a buffer, break it up in segments (segment - * size is a multiple of the maxpacket size). For each segment issue a - * segment request (struct wa_xfer_*), then send the data buffer if - * out or nothing if in (all over the DTO endpoint). - * - * For each submitted segment request, a notification will come over - * the NEP endpoint and a transfer result (struct xfer_result) will - * arrive in the DTI URB. Read it, get the xfer ID, see if there is - * data coming (inbound transfer), schedule a read and handle it. - * - * Sounds simple, it is a pain to implement. - * - * - * ENTRY POINTS - * - * FIXME - * - * LIFE CYCLE / STATE DIAGRAM - * - * FIXME - * - * THIS CODE IS DISGUSTING - * - * Warned you are; it's my second try and still not happy with it. - * - * NOTES: - * - * - No iso - * - * - Supports DMA xfers, control, bulk and maybe interrupt - * - * - Does not recycle unused rpipes - * - * An rpipe is assigned to an endpoint the first time it is used, - * and then it's there, assigned, until the endpoint is disabled - * (destroyed [{h,d}wahc_op_ep_disable()]. The assignment of the - * rpipe to the endpoint is done under the wa->rpipe_sem semaphore - * (should be a mutex). - * - * Two methods it could be done: - * - * (a) set up a timer every time an rpipe's use count drops to 1 - * (which means unused) or when a transfer ends. Reset the - * timer when a xfer is queued. If the timer expires, release - * the rpipe [see rpipe_ep_disable()]. - * - * (b) when looking for free rpipes to attach [rpipe_get_by_ep()], - * when none are found go over the list, check their endpoint - * and their activity record (if no last-xfer-done-ts in the - * last x seconds) take it - * - * However, due to the fact that we have a set of limited - * resources (max-segments-at-the-same-time per xfer, - * xfers-per-ripe, blocks-per-rpipe, rpipes-per-host), at the end - * we are going to have to rebuild all this based on an scheduler, - * to where we have a list of transactions to do and based on the - * availability of the different required components (blocks, - * rpipes, segment slots, etc), we go scheduling them. Painful. - */ -#include <linux/spinlock.h> -#include <linux/slab.h> -#include <linux/hash.h> -#include <linux/ratelimit.h> -#include <linux/export.h> -#include <linux/scatterlist.h> - -#include "wa-hc.h" -#include "wusbhc.h" - -enum { - /* [WUSB] section 8.3.3 allocates 7 bits for the segment index. */ - WA_SEGS_MAX = 128, -}; - -enum wa_seg_status { - WA_SEG_NOTREADY, - WA_SEG_READY, - WA_SEG_DELAYED, - WA_SEG_SUBMITTED, - WA_SEG_PENDING, - WA_SEG_DTI_PENDING, - WA_SEG_DONE, - WA_SEG_ERROR, - WA_SEG_ABORTED, -}; - -static void wa_xfer_delayed_run(struct wa_rpipe *); -static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting); - -/* - * Life cycle governed by 'struct urb' (the refcount of the struct is - * that of the 'struct urb' and usb_free_urb() would free the whole - * struct). - */ -struct wa_seg { - struct urb tr_urb; /* transfer request urb. */ - struct urb *isoc_pack_desc_urb; /* for isoc packet descriptor. */ - struct urb *dto_urb; /* for data output. */ - struct list_head list_node; /* for rpipe->req_list */ - struct wa_xfer *xfer; /* out xfer */ - u8 index; /* which segment we are */ - int isoc_frame_count; /* number of isoc frames in this segment. */ - int isoc_frame_offset; /* starting frame offset in the xfer URB. */ - /* Isoc frame that the current transfer buffer corresponds to. */ - int isoc_frame_index; - int isoc_size; /* size of all isoc frames sent by this seg. */ - enum wa_seg_status status; - ssize_t result; /* bytes xfered or error */ - struct wa_xfer_hdr xfer_hdr; -}; - -static inline void wa_seg_init(struct wa_seg *seg) -{ - usb_init_urb(&seg->tr_urb); - - /* set the remaining memory to 0. */ - memset(((void *)seg) + sizeof(seg->tr_urb), 0, - sizeof(*seg) - sizeof(seg->tr_urb)); -} - -/* - * Protected by xfer->lock - * - */ -struct wa_xfer { - struct kref refcnt; - struct list_head list_node; - spinlock_t lock; - u32 id; - - struct wahc *wa; /* Wire adapter we are plugged to */ - struct usb_host_endpoint *ep; - struct urb *urb; /* URB we are transferring for */ - struct wa_seg **seg; /* transfer segments */ - u8 segs, segs_submitted, segs_done; - unsigned is_inbound:1; - unsigned is_dma:1; - size_t seg_size; - int result; - - gfp_t gfp; /* allocation mask */ - - struct wusb_dev *wusb_dev; /* for activity timestamps */ -}; - -static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer, - struct wa_seg *seg, int curr_iso_frame); -static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, - int starting_index, enum wa_seg_status status); - -static inline void wa_xfer_init(struct wa_xfer *xfer) -{ - kref_init(&xfer->refcnt); - INIT_LIST_HEAD(&xfer->list_node); - spin_lock_init(&xfer->lock); -} - -/* - * Destroy a transfer structure - * - * Note that freeing xfer->seg[cnt]->tr_urb will free the containing - * xfer->seg[cnt] memory that was allocated by __wa_xfer_setup_segs. - */ -static void wa_xfer_destroy(struct kref *_xfer) -{ - struct wa_xfer *xfer = container_of(_xfer, struct wa_xfer, refcnt); - if (xfer->seg) { - unsigned cnt; - for (cnt = 0; cnt < xfer->segs; cnt++) { - struct wa_seg *seg = xfer->seg[cnt]; - if (seg) { - usb_free_urb(seg->isoc_pack_desc_urb); - if (seg->dto_urb) { - kfree(seg->dto_urb->sg); - usb_free_urb(seg->dto_urb); - } - usb_free_urb(&seg->tr_urb); - } - } - kfree(xfer->seg); - } - kfree(xfer); -} - -static void wa_xfer_get(struct wa_xfer *xfer) -{ - kref_get(&xfer->refcnt); -} - -static void wa_xfer_put(struct wa_xfer *xfer) -{ - kref_put(&xfer->refcnt, wa_xfer_destroy); -} - -/* - * Try to get exclusive access to the DTO endpoint resource. Return true - * if successful. - */ -static inline int __wa_dto_try_get(struct wahc *wa) -{ - return (test_and_set_bit(0, &wa->dto_in_use) == 0); -} - -/* Release the DTO endpoint resource. */ -static inline void __wa_dto_put(struct wahc *wa) -{ - clear_bit_unlock(0, &wa->dto_in_use); -} - -/* Service RPIPEs that are waiting on the DTO resource. */ -static void wa_check_for_delayed_rpipes(struct wahc *wa) -{ - unsigned long flags; - int dto_waiting = 0; - struct wa_rpipe *rpipe; - - spin_lock_irqsave(&wa->rpipe_lock, flags); - while (!list_empty(&wa->rpipe_delayed_list) && !dto_waiting) { - rpipe = list_first_entry(&wa->rpipe_delayed_list, - struct wa_rpipe, list_node); - __wa_xfer_delayed_run(rpipe, &dto_waiting); - /* remove this RPIPE from the list if it is not waiting. */ - if (!dto_waiting) { - pr_debug("%s: RPIPE %d serviced and removed from delayed list.\n", - __func__, - le16_to_cpu(rpipe->descr.wRPipeIndex)); - list_del_init(&rpipe->list_node); - } - } - spin_unlock_irqrestore(&wa->rpipe_lock, flags); -} - -/* add this RPIPE to the end of the delayed RPIPE list. */ -static void wa_add_delayed_rpipe(struct wahc *wa, struct wa_rpipe *rpipe) -{ - unsigned long flags; - - spin_lock_irqsave(&wa->rpipe_lock, flags); - /* add rpipe to the list if it is not already on it. */ - if (list_empty(&rpipe->list_node)) { - pr_debug("%s: adding RPIPE %d to the delayed list.\n", - __func__, le16_to_cpu(rpipe->descr.wRPipeIndex)); - list_add_tail(&rpipe->list_node, &wa->rpipe_delayed_list); - } - spin_unlock_irqrestore(&wa->rpipe_lock, flags); -} - -/* - * xfer is referenced - * - * xfer->lock has to be unlocked - * - * We take xfer->lock for setting the result; this is a barrier - * against drivers/usb/core/hcd.c:unlink1() being called after we call - * usb_hcd_giveback_urb() and wa_urb_dequeue() trying to get a - * reference to the transfer. - */ -static void wa_xfer_giveback(struct wa_xfer *xfer) -{ - unsigned long flags; - - spin_lock_irqsave(&xfer->wa->xfer_list_lock, flags); - list_del_init(&xfer->list_node); - usb_hcd_unlink_urb_from_ep(&(xfer->wa->wusb->usb_hcd), xfer->urb); - spin_unlock_irqrestore(&xfer->wa->xfer_list_lock, flags); - /* FIXME: segmentation broken -- kills DWA */ - wusbhc_giveback_urb(xfer->wa->wusb, xfer->urb, xfer->result); - wa_put(xfer->wa); - wa_xfer_put(xfer); -} - -/* - * xfer is referenced - * - * xfer->lock has to be unlocked - */ -static void wa_xfer_completion(struct wa_xfer *xfer) -{ - if (xfer->wusb_dev) - wusb_dev_put(xfer->wusb_dev); - rpipe_put(xfer->ep->hcpriv); - wa_xfer_giveback(xfer); -} - -/* - * Initialize a transfer's ID - * - * We need to use a sequential number; if we use the pointer or the - * hash of the pointer, it can repeat over sequential transfers and - * then it will confuse the HWA....wonder why in hell they put a 32 - * bit handle in there then. - */ -static void wa_xfer_id_init(struct wa_xfer *xfer) -{ - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count); -} - -/* Return the xfer's ID. */ -static inline u32 wa_xfer_id(struct wa_xfer *xfer) -{ - return xfer->id; -} - -/* Return the xfer's ID in transport format (little endian). */ -static inline __le32 wa_xfer_id_le32(struct wa_xfer *xfer) -{ - return cpu_to_le32(xfer->id); -} - -/* - * If transfer is done, wrap it up and return true - * - * xfer->lock has to be locked - */ -static unsigned __wa_xfer_is_done(struct wa_xfer *xfer) -{ - struct device *dev = &xfer->wa->usb_iface->dev; - unsigned result, cnt; - struct wa_seg *seg; - struct urb *urb = xfer->urb; - unsigned found_short = 0; - - result = xfer->segs_done == xfer->segs_submitted; - if (result == 0) - goto out; - urb->actual_length = 0; - for (cnt = 0; cnt < xfer->segs; cnt++) { - seg = xfer->seg[cnt]; - switch (seg->status) { - case WA_SEG_DONE: - if (found_short && seg->result > 0) { - dev_dbg(dev, "xfer %p ID %08X#%u: bad short segments (%zu)\n", - xfer, wa_xfer_id(xfer), cnt, - seg->result); - urb->status = -EINVAL; - goto out; - } - urb->actual_length += seg->result; - if (!(usb_pipeisoc(xfer->urb->pipe)) - && seg->result < xfer->seg_size - && cnt != xfer->segs-1) - found_short = 1; - dev_dbg(dev, "xfer %p ID %08X#%u: DONE short %d " - "result %zu urb->actual_length %d\n", - xfer, wa_xfer_id(xfer), seg->index, found_short, - seg->result, urb->actual_length); - break; - case WA_SEG_ERROR: - xfer->result = seg->result; - dev_dbg(dev, "xfer %p ID %08X#%u: ERROR result %zi(0x%08zX)\n", - xfer, wa_xfer_id(xfer), seg->index, seg->result, - seg->result); - goto out; - case WA_SEG_ABORTED: - xfer->result = seg->result; - dev_dbg(dev, "xfer %p ID %08X#%u: ABORTED result %zi(0x%08zX)\n", - xfer, wa_xfer_id(xfer), seg->index, seg->result, - seg->result); - goto out; - default: - dev_warn(dev, "xfer %p ID %08X#%u: is_done bad state %d\n", - xfer, wa_xfer_id(xfer), cnt, seg->status); - xfer->result = -EINVAL; - goto out; - } - } - xfer->result = 0; -out: - return result; -} - -/* - * Mark the given segment as done. Return true if this completes the xfer. - * This should only be called for segs that have been submitted to an RPIPE. - * Delayed segs are not marked as submitted so they do not need to be marked - * as done when cleaning up. - * - * xfer->lock has to be locked - */ -static unsigned __wa_xfer_mark_seg_as_done(struct wa_xfer *xfer, - struct wa_seg *seg, enum wa_seg_status status) -{ - seg->status = status; - xfer->segs_done++; - - /* check for done. */ - return __wa_xfer_is_done(xfer); -} - -/* - * Search for a transfer list ID on the HCD's URB list - * - * For 32 bit architectures, we use the pointer itself; for 64 bits, a - * 32-bit hash of the pointer. - * - * @returns NULL if not found. - */ -static struct wa_xfer *wa_xfer_get_by_id(struct wahc *wa, u32 id) -{ - unsigned long flags; - struct wa_xfer *xfer_itr; - spin_lock_irqsave(&wa->xfer_list_lock, flags); - list_for_each_entry(xfer_itr, &wa->xfer_list, list_node) { - if (id == xfer_itr->id) { - wa_xfer_get(xfer_itr); - goto out; - } - } - xfer_itr = NULL; -out: - spin_unlock_irqrestore(&wa->xfer_list_lock, flags); - return xfer_itr; -} - -struct wa_xfer_abort_buffer { - struct urb urb; - struct wahc *wa; - struct wa_xfer_abort cmd; -}; - -static void __wa_xfer_abort_cb(struct urb *urb) -{ - struct wa_xfer_abort_buffer *b = urb->context; - struct wahc *wa = b->wa; - - /* - * If the abort request URB failed, then the HWA did not get the abort - * command. Forcibly clean up the xfer without waiting for a Transfer - * Result from the HWA. - */ - if (urb->status < 0) { - struct wa_xfer *xfer; - struct device *dev = &wa->usb_iface->dev; - - xfer = wa_xfer_get_by_id(wa, le32_to_cpu(b->cmd.dwTransferID)); - dev_err(dev, "%s: Transfer Abort request failed. result: %d\n", - __func__, urb->status); - if (xfer) { - unsigned long flags; - int done, seg_index = 0; - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - - dev_err(dev, "%s: cleaning up xfer %p ID 0x%08X.\n", - __func__, xfer, wa_xfer_id(xfer)); - spin_lock_irqsave(&xfer->lock, flags); - /* skip done segs. */ - while (seg_index < xfer->segs) { - struct wa_seg *seg = xfer->seg[seg_index]; - - if ((seg->status == WA_SEG_DONE) || - (seg->status == WA_SEG_ERROR)) { - ++seg_index; - } else { - break; - } - } - /* mark remaining segs as aborted. */ - wa_complete_remaining_xfer_segs(xfer, seg_index, - WA_SEG_ABORTED); - done = __wa_xfer_is_done(xfer); - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - wa_xfer_delayed_run(rpipe); - wa_xfer_put(xfer); - } else { - dev_err(dev, "%s: xfer ID 0x%08X already gone.\n", - __func__, le32_to_cpu(b->cmd.dwTransferID)); - } - } - - wa_put(wa); /* taken in __wa_xfer_abort */ - usb_put_urb(&b->urb); -} - -/* - * Aborts an ongoing transaction - * - * Assumes the transfer is referenced and locked and in a submitted - * state (mainly that there is an endpoint/rpipe assigned). - * - * The callback (see above) does nothing but freeing up the data by - * putting the URB. Because the URB is allocated at the head of the - * struct, the whole space we allocated is kfreed. * - */ -static int __wa_xfer_abort(struct wa_xfer *xfer) -{ - int result = -ENOMEM; - struct device *dev = &xfer->wa->usb_iface->dev; - struct wa_xfer_abort_buffer *b; - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - - b = kmalloc(sizeof(*b), GFP_ATOMIC); - if (b == NULL) - goto error_kmalloc; - b->cmd.bLength = sizeof(b->cmd); - b->cmd.bRequestType = WA_XFER_ABORT; - b->cmd.wRPipe = rpipe->descr.wRPipeIndex; - b->cmd.dwTransferID = wa_xfer_id_le32(xfer); - b->wa = wa_get(xfer->wa); - - usb_init_urb(&b->urb); - usb_fill_bulk_urb(&b->urb, xfer->wa->usb_dev, - usb_sndbulkpipe(xfer->wa->usb_dev, - xfer->wa->dto_epd->bEndpointAddress), - &b->cmd, sizeof(b->cmd), __wa_xfer_abort_cb, b); - result = usb_submit_urb(&b->urb, GFP_ATOMIC); - if (result < 0) - goto error_submit; - return result; /* callback frees! */ - - -error_submit: - wa_put(xfer->wa); - if (printk_ratelimit()) - dev_err(dev, "xfer %p: Can't submit abort request: %d\n", - xfer, result); - kfree(b); -error_kmalloc: - return result; - -} - -/* - * Calculate the number of isoc frames starting from isoc_frame_offset - * that will fit a in transfer segment. - */ -static int __wa_seg_calculate_isoc_frame_count(struct wa_xfer *xfer, - int isoc_frame_offset, int *total_size) -{ - int segment_size = 0, frame_count = 0; - int index = isoc_frame_offset; - struct usb_iso_packet_descriptor *iso_frame_desc = - xfer->urb->iso_frame_desc; - - while ((index < xfer->urb->number_of_packets) - && ((segment_size + iso_frame_desc[index].length) - <= xfer->seg_size)) { - /* - * For Alereon HWA devices, only include an isoc frame in an - * out segment if it is physically contiguous with the previous - * frame. This is required because those devices expect - * the isoc frames to be sent as a single USB transaction as - * opposed to one transaction per frame with standard HWA. - */ - if ((xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) - && (xfer->is_inbound == 0) - && (index > isoc_frame_offset) - && ((iso_frame_desc[index - 1].offset + - iso_frame_desc[index - 1].length) != - iso_frame_desc[index].offset)) - break; - - /* this frame fits. count it. */ - ++frame_count; - segment_size += iso_frame_desc[index].length; - - /* move to the next isoc frame. */ - ++index; - } - - *total_size = segment_size; - return frame_count; -} - -/* - * - * @returns < 0 on error, transfer segment request size if ok - */ -static ssize_t __wa_xfer_setup_sizes(struct wa_xfer *xfer, - enum wa_xfer_type *pxfer_type) -{ - ssize_t result; - struct device *dev = &xfer->wa->usb_iface->dev; - size_t maxpktsize; - struct urb *urb = xfer->urb; - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - - switch (rpipe->descr.bmAttribute & 0x3) { - case USB_ENDPOINT_XFER_CONTROL: - *pxfer_type = WA_XFER_TYPE_CTL; - result = sizeof(struct wa_xfer_ctl); - break; - case USB_ENDPOINT_XFER_INT: - case USB_ENDPOINT_XFER_BULK: - *pxfer_type = WA_XFER_TYPE_BI; - result = sizeof(struct wa_xfer_bi); - break; - case USB_ENDPOINT_XFER_ISOC: - *pxfer_type = WA_XFER_TYPE_ISO; - result = sizeof(struct wa_xfer_hwaiso); - break; - default: - /* never happens */ - BUG(); - result = -EINVAL; /* shut gcc up */ - } - xfer->is_inbound = urb->pipe & USB_DIR_IN ? 1 : 0; - xfer->is_dma = urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? 1 : 0; - - maxpktsize = le16_to_cpu(rpipe->descr.wMaxPacketSize); - xfer->seg_size = le16_to_cpu(rpipe->descr.wBlocks) - * 1 << (xfer->wa->wa_descr->bRPipeBlockSize - 1); - /* Compute the segment size and make sure it is a multiple of - * the maxpktsize (WUSB1.0[8.3.3.1])...not really too much of - * a check (FIXME) */ - if (xfer->seg_size < maxpktsize) { - dev_err(dev, - "HW BUG? seg_size %zu smaller than maxpktsize %zu\n", - xfer->seg_size, maxpktsize); - result = -EINVAL; - goto error; - } - xfer->seg_size = (xfer->seg_size / maxpktsize) * maxpktsize; - if ((rpipe->descr.bmAttribute & 0x3) == USB_ENDPOINT_XFER_ISOC) { - int index = 0; - - xfer->segs = 0; - /* - * loop over urb->number_of_packets to determine how many - * xfer segments will be needed to send the isoc frames. - */ - while (index < urb->number_of_packets) { - int seg_size; /* don't care. */ - index += __wa_seg_calculate_isoc_frame_count(xfer, - index, &seg_size); - ++xfer->segs; - } - } else { - xfer->segs = DIV_ROUND_UP(urb->transfer_buffer_length, - xfer->seg_size); - if (xfer->segs == 0 && *pxfer_type == WA_XFER_TYPE_CTL) - xfer->segs = 1; - } - - if (xfer->segs > WA_SEGS_MAX) { - dev_err(dev, "BUG? oops, number of segments %zu bigger than %d\n", - (urb->transfer_buffer_length/xfer->seg_size), - WA_SEGS_MAX); - result = -EINVAL; - goto error; - } -error: - return result; -} - -static void __wa_setup_isoc_packet_descr( - struct wa_xfer_packet_info_hwaiso *packet_desc, - struct wa_xfer *xfer, - struct wa_seg *seg) { - struct usb_iso_packet_descriptor *iso_frame_desc = - xfer->urb->iso_frame_desc; - int frame_index; - - /* populate isoc packet descriptor. */ - packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO; - packet_desc->wLength = cpu_to_le16(struct_size(packet_desc, - PacketLength, - seg->isoc_frame_count)); - for (frame_index = 0; frame_index < seg->isoc_frame_count; - ++frame_index) { - int offset_index = frame_index + seg->isoc_frame_offset; - packet_desc->PacketLength[frame_index] = - cpu_to_le16(iso_frame_desc[offset_index].length); - } -} - - -/* Fill in the common request header and xfer-type specific data. */ -static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer, - struct wa_xfer_hdr *xfer_hdr0, - enum wa_xfer_type xfer_type, - size_t xfer_hdr_size) -{ - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - struct wa_seg *seg = xfer->seg[0]; - - xfer_hdr0 = &seg->xfer_hdr; - xfer_hdr0->bLength = xfer_hdr_size; - xfer_hdr0->bRequestType = xfer_type; - xfer_hdr0->wRPipe = rpipe->descr.wRPipeIndex; - xfer_hdr0->dwTransferID = wa_xfer_id_le32(xfer); - xfer_hdr0->bTransferSegment = 0; - switch (xfer_type) { - case WA_XFER_TYPE_CTL: { - struct wa_xfer_ctl *xfer_ctl = - container_of(xfer_hdr0, struct wa_xfer_ctl, hdr); - xfer_ctl->bmAttribute = xfer->is_inbound ? 1 : 0; - memcpy(&xfer_ctl->baSetupData, xfer->urb->setup_packet, - sizeof(xfer_ctl->baSetupData)); - break; - } - case WA_XFER_TYPE_BI: - break; - case WA_XFER_TYPE_ISO: { - struct wa_xfer_hwaiso *xfer_iso = - container_of(xfer_hdr0, struct wa_xfer_hwaiso, hdr); - struct wa_xfer_packet_info_hwaiso *packet_desc = - ((void *)xfer_iso) + xfer_hdr_size; - - /* populate the isoc section of the transfer request. */ - xfer_iso->dwNumOfPackets = cpu_to_le32(seg->isoc_frame_count); - /* populate isoc packet descriptor. */ - __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); - break; - } - default: - BUG(); - }; -} - -/* - * Callback for the OUT data phase of the segment request - * - * Check wa_seg_tr_cb(); most comments also apply here because this - * function does almost the same thing and they work closely - * together. - * - * If the seg request has failed but this DTO phase has succeeded, - * wa_seg_tr_cb() has already failed the segment and moved the - * status to WA_SEG_ERROR, so this will go through 'case 0' and - * effectively do nothing. - */ -static void wa_seg_dto_cb(struct urb *urb) -{ - struct wa_seg *seg = urb->context; - struct wa_xfer *xfer = seg->xfer; - struct wahc *wa; - struct device *dev; - struct wa_rpipe *rpipe; - unsigned long flags; - unsigned rpipe_ready = 0; - int data_send_done = 1, release_dto = 0, holding_dto = 0; - u8 done = 0; - int result; - - /* free the sg if it was used. */ - kfree(urb->sg); - urb->sg = NULL; - - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - if (usb_pipeisoc(xfer->urb->pipe)) { - /* Alereon HWA sends all isoc frames in a single transfer. */ - if (wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) - seg->isoc_frame_index += seg->isoc_frame_count; - else - seg->isoc_frame_index += 1; - if (seg->isoc_frame_index < seg->isoc_frame_count) { - data_send_done = 0; - holding_dto = 1; /* checked in error cases. */ - /* - * if this is the last isoc frame of the segment, we - * can release DTO after sending this frame. - */ - if ((seg->isoc_frame_index + 1) >= - seg->isoc_frame_count) - release_dto = 1; - } - dev_dbg(dev, "xfer 0x%08X#%u: isoc frame = %d, holding_dto = %d, release_dto = %d.\n", - wa_xfer_id(xfer), seg->index, seg->isoc_frame_index, - holding_dto, release_dto); - } - spin_unlock_irqrestore(&xfer->lock, flags); - - switch (urb->status) { - case 0: - spin_lock_irqsave(&xfer->lock, flags); - seg->result += urb->actual_length; - if (data_send_done) { - dev_dbg(dev, "xfer 0x%08X#%u: data out done (%zu bytes)\n", - wa_xfer_id(xfer), seg->index, seg->result); - if (seg->status < WA_SEG_PENDING) - seg->status = WA_SEG_PENDING; - } else { - /* should only hit this for isoc xfers. */ - /* - * Populate the dto URB with the next isoc frame buffer, - * send the URB and release DTO if we no longer need it. - */ - __wa_populate_dto_urb_isoc(xfer, seg, - seg->isoc_frame_offset + seg->isoc_frame_index); - - /* resubmit the URB with the next isoc frame. */ - /* take a ref on resubmit. */ - wa_xfer_get(xfer); - result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); - if (result < 0) { - dev_err(dev, "xfer 0x%08X#%u: DTO submit failed: %d\n", - wa_xfer_id(xfer), seg->index, result); - spin_unlock_irqrestore(&xfer->lock, flags); - goto error_dto_submit; - } - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (release_dto) { - __wa_dto_put(wa); - wa_check_for_delayed_rpipes(wa); - } - break; - case -ECONNRESET: /* URB unlinked; no need to do anything */ - case -ENOENT: /* as it was done by the who unlinked us */ - if (holding_dto) { - __wa_dto_put(wa); - wa_check_for_delayed_rpipes(wa); - } - break; - default: /* Other errors ... */ - dev_err(dev, "xfer 0x%08X#%u: data out error %d\n", - wa_xfer_id(xfer), seg->index, urb->status); - goto error_default; - } - - /* taken when this URB was submitted. */ - wa_xfer_put(xfer); - return; - -error_dto_submit: - /* taken on resubmit attempt. */ - wa_xfer_put(xfer); -error_default: - spin_lock_irqsave(&xfer->lock, flags); - rpipe = xfer->ep->hcpriv; - if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)){ - dev_err(dev, "DTO: URB max acceptable errors exceeded, resetting device\n"); - wa_reset_all(wa); - } - if (seg->status != WA_SEG_ERROR) { - seg->result = urb->status; - __wa_xfer_abort(xfer); - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, WA_SEG_ERROR); - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (holding_dto) { - __wa_dto_put(wa); - wa_check_for_delayed_rpipes(wa); - } - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - /* taken when this URB was submitted. */ - wa_xfer_put(xfer); -} - -/* - * Callback for the isoc packet descriptor phase of the segment request - * - * Check wa_seg_tr_cb(); most comments also apply here because this - * function does almost the same thing and they work closely - * together. - * - * If the seg request has failed but this phase has succeeded, - * wa_seg_tr_cb() has already failed the segment and moved the - * status to WA_SEG_ERROR, so this will go through 'case 0' and - * effectively do nothing. - */ -static void wa_seg_iso_pack_desc_cb(struct urb *urb) -{ - struct wa_seg *seg = urb->context; - struct wa_xfer *xfer = seg->xfer; - struct wahc *wa; - struct device *dev; - struct wa_rpipe *rpipe; - unsigned long flags; - unsigned rpipe_ready = 0; - u8 done = 0; - - switch (urb->status) { - case 0: - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - dev_dbg(dev, "iso xfer %08X#%u: packet descriptor done\n", - wa_xfer_id(xfer), seg->index); - if (xfer->is_inbound && seg->status < WA_SEG_PENDING) - seg->status = WA_SEG_PENDING; - spin_unlock_irqrestore(&xfer->lock, flags); - break; - case -ECONNRESET: /* URB unlinked; no need to do anything */ - case -ENOENT: /* as it was done by the who unlinked us */ - break; - default: /* Other errors ... */ - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - rpipe = xfer->ep->hcpriv; - pr_err_ratelimited("iso xfer %08X#%u: packet descriptor error %d\n", - wa_xfer_id(xfer), seg->index, urb->status); - if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)){ - dev_err(dev, "iso xfer: URB max acceptable errors exceeded, resetting device\n"); - wa_reset_all(wa); - } - if (seg->status != WA_SEG_ERROR) { - usb_unlink_urb(seg->dto_urb); - seg->result = urb->status; - __wa_xfer_abort(xfer); - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, - WA_SEG_ERROR); - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - } - /* taken when this URB was submitted. */ - wa_xfer_put(xfer); -} - -/* - * Callback for the segment request - * - * If successful transition state (unless already transitioned or - * outbound transfer); otherwise, take a note of the error, mark this - * segment done and try completion. - * - * Note we don't access until we are sure that the transfer hasn't - * been cancelled (ECONNRESET, ENOENT), which could mean that - * seg->xfer could be already gone. - * - * We have to check before setting the status to WA_SEG_PENDING - * because sometimes the xfer result callback arrives before this - * callback (geeeeeeze), so it might happen that we are already in - * another state. As well, we don't set it if the transfer is not inbound, - * as in that case, wa_seg_dto_cb will do it when the OUT data phase - * finishes. - */ -static void wa_seg_tr_cb(struct urb *urb) -{ - struct wa_seg *seg = urb->context; - struct wa_xfer *xfer = seg->xfer; - struct wahc *wa; - struct device *dev; - struct wa_rpipe *rpipe; - unsigned long flags; - unsigned rpipe_ready; - u8 done = 0; - - switch (urb->status) { - case 0: - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - dev_dbg(dev, "xfer %p ID 0x%08X#%u: request done\n", - xfer, wa_xfer_id(xfer), seg->index); - if (xfer->is_inbound && - seg->status < WA_SEG_PENDING && - !(usb_pipeisoc(xfer->urb->pipe))) - seg->status = WA_SEG_PENDING; - spin_unlock_irqrestore(&xfer->lock, flags); - break; - case -ECONNRESET: /* URB unlinked; no need to do anything */ - case -ENOENT: /* as it was done by the who unlinked us */ - break; - default: /* Other errors ... */ - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - rpipe = xfer->ep->hcpriv; - if (printk_ratelimit()) - dev_err(dev, "xfer %p ID 0x%08X#%u: request error %d\n", - xfer, wa_xfer_id(xfer), seg->index, - urb->status); - if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)){ - dev_err(dev, "DTO: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - } - usb_unlink_urb(seg->isoc_pack_desc_urb); - usb_unlink_urb(seg->dto_urb); - seg->result = urb->status; - __wa_xfer_abort(xfer); - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, WA_SEG_ERROR); - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - } - /* taken when this URB was submitted. */ - wa_xfer_put(xfer); -} - -/* - * Allocate an SG list to store bytes_to_transfer bytes and copy the - * subset of the in_sg that matches the buffer subset - * we are about to transfer. - */ -static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg, - const unsigned int bytes_transferred, - const unsigned int bytes_to_transfer, int *out_num_sgs) -{ - struct scatterlist *out_sg; - unsigned int bytes_processed = 0, offset_into_current_page_data = 0, - nents; - struct scatterlist *current_xfer_sg = in_sg; - struct scatterlist *current_seg_sg, *last_seg_sg; - - /* skip previously transferred pages. */ - while ((current_xfer_sg) && - (bytes_processed < bytes_transferred)) { - bytes_processed += current_xfer_sg->length; - - /* advance the sg if current segment starts on or past the - next page. */ - if (bytes_processed <= bytes_transferred) - current_xfer_sg = sg_next(current_xfer_sg); - } - - /* the data for the current segment starts in current_xfer_sg. - calculate the offset. */ - if (bytes_processed > bytes_transferred) { - offset_into_current_page_data = current_xfer_sg->length - - (bytes_processed - bytes_transferred); - } - - /* calculate the number of pages needed by this segment. */ - nents = DIV_ROUND_UP((bytes_to_transfer + - offset_into_current_page_data + - current_xfer_sg->offset), - PAGE_SIZE); - - out_sg = kmalloc((sizeof(struct scatterlist) * nents), GFP_ATOMIC); - if (out_sg) { - sg_init_table(out_sg, nents); - - /* copy the portion of the incoming SG that correlates to the - * data to be transferred by this segment to the segment SG. */ - last_seg_sg = current_seg_sg = out_sg; - bytes_processed = 0; - - /* reset nents and calculate the actual number of sg entries - needed. */ - nents = 0; - while ((bytes_processed < bytes_to_transfer) && - current_seg_sg && current_xfer_sg) { - unsigned int page_len = min((current_xfer_sg->length - - offset_into_current_page_data), - (bytes_to_transfer - bytes_processed)); - - sg_set_page(current_seg_sg, sg_page(current_xfer_sg), - page_len, - current_xfer_sg->offset + - offset_into_current_page_data); - - bytes_processed += page_len; - - last_seg_sg = current_seg_sg; - current_seg_sg = sg_next(current_seg_sg); - current_xfer_sg = sg_next(current_xfer_sg); - - /* only the first page may require additional offset. */ - offset_into_current_page_data = 0; - nents++; - } - - /* update num_sgs and terminate the list since we may have - * concatenated pages. */ - sg_mark_end(last_seg_sg); - *out_num_sgs = nents; - } - - return out_sg; -} - -/* - * Populate DMA buffer info for the isoc dto urb. - */ -static void __wa_populate_dto_urb_isoc(struct wa_xfer *xfer, - struct wa_seg *seg, int curr_iso_frame) -{ - seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - seg->dto_urb->sg = NULL; - seg->dto_urb->num_sgs = 0; - /* dto urb buffer address pulled from iso_frame_desc. */ - seg->dto_urb->transfer_dma = xfer->urb->transfer_dma + - xfer->urb->iso_frame_desc[curr_iso_frame].offset; - /* The Alereon HWA sends a single URB with all isoc segs. */ - if (xfer->wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) - seg->dto_urb->transfer_buffer_length = seg->isoc_size; - else - seg->dto_urb->transfer_buffer_length = - xfer->urb->iso_frame_desc[curr_iso_frame].length; -} - -/* - * Populate buffer ptr and size, DMA buffer or SG list for the dto urb. - */ -static int __wa_populate_dto_urb(struct wa_xfer *xfer, - struct wa_seg *seg, size_t buf_itr_offset, size_t buf_itr_size) -{ - int result = 0; - - if (xfer->is_dma) { - seg->dto_urb->transfer_dma = - xfer->urb->transfer_dma + buf_itr_offset; - seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - seg->dto_urb->sg = NULL; - seg->dto_urb->num_sgs = 0; - } else { - /* do buffer or SG processing. */ - seg->dto_urb->transfer_flags &= - ~URB_NO_TRANSFER_DMA_MAP; - /* this should always be 0 before a resubmit. */ - seg->dto_urb->num_mapped_sgs = 0; - - if (xfer->urb->transfer_buffer) { - seg->dto_urb->transfer_buffer = - xfer->urb->transfer_buffer + - buf_itr_offset; - seg->dto_urb->sg = NULL; - seg->dto_urb->num_sgs = 0; - } else { - seg->dto_urb->transfer_buffer = NULL; - - /* - * allocate an SG list to store seg_size bytes - * and copy the subset of the xfer->urb->sg that - * matches the buffer subset we are about to - * read. - */ - seg->dto_urb->sg = wa_xfer_create_subset_sg( - xfer->urb->sg, - buf_itr_offset, buf_itr_size, - &(seg->dto_urb->num_sgs)); - if (!(seg->dto_urb->sg)) - result = -ENOMEM; - } - } - seg->dto_urb->transfer_buffer_length = buf_itr_size; - - return result; -} - -/* - * Allocate the segs array and initialize each of them - * - * The segments are freed by wa_xfer_destroy() when the xfer use count - * drops to zero; however, because each segment is given the same life - * cycle as the USB URB it contains, it is actually freed by - * usb_put_urb() on the contained USB URB (twisted, eh?). - */ -static int __wa_xfer_setup_segs(struct wa_xfer *xfer, size_t xfer_hdr_size) -{ - int result, cnt, isoc_frame_offset = 0; - size_t alloc_size = sizeof(*xfer->seg[0]) - - sizeof(xfer->seg[0]->xfer_hdr) + xfer_hdr_size; - struct usb_device *usb_dev = xfer->wa->usb_dev; - const struct usb_endpoint_descriptor *dto_epd = xfer->wa->dto_epd; - struct wa_seg *seg; - size_t buf_itr, buf_size, buf_itr_size; - - result = -ENOMEM; - xfer->seg = kcalloc(xfer->segs, sizeof(xfer->seg[0]), GFP_ATOMIC); - if (xfer->seg == NULL) - goto error_segs_kzalloc; - buf_itr = 0; - buf_size = xfer->urb->transfer_buffer_length; - for (cnt = 0; cnt < xfer->segs; cnt++) { - size_t iso_pkt_descr_size = 0; - int seg_isoc_frame_count = 0, seg_isoc_size = 0; - - /* - * Adjust the size of the segment object to contain space for - * the isoc packet descriptor buffer. - */ - if (usb_pipeisoc(xfer->urb->pipe)) { - seg_isoc_frame_count = - __wa_seg_calculate_isoc_frame_count(xfer, - isoc_frame_offset, &seg_isoc_size); - - iso_pkt_descr_size = - sizeof(struct wa_xfer_packet_info_hwaiso) + - (seg_isoc_frame_count * sizeof(__le16)); - } - result = -ENOMEM; - seg = xfer->seg[cnt] = kmalloc(alloc_size + iso_pkt_descr_size, - GFP_ATOMIC); - if (seg == NULL) - goto error_seg_kmalloc; - wa_seg_init(seg); - seg->xfer = xfer; - seg->index = cnt; - usb_fill_bulk_urb(&seg->tr_urb, usb_dev, - usb_sndbulkpipe(usb_dev, - dto_epd->bEndpointAddress), - &seg->xfer_hdr, xfer_hdr_size, - wa_seg_tr_cb, seg); - buf_itr_size = min(buf_size, xfer->seg_size); - - if (usb_pipeisoc(xfer->urb->pipe)) { - seg->isoc_frame_count = seg_isoc_frame_count; - seg->isoc_frame_offset = isoc_frame_offset; - seg->isoc_size = seg_isoc_size; - /* iso packet descriptor. */ - seg->isoc_pack_desc_urb = - usb_alloc_urb(0, GFP_ATOMIC); - if (seg->isoc_pack_desc_urb == NULL) - goto error_iso_pack_desc_alloc; - /* - * The buffer for the isoc packet descriptor starts - * after the transfer request header in the - * segment object memory buffer. - */ - usb_fill_bulk_urb( - seg->isoc_pack_desc_urb, usb_dev, - usb_sndbulkpipe(usb_dev, - dto_epd->bEndpointAddress), - (void *)(&seg->xfer_hdr) + - xfer_hdr_size, - iso_pkt_descr_size, - wa_seg_iso_pack_desc_cb, seg); - - /* adjust starting frame offset for next seg. */ - isoc_frame_offset += seg_isoc_frame_count; - } - - if (xfer->is_inbound == 0 && buf_size > 0) { - /* outbound data. */ - seg->dto_urb = usb_alloc_urb(0, GFP_ATOMIC); - if (seg->dto_urb == NULL) - goto error_dto_alloc; - usb_fill_bulk_urb( - seg->dto_urb, usb_dev, - usb_sndbulkpipe(usb_dev, - dto_epd->bEndpointAddress), - NULL, 0, wa_seg_dto_cb, seg); - - if (usb_pipeisoc(xfer->urb->pipe)) { - /* - * Fill in the xfer buffer information for the - * first isoc frame. Subsequent frames in this - * segment will be filled in and sent from the - * DTO completion routine, if needed. - */ - __wa_populate_dto_urb_isoc(xfer, seg, - seg->isoc_frame_offset); - } else { - /* fill in the xfer buffer information. */ - result = __wa_populate_dto_urb(xfer, seg, - buf_itr, buf_itr_size); - if (result < 0) - goto error_seg_outbound_populate; - - buf_itr += buf_itr_size; - buf_size -= buf_itr_size; - } - } - seg->status = WA_SEG_READY; - } - return 0; - - /* - * Free the memory for the current segment which failed to init. - * Use the fact that cnt is left at were it failed. The remaining - * segments will be cleaned up by wa_xfer_destroy. - */ -error_seg_outbound_populate: - usb_free_urb(xfer->seg[cnt]->dto_urb); -error_dto_alloc: - usb_free_urb(xfer->seg[cnt]->isoc_pack_desc_urb); -error_iso_pack_desc_alloc: - kfree(xfer->seg[cnt]); - xfer->seg[cnt] = NULL; -error_seg_kmalloc: -error_segs_kzalloc: - return result; -} - -/* - * Allocates all the stuff needed to submit a transfer - * - * Breaks the whole data buffer in a list of segments, each one has a - * structure allocated to it and linked in xfer->seg[index] - * - * FIXME: merge setup_segs() and the last part of this function, no - * need to do two for loops when we could run everything in a - * single one - */ -static int __wa_xfer_setup(struct wa_xfer *xfer, struct urb *urb) -{ - int result; - struct device *dev = &xfer->wa->usb_iface->dev; - enum wa_xfer_type xfer_type = 0; /* shut up GCC */ - size_t xfer_hdr_size, cnt, transfer_size; - struct wa_xfer_hdr *xfer_hdr0, *xfer_hdr; - - result = __wa_xfer_setup_sizes(xfer, &xfer_type); - if (result < 0) - goto error_setup_sizes; - xfer_hdr_size = result; - result = __wa_xfer_setup_segs(xfer, xfer_hdr_size); - if (result < 0) { - dev_err(dev, "xfer %p: Failed to allocate %d segments: %d\n", - xfer, xfer->segs, result); - goto error_setup_segs; - } - /* Fill the first header */ - xfer_hdr0 = &xfer->seg[0]->xfer_hdr; - wa_xfer_id_init(xfer); - __wa_xfer_setup_hdr0(xfer, xfer_hdr0, xfer_type, xfer_hdr_size); - - /* Fill remaining headers */ - xfer_hdr = xfer_hdr0; - if (xfer_type == WA_XFER_TYPE_ISO) { - xfer_hdr0->dwTransferLength = - cpu_to_le32(xfer->seg[0]->isoc_size); - for (cnt = 1; cnt < xfer->segs; cnt++) { - struct wa_xfer_packet_info_hwaiso *packet_desc; - struct wa_seg *seg = xfer->seg[cnt]; - struct wa_xfer_hwaiso *xfer_iso; - - xfer_hdr = &seg->xfer_hdr; - xfer_iso = container_of(xfer_hdr, - struct wa_xfer_hwaiso, hdr); - packet_desc = ((void *)xfer_hdr) + xfer_hdr_size; - /* - * Copy values from the 0th header. Segment specific - * values are set below. - */ - memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); - xfer_hdr->bTransferSegment = cnt; - xfer_hdr->dwTransferLength = - cpu_to_le32(seg->isoc_size); - xfer_iso->dwNumOfPackets = - cpu_to_le32(seg->isoc_frame_count); - __wa_setup_isoc_packet_descr(packet_desc, xfer, seg); - seg->status = WA_SEG_READY; - } - } else { - transfer_size = urb->transfer_buffer_length; - xfer_hdr0->dwTransferLength = transfer_size > xfer->seg_size ? - cpu_to_le32(xfer->seg_size) : - cpu_to_le32(transfer_size); - transfer_size -= xfer->seg_size; - for (cnt = 1; cnt < xfer->segs; cnt++) { - xfer_hdr = &xfer->seg[cnt]->xfer_hdr; - memcpy(xfer_hdr, xfer_hdr0, xfer_hdr_size); - xfer_hdr->bTransferSegment = cnt; - xfer_hdr->dwTransferLength = - transfer_size > xfer->seg_size ? - cpu_to_le32(xfer->seg_size) - : cpu_to_le32(transfer_size); - xfer->seg[cnt]->status = WA_SEG_READY; - transfer_size -= xfer->seg_size; - } - } - xfer_hdr->bTransferSegment |= 0x80; /* this is the last segment */ - result = 0; -error_setup_segs: -error_setup_sizes: - return result; -} - -/* - * - * - * rpipe->seg_lock is held! - */ -static int __wa_seg_submit(struct wa_rpipe *rpipe, struct wa_xfer *xfer, - struct wa_seg *seg, int *dto_done) -{ - int result; - - /* default to done unless we encounter a multi-frame isoc segment. */ - *dto_done = 1; - - /* - * Take a ref for each segment urb so the xfer cannot disappear until - * all of the callbacks run. - */ - wa_xfer_get(xfer); - /* submit the transfer request. */ - seg->status = WA_SEG_SUBMITTED; - result = usb_submit_urb(&seg->tr_urb, GFP_ATOMIC); - if (result < 0) { - pr_err("%s: xfer %p#%u: REQ submit failed: %d\n", - __func__, xfer, seg->index, result); - wa_xfer_put(xfer); - goto error_tr_submit; - } - /* submit the isoc packet descriptor if present. */ - if (seg->isoc_pack_desc_urb) { - wa_xfer_get(xfer); - result = usb_submit_urb(seg->isoc_pack_desc_urb, GFP_ATOMIC); - seg->isoc_frame_index = 0; - if (result < 0) { - pr_err("%s: xfer %p#%u: ISO packet descriptor submit failed: %d\n", - __func__, xfer, seg->index, result); - wa_xfer_put(xfer); - goto error_iso_pack_desc_submit; - } - } - /* submit the out data if this is an out request. */ - if (seg->dto_urb) { - struct wahc *wa = xfer->wa; - wa_xfer_get(xfer); - result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC); - if (result < 0) { - pr_err("%s: xfer %p#%u: DTO submit failed: %d\n", - __func__, xfer, seg->index, result); - wa_xfer_put(xfer); - goto error_dto_submit; - } - /* - * If this segment contains more than one isoc frame, hold - * onto the dto resource until we send all frames. - * Only applies to non-Alereon devices. - */ - if (((wa->quirks & WUSB_QUIRK_ALEREON_HWA_CONCAT_ISOC) == 0) - && (seg->isoc_frame_count > 1)) - *dto_done = 0; - } - rpipe_avail_dec(rpipe); - return 0; - -error_dto_submit: - usb_unlink_urb(seg->isoc_pack_desc_urb); -error_iso_pack_desc_submit: - usb_unlink_urb(&seg->tr_urb); -error_tr_submit: - seg->status = WA_SEG_ERROR; - seg->result = result; - *dto_done = 1; - return result; -} - -/* - * Execute more queued request segments until the maximum concurrent allowed. - * Return true if the DTO resource was acquired and released. - * - * The ugly unlock/lock sequence on the error path is needed as the - * xfer->lock normally nests the seg_lock and not viceversa. - */ -static int __wa_xfer_delayed_run(struct wa_rpipe *rpipe, int *dto_waiting) -{ - int result, dto_acquired = 0, dto_done = 0; - struct device *dev = &rpipe->wa->usb_iface->dev; - struct wa_seg *seg; - struct wa_xfer *xfer; - unsigned long flags; - - *dto_waiting = 0; - - spin_lock_irqsave(&rpipe->seg_lock, flags); - while (atomic_read(&rpipe->segs_available) > 0 - && !list_empty(&rpipe->seg_list) - && (dto_acquired = __wa_dto_try_get(rpipe->wa))) { - seg = list_first_entry(&(rpipe->seg_list), struct wa_seg, - list_node); - list_del(&seg->list_node); - xfer = seg->xfer; - /* - * Get a reference to the xfer in case the callbacks for the - * URBs submitted by __wa_seg_submit attempt to complete - * the xfer before this function completes. - */ - wa_xfer_get(xfer); - result = __wa_seg_submit(rpipe, xfer, seg, &dto_done); - /* release the dto resource if this RPIPE is done with it. */ - if (dto_done) - __wa_dto_put(rpipe->wa); - dev_dbg(dev, "xfer %p ID %08X#%u submitted from delayed [%d segments available] %d\n", - xfer, wa_xfer_id(xfer), seg->index, - atomic_read(&rpipe->segs_available), result); - if (unlikely(result < 0)) { - int done; - - spin_unlock_irqrestore(&rpipe->seg_lock, flags); - spin_lock_irqsave(&xfer->lock, flags); - __wa_xfer_abort(xfer); - /* - * This seg was marked as submitted when it was put on - * the RPIPE seg_list. Mark it done. - */ - xfer->segs_done++; - done = __wa_xfer_is_done(xfer); - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - spin_lock_irqsave(&rpipe->seg_lock, flags); - } - wa_xfer_put(xfer); - } - /* - * Mark this RPIPE as waiting if dto was not acquired, there are - * delayed segs and no active transfers to wake us up later. - */ - if (!dto_acquired && !list_empty(&rpipe->seg_list) - && (atomic_read(&rpipe->segs_available) == - le16_to_cpu(rpipe->descr.wRequests))) - *dto_waiting = 1; - - spin_unlock_irqrestore(&rpipe->seg_lock, flags); - - return dto_done; -} - -static void wa_xfer_delayed_run(struct wa_rpipe *rpipe) -{ - int dto_waiting; - int dto_done = __wa_xfer_delayed_run(rpipe, &dto_waiting); - - /* - * If this RPIPE is waiting on the DTO resource, add it to the tail of - * the waiting list. - * Otherwise, if the WA DTO resource was acquired and released by - * __wa_xfer_delayed_run, another RPIPE may have attempted to acquire - * DTO and failed during that time. Check the delayed list and process - * any waiters. Start searching from the next RPIPE index. - */ - if (dto_waiting) - wa_add_delayed_rpipe(rpipe->wa, rpipe); - else if (dto_done) - wa_check_for_delayed_rpipes(rpipe->wa); -} - -/* - * - * xfer->lock is taken - * - * On failure submitting we just stop submitting and return error; - * wa_urb_enqueue_b() will execute the completion path - */ -static int __wa_xfer_submit(struct wa_xfer *xfer) -{ - int result, dto_acquired = 0, dto_done = 0, dto_waiting = 0; - struct wahc *wa = xfer->wa; - struct device *dev = &wa->usb_iface->dev; - unsigned cnt; - struct wa_seg *seg; - unsigned long flags; - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - size_t maxrequests = le16_to_cpu(rpipe->descr.wRequests); - u8 available; - u8 empty; - - spin_lock_irqsave(&wa->xfer_list_lock, flags); - list_add_tail(&xfer->list_node, &wa->xfer_list); - spin_unlock_irqrestore(&wa->xfer_list_lock, flags); - - BUG_ON(atomic_read(&rpipe->segs_available) > maxrequests); - result = 0; - spin_lock_irqsave(&rpipe->seg_lock, flags); - for (cnt = 0; cnt < xfer->segs; cnt++) { - int delay_seg = 1; - - available = atomic_read(&rpipe->segs_available); - empty = list_empty(&rpipe->seg_list); - seg = xfer->seg[cnt]; - if (available && empty) { - /* - * Only attempt to acquire DTO if we have a segment - * to send. - */ - dto_acquired = __wa_dto_try_get(rpipe->wa); - if (dto_acquired) { - delay_seg = 0; - result = __wa_seg_submit(rpipe, xfer, seg, - &dto_done); - dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u submitted\n", - xfer, wa_xfer_id(xfer), cnt, available, - empty); - if (dto_done) - __wa_dto_put(rpipe->wa); - - if (result < 0) { - __wa_xfer_abort(xfer); - goto error_seg_submit; - } - } - } - - if (delay_seg) { - dev_dbg(dev, "xfer %p ID 0x%08X#%u: available %u empty %u delayed\n", - xfer, wa_xfer_id(xfer), cnt, available, empty); - seg->status = WA_SEG_DELAYED; - list_add_tail(&seg->list_node, &rpipe->seg_list); - } - xfer->segs_submitted++; - } -error_seg_submit: - /* - * Mark this RPIPE as waiting if dto was not acquired, there are - * delayed segs and no active transfers to wake us up later. - */ - if (!dto_acquired && !list_empty(&rpipe->seg_list) - && (atomic_read(&rpipe->segs_available) == - le16_to_cpu(rpipe->descr.wRequests))) - dto_waiting = 1; - spin_unlock_irqrestore(&rpipe->seg_lock, flags); - - if (dto_waiting) - wa_add_delayed_rpipe(rpipe->wa, rpipe); - else if (dto_done) - wa_check_for_delayed_rpipes(rpipe->wa); - - return result; -} - -/* - * Second part of a URB/transfer enqueuement - * - * Assumes this comes from wa_urb_enqueue() [maybe through - * wa_urb_enqueue_run()]. At this point: - * - * xfer->wa filled and refcounted - * xfer->ep filled with rpipe refcounted if - * delayed == 0 - * xfer->urb filled and refcounted (this is the case when called - * from wa_urb_enqueue() as we come from usb_submit_urb() - * and when called by wa_urb_enqueue_run(), as we took an - * extra ref dropped by _run() after we return). - * xfer->gfp filled - * - * If we fail at __wa_xfer_submit(), then we just check if we are done - * and if so, we run the completion procedure. However, if we are not - * yet done, we do nothing and wait for the completion handlers from - * the submitted URBs or from the xfer-result path to kick in. If xfer - * result never kicks in, the xfer will timeout from the USB code and - * dequeue() will be called. - */ -static int wa_urb_enqueue_b(struct wa_xfer *xfer) -{ - int result; - unsigned long flags; - struct urb *urb = xfer->urb; - struct wahc *wa = xfer->wa; - struct wusbhc *wusbhc = wa->wusb; - struct wusb_dev *wusb_dev; - unsigned done; - - result = rpipe_get_by_ep(wa, xfer->ep, urb, xfer->gfp); - if (result < 0) { - pr_err("%s: error_rpipe_get\n", __func__); - goto error_rpipe_get; - } - result = -ENODEV; - /* FIXME: segmentation broken -- kills DWA */ - mutex_lock(&wusbhc->mutex); /* get a WUSB dev */ - if (urb->dev == NULL) { - mutex_unlock(&wusbhc->mutex); - pr_err("%s: error usb dev gone\n", __func__); - goto error_dev_gone; - } - wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, urb->dev); - if (wusb_dev == NULL) { - mutex_unlock(&wusbhc->mutex); - dev_err(&(urb->dev->dev), "%s: error wusb dev gone\n", - __func__); - goto error_dev_gone; - } - mutex_unlock(&wusbhc->mutex); - - spin_lock_irqsave(&xfer->lock, flags); - xfer->wusb_dev = wusb_dev; - result = urb->status; - if (urb->status != -EINPROGRESS) { - dev_err(&(urb->dev->dev), "%s: error_dequeued\n", __func__); - goto error_dequeued; - } - - result = __wa_xfer_setup(xfer, urb); - if (result < 0) { - dev_err(&(urb->dev->dev), "%s: error_xfer_setup\n", __func__); - goto error_xfer_setup; - } - /* - * Get a xfer reference since __wa_xfer_submit starts asynchronous - * operations that may try to complete the xfer before this function - * exits. - */ - wa_xfer_get(xfer); - result = __wa_xfer_submit(xfer); - if (result < 0) { - dev_err(&(urb->dev->dev), "%s: error_xfer_submit\n", __func__); - goto error_xfer_submit; - } - spin_unlock_irqrestore(&xfer->lock, flags); - wa_xfer_put(xfer); - return 0; - - /* - * this is basically wa_xfer_completion() broken up wa_xfer_giveback() - * does a wa_xfer_put() that will call wa_xfer_destroy() and undo - * setup(). - */ -error_xfer_setup: -error_dequeued: - spin_unlock_irqrestore(&xfer->lock, flags); - /* FIXME: segmentation broken, kills DWA */ - if (wusb_dev) - wusb_dev_put(wusb_dev); -error_dev_gone: - rpipe_put(xfer->ep->hcpriv); -error_rpipe_get: - xfer->result = result; - return result; - -error_xfer_submit: - done = __wa_xfer_is_done(xfer); - xfer->result = result; - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - wa_xfer_put(xfer); - /* return success since the completion routine will run. */ - return 0; -} - -/* - * Execute the delayed transfers in the Wire Adapter @wa - * - * We need to be careful here, as dequeue() could be called in the - * middle. That's why we do the whole thing under the - * wa->xfer_list_lock. If dequeue() jumps in, it first locks xfer->lock - * and then checks the list -- so as we would be acquiring in inverse - * order, we move the delayed list to a separate list while locked and then - * submit them without the list lock held. - */ -void wa_urb_enqueue_run(struct work_struct *ws) -{ - struct wahc *wa = container_of(ws, struct wahc, xfer_enqueue_work); - struct wa_xfer *xfer, *next; - struct urb *urb; - LIST_HEAD(tmp_list); - - /* Create a copy of the wa->xfer_delayed_list while holding the lock */ - spin_lock_irq(&wa->xfer_list_lock); - list_cut_position(&tmp_list, &wa->xfer_delayed_list, - wa->xfer_delayed_list.prev); - spin_unlock_irq(&wa->xfer_list_lock); - - /* - * enqueue from temp list without list lock held since wa_urb_enqueue_b - * can take xfer->lock as well as lock mutexes. - */ - list_for_each_entry_safe(xfer, next, &tmp_list, list_node) { - list_del_init(&xfer->list_node); - - urb = xfer->urb; - if (wa_urb_enqueue_b(xfer) < 0) - wa_xfer_giveback(xfer); - usb_put_urb(urb); /* taken when queuing */ - } -} -EXPORT_SYMBOL_GPL(wa_urb_enqueue_run); - -/* - * Process the errored transfers on the Wire Adapter outside of interrupt. - */ -void wa_process_errored_transfers_run(struct work_struct *ws) -{ - struct wahc *wa = container_of(ws, struct wahc, xfer_error_work); - struct wa_xfer *xfer, *next; - LIST_HEAD(tmp_list); - - pr_info("%s: Run delayed STALL processing.\n", __func__); - - /* Create a copy of the wa->xfer_errored_list while holding the lock */ - spin_lock_irq(&wa->xfer_list_lock); - list_cut_position(&tmp_list, &wa->xfer_errored_list, - wa->xfer_errored_list.prev); - spin_unlock_irq(&wa->xfer_list_lock); - - /* - * run rpipe_clear_feature_stalled from temp list without list lock - * held. - */ - list_for_each_entry_safe(xfer, next, &tmp_list, list_node) { - struct usb_host_endpoint *ep; - unsigned long flags; - struct wa_rpipe *rpipe; - - spin_lock_irqsave(&xfer->lock, flags); - ep = xfer->ep; - rpipe = ep->hcpriv; - spin_unlock_irqrestore(&xfer->lock, flags); - - /* clear RPIPE feature stalled without holding a lock. */ - rpipe_clear_feature_stalled(wa, ep); - - /* complete the xfer. This removes it from the tmp list. */ - wa_xfer_completion(xfer); - - /* check for work. */ - wa_xfer_delayed_run(rpipe); - } -} -EXPORT_SYMBOL_GPL(wa_process_errored_transfers_run); - -/* - * Submit a transfer to the Wire Adapter in a delayed way - * - * The process of enqueuing involves possible sleeps() [see - * enqueue_b(), for the rpipe_get() and the mutex_lock()]. If we are - * in an atomic section, we defer the enqueue_b() call--else we call direct. - * - * @urb: We own a reference to it done by the HCI Linux USB stack that - * will be given up by calling usb_hcd_giveback_urb() or by - * returning error from this function -> ergo we don't have to - * refcount it. - */ -int wa_urb_enqueue(struct wahc *wa, struct usb_host_endpoint *ep, - struct urb *urb, gfp_t gfp) -{ - int result; - struct device *dev = &wa->usb_iface->dev; - struct wa_xfer *xfer; - unsigned long my_flags; - unsigned cant_sleep = irqs_disabled() | in_atomic(); - - if ((urb->transfer_buffer == NULL) - && (urb->sg == NULL) - && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) - && urb->transfer_buffer_length != 0) { - dev_err(dev, "BUG? urb %p: NULL xfer buffer & NODMA\n", urb); - dump_stack(); - } - - spin_lock_irqsave(&wa->xfer_list_lock, my_flags); - result = usb_hcd_link_urb_to_ep(&(wa->wusb->usb_hcd), urb); - spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); - if (result < 0) - goto error_link_urb; - - result = -ENOMEM; - xfer = kzalloc(sizeof(*xfer), gfp); - if (xfer == NULL) - goto error_kmalloc; - - result = -ENOENT; - if (urb->status != -EINPROGRESS) /* cancelled */ - goto error_dequeued; /* before starting? */ - wa_xfer_init(xfer); - xfer->wa = wa_get(wa); - xfer->urb = urb; - xfer->gfp = gfp; - xfer->ep = ep; - urb->hcpriv = xfer; - - dev_dbg(dev, "xfer %p urb %p pipe 0x%02x [%d bytes] %s %s %s\n", - xfer, urb, urb->pipe, urb->transfer_buffer_length, - urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP ? "dma" : "nodma", - urb->pipe & USB_DIR_IN ? "inbound" : "outbound", - cant_sleep ? "deferred" : "inline"); - - if (cant_sleep) { - usb_get_urb(urb); - spin_lock_irqsave(&wa->xfer_list_lock, my_flags); - list_add_tail(&xfer->list_node, &wa->xfer_delayed_list); - spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); - queue_work(wusbd, &wa->xfer_enqueue_work); - } else { - result = wa_urb_enqueue_b(xfer); - if (result < 0) { - /* - * URB submit/enqueue failed. Clean up, return an - * error and do not run the callback. This avoids - * an infinite submit/complete loop. - */ - dev_err(dev, "%s: URB enqueue failed: %d\n", - __func__, result); - wa_put(xfer->wa); - wa_xfer_put(xfer); - spin_lock_irqsave(&wa->xfer_list_lock, my_flags); - usb_hcd_unlink_urb_from_ep(&(wa->wusb->usb_hcd), urb); - spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); - return result; - } - } - return 0; - -error_dequeued: - kfree(xfer); -error_kmalloc: - spin_lock_irqsave(&wa->xfer_list_lock, my_flags); - usb_hcd_unlink_urb_from_ep(&(wa->wusb->usb_hcd), urb); - spin_unlock_irqrestore(&wa->xfer_list_lock, my_flags); -error_link_urb: - return result; -} -EXPORT_SYMBOL_GPL(wa_urb_enqueue); - -/* - * Dequeue a URB and make sure uwb_hcd_giveback_urb() [completion - * handler] is called. - * - * Until a transfer goes successfully through wa_urb_enqueue() it - * needs to be dequeued with completion calling; when stuck in delayed - * or before wa_xfer_setup() is called, we need to do completion. - * - * not setup If there is no hcpriv yet, that means that that enqueue - * still had no time to set the xfer up. Because - * urb->status should be other than -EINPROGRESS, - * enqueue() will catch that and bail out. - * - * If the transfer has gone through setup, we just need to clean it - * up. If it has gone through submit(), we have to abort it [with an - * asynch request] and then make sure we cancel each segment. - * - */ -int wa_urb_dequeue(struct wahc *wa, struct urb *urb, int status) -{ - unsigned long flags; - struct wa_xfer *xfer; - struct wa_seg *seg; - struct wa_rpipe *rpipe; - unsigned cnt, done = 0, xfer_abort_pending; - unsigned rpipe_ready = 0; - int result; - - /* check if it is safe to unlink. */ - spin_lock_irqsave(&wa->xfer_list_lock, flags); - result = usb_hcd_check_unlink_urb(&(wa->wusb->usb_hcd), urb, status); - if ((result == 0) && urb->hcpriv) { - /* - * Get a xfer ref to prevent a race with wa_xfer_giveback - * cleaning up the xfer while we are working with it. - */ - wa_xfer_get(urb->hcpriv); - } - spin_unlock_irqrestore(&wa->xfer_list_lock, flags); - if (result) - return result; - - xfer = urb->hcpriv; - if (xfer == NULL) - return -ENOENT; - spin_lock_irqsave(&xfer->lock, flags); - pr_debug("%s: DEQUEUE xfer id 0x%08X\n", __func__, wa_xfer_id(xfer)); - rpipe = xfer->ep->hcpriv; - if (rpipe == NULL) { - pr_debug("%s: xfer %p id 0x%08X has no RPIPE. %s", - __func__, xfer, wa_xfer_id(xfer), - "Probably already aborted.\n" ); - result = -ENOENT; - goto out_unlock; - } - /* - * Check for done to avoid racing with wa_xfer_giveback and completing - * twice. - */ - if (__wa_xfer_is_done(xfer)) { - pr_debug("%s: xfer %p id 0x%08X already done.\n", __func__, - xfer, wa_xfer_id(xfer)); - result = -ENOENT; - goto out_unlock; - } - /* Check the delayed list -> if there, release and complete */ - spin_lock(&wa->xfer_list_lock); - if (!list_empty(&xfer->list_node) && xfer->seg == NULL) - goto dequeue_delayed; - spin_unlock(&wa->xfer_list_lock); - if (xfer->seg == NULL) /* still hasn't reached */ - goto out_unlock; /* setup(), enqueue_b() completes */ - /* Ok, the xfer is in flight already, it's been setup and submitted.*/ - xfer_abort_pending = __wa_xfer_abort(xfer) >= 0; - /* - * grab the rpipe->seg_lock here to prevent racing with - * __wa_xfer_delayed_run. - */ - spin_lock(&rpipe->seg_lock); - for (cnt = 0; cnt < xfer->segs; cnt++) { - seg = xfer->seg[cnt]; - pr_debug("%s: xfer id 0x%08X#%d status = %d\n", - __func__, wa_xfer_id(xfer), cnt, seg->status); - switch (seg->status) { - case WA_SEG_NOTREADY: - case WA_SEG_READY: - printk(KERN_ERR "xfer %p#%u: dequeue bad state %u\n", - xfer, cnt, seg->status); - WARN_ON(1); - break; - case WA_SEG_DELAYED: - /* - * delete from rpipe delayed list. If no segments on - * this xfer have been submitted, __wa_xfer_is_done will - * trigger a giveback below. Otherwise, the submitted - * segments will be completed in the DTI interrupt. - */ - seg->status = WA_SEG_ABORTED; - seg->result = -ENOENT; - list_del(&seg->list_node); - xfer->segs_done++; - break; - case WA_SEG_DONE: - case WA_SEG_ERROR: - case WA_SEG_ABORTED: - break; - /* - * The buf_in data for a segment in the - * WA_SEG_DTI_PENDING state is actively being read. - * Let wa_buf_in_cb handle it since it will be called - * and will increment xfer->segs_done. Cleaning up - * here could cause wa_buf_in_cb to access the xfer - * after it has been completed/freed. - */ - case WA_SEG_DTI_PENDING: - break; - /* - * In the states below, the HWA device already knows - * about the transfer. If an abort request was sent, - * allow the HWA to process it and wait for the - * results. Otherwise, the DTI state and seg completed - * counts can get out of sync. - */ - case WA_SEG_SUBMITTED: - case WA_SEG_PENDING: - /* - * Check if the abort was successfully sent. This could - * be false if the HWA has been removed but we haven't - * gotten the disconnect notification yet. - */ - if (!xfer_abort_pending) { - seg->status = WA_SEG_ABORTED; - rpipe_ready = rpipe_avail_inc(rpipe); - xfer->segs_done++; - } - break; - } - } - spin_unlock(&rpipe->seg_lock); - xfer->result = urb->status; /* -ENOENT or -ECONNRESET */ - done = __wa_xfer_is_done(xfer); - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - wa_xfer_put(xfer); - return result; - -out_unlock: - spin_unlock_irqrestore(&xfer->lock, flags); - wa_xfer_put(xfer); - return result; - -dequeue_delayed: - list_del_init(&xfer->list_node); - spin_unlock(&wa->xfer_list_lock); - xfer->result = urb->status; - spin_unlock_irqrestore(&xfer->lock, flags); - wa_xfer_giveback(xfer); - wa_xfer_put(xfer); - usb_put_urb(urb); /* we got a ref in enqueue() */ - return 0; -} -EXPORT_SYMBOL_GPL(wa_urb_dequeue); - -/* - * Translation from WA status codes (WUSB1.0 Table 8.15) to errno - * codes - * - * Positive errno values are internal inconsistencies and should be - * flagged louder. Negative are to be passed up to the user in the - * normal way. - * - * @status: USB WA status code -- high two bits are stripped. - */ -static int wa_xfer_status_to_errno(u8 status) -{ - int errno; - u8 real_status = status; - static int xlat[] = { - [WA_XFER_STATUS_SUCCESS] = 0, - [WA_XFER_STATUS_HALTED] = -EPIPE, - [WA_XFER_STATUS_DATA_BUFFER_ERROR] = -ENOBUFS, - [WA_XFER_STATUS_BABBLE] = -EOVERFLOW, - [WA_XFER_RESERVED] = EINVAL, - [WA_XFER_STATUS_NOT_FOUND] = 0, - [WA_XFER_STATUS_INSUFFICIENT_RESOURCE] = -ENOMEM, - [WA_XFER_STATUS_TRANSACTION_ERROR] = -EILSEQ, - [WA_XFER_STATUS_ABORTED] = -ENOENT, - [WA_XFER_STATUS_RPIPE_NOT_READY] = EINVAL, - [WA_XFER_INVALID_FORMAT] = EINVAL, - [WA_XFER_UNEXPECTED_SEGMENT_NUMBER] = EINVAL, - [WA_XFER_STATUS_RPIPE_TYPE_MISMATCH] = EINVAL, - }; - status &= 0x3f; - - if (status == 0) - return 0; - if (status >= ARRAY_SIZE(xlat)) { - printk_ratelimited(KERN_ERR "%s(): BUG? " - "Unknown WA transfer status 0x%02x\n", - __func__, real_status); - return -EINVAL; - } - errno = xlat[status]; - if (unlikely(errno > 0)) { - printk_ratelimited(KERN_ERR "%s(): BUG? " - "Inconsistent WA status: 0x%02x\n", - __func__, real_status); - errno = -errno; - } - return errno; -} - -/* - * If a last segment flag and/or a transfer result error is encountered, - * no other segment transfer results will be returned from the device. - * Mark the remaining submitted or pending xfers as completed so that - * the xfer will complete cleanly. - * - * xfer->lock must be held - * - */ -static void wa_complete_remaining_xfer_segs(struct wa_xfer *xfer, - int starting_index, enum wa_seg_status status) -{ - int index; - struct wa_rpipe *rpipe = xfer->ep->hcpriv; - - for (index = starting_index; index < xfer->segs_submitted; index++) { - struct wa_seg *current_seg = xfer->seg[index]; - - BUG_ON(current_seg == NULL); - - switch (current_seg->status) { - case WA_SEG_SUBMITTED: - case WA_SEG_PENDING: - case WA_SEG_DTI_PENDING: - rpipe_avail_inc(rpipe); - /* - * do not increment RPIPE avail for the WA_SEG_DELAYED case - * since it has not been submitted to the RPIPE. - */ - /* fall through */ - case WA_SEG_DELAYED: - xfer->segs_done++; - current_seg->status = status; - break; - case WA_SEG_ABORTED: - break; - default: - WARN(1, "%s: xfer 0x%08X#%d. bad seg status = %d\n", - __func__, wa_xfer_id(xfer), index, - current_seg->status); - break; - } - } -} - -/* Populate the given urb based on the current isoc transfer state. */ -static int __wa_populate_buf_in_urb_isoc(struct wahc *wa, - struct urb *buf_in_urb, struct wa_xfer *xfer, struct wa_seg *seg) -{ - int urb_start_frame = seg->isoc_frame_index + seg->isoc_frame_offset; - int seg_index, total_len = 0, urb_frame_index = urb_start_frame; - struct usb_iso_packet_descriptor *iso_frame_desc = - xfer->urb->iso_frame_desc; - const int dti_packet_size = usb_endpoint_maxp(wa->dti_epd); - int next_frame_contiguous; - struct usb_iso_packet_descriptor *iso_frame; - - BUG_ON(buf_in_urb->status == -EINPROGRESS); - - /* - * If the current frame actual_length is contiguous with the next frame - * and actual_length is a multiple of the DTI endpoint max packet size, - * combine the current frame with the next frame in a single URB. This - * reduces the number of URBs that must be submitted in that case. - */ - seg_index = seg->isoc_frame_index; - do { - next_frame_contiguous = 0; - - iso_frame = &iso_frame_desc[urb_frame_index]; - total_len += iso_frame->actual_length; - ++urb_frame_index; - ++seg_index; - - if (seg_index < seg->isoc_frame_count) { - struct usb_iso_packet_descriptor *next_iso_frame; - - next_iso_frame = &iso_frame_desc[urb_frame_index]; - - if ((iso_frame->offset + iso_frame->actual_length) == - next_iso_frame->offset) - next_frame_contiguous = 1; - } - } while (next_frame_contiguous - && ((iso_frame->actual_length % dti_packet_size) == 0)); - - /* this should always be 0 before a resubmit. */ - buf_in_urb->num_mapped_sgs = 0; - buf_in_urb->transfer_dma = xfer->urb->transfer_dma + - iso_frame_desc[urb_start_frame].offset; - buf_in_urb->transfer_buffer_length = total_len; - buf_in_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - buf_in_urb->transfer_buffer = NULL; - buf_in_urb->sg = NULL; - buf_in_urb->num_sgs = 0; - buf_in_urb->context = seg; - - /* return the number of frames included in this URB. */ - return seg_index - seg->isoc_frame_index; -} - -/* Populate the given urb based on the current transfer state. */ -static int wa_populate_buf_in_urb(struct urb *buf_in_urb, struct wa_xfer *xfer, - unsigned int seg_idx, unsigned int bytes_transferred) -{ - int result = 0; - struct wa_seg *seg = xfer->seg[seg_idx]; - - BUG_ON(buf_in_urb->status == -EINPROGRESS); - /* this should always be 0 before a resubmit. */ - buf_in_urb->num_mapped_sgs = 0; - - if (xfer->is_dma) { - buf_in_urb->transfer_dma = xfer->urb->transfer_dma - + (seg_idx * xfer->seg_size); - buf_in_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - buf_in_urb->transfer_buffer = NULL; - buf_in_urb->sg = NULL; - buf_in_urb->num_sgs = 0; - } else { - /* do buffer or SG processing. */ - buf_in_urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP; - - if (xfer->urb->transfer_buffer) { - buf_in_urb->transfer_buffer = - xfer->urb->transfer_buffer - + (seg_idx * xfer->seg_size); - buf_in_urb->sg = NULL; - buf_in_urb->num_sgs = 0; - } else { - /* allocate an SG list to store seg_size bytes - and copy the subset of the xfer->urb->sg - that matches the buffer subset we are - about to read. */ - buf_in_urb->sg = wa_xfer_create_subset_sg( - xfer->urb->sg, - seg_idx * xfer->seg_size, - bytes_transferred, - &(buf_in_urb->num_sgs)); - - if (!(buf_in_urb->sg)) { - buf_in_urb->num_sgs = 0; - result = -ENOMEM; - } - buf_in_urb->transfer_buffer = NULL; - } - } - buf_in_urb->transfer_buffer_length = bytes_transferred; - buf_in_urb->context = seg; - - return result; -} - -/* - * Process a xfer result completion message - * - * inbound transfers: need to schedule a buf_in_urb read - * - * FIXME: this function needs to be broken up in parts - */ -static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer, - struct wa_xfer_result *xfer_result) -{ - int result; - struct device *dev = &wa->usb_iface->dev; - unsigned long flags; - unsigned int seg_idx; - struct wa_seg *seg; - struct wa_rpipe *rpipe; - unsigned done = 0; - u8 usb_status; - unsigned rpipe_ready = 0; - unsigned bytes_transferred = le32_to_cpu(xfer_result->dwTransferLength); - struct urb *buf_in_urb = &(wa->buf_in_urbs[0]); - - spin_lock_irqsave(&xfer->lock, flags); - seg_idx = xfer_result->bTransferSegment & 0x7f; - if (unlikely(seg_idx >= xfer->segs)) - goto error_bad_seg; - seg = xfer->seg[seg_idx]; - rpipe = xfer->ep->hcpriv; - usb_status = xfer_result->bTransferStatus; - dev_dbg(dev, "xfer %p ID 0x%08X#%u: bTransferStatus 0x%02x (seg status %u)\n", - xfer, wa_xfer_id(xfer), seg_idx, usb_status, seg->status); - if (seg->status == WA_SEG_ABORTED - || seg->status == WA_SEG_ERROR) /* already handled */ - goto segment_aborted; - if (seg->status == WA_SEG_SUBMITTED) /* ops, got here */ - seg->status = WA_SEG_PENDING; /* before wa_seg{_dto}_cb() */ - if (seg->status != WA_SEG_PENDING) { - if (printk_ratelimit()) - dev_err(dev, "xfer %p#%u: Bad segment state %u\n", - xfer, seg_idx, seg->status); - seg->status = WA_SEG_PENDING; /* workaround/"fix" it */ - } - if (usb_status & 0x80) { - seg->result = wa_xfer_status_to_errno(usb_status); - dev_err(dev, "DTI: xfer %p 0x%08X:#%u failed (0x%02x)\n", - xfer, xfer->id, seg->index, usb_status); - seg->status = ((usb_status & 0x7F) == WA_XFER_STATUS_ABORTED) ? - WA_SEG_ABORTED : WA_SEG_ERROR; - goto error_complete; - } - /* FIXME: we ignore warnings, tally them for stats */ - if (usb_status & 0x40) /* Warning?... */ - usb_status = 0; /* ... pass */ - /* - * If the last segment bit is set, complete the remaining segments. - * When the current segment is completed, either in wa_buf_in_cb for - * transfers with data or below for no data, the xfer will complete. - */ - if (xfer_result->bTransferSegment & 0x80) - wa_complete_remaining_xfer_segs(xfer, seg->index + 1, - WA_SEG_DONE); - if (usb_pipeisoc(xfer->urb->pipe) - && (le32_to_cpu(xfer_result->dwNumOfPackets) > 0)) { - /* set up WA state to read the isoc packet status next. */ - wa->dti_isoc_xfer_in_progress = wa_xfer_id(xfer); - wa->dti_isoc_xfer_seg = seg_idx; - wa->dti_state = WA_DTI_ISOC_PACKET_STATUS_PENDING; - } else if (xfer->is_inbound && !usb_pipeisoc(xfer->urb->pipe) - && (bytes_transferred > 0)) { - /* IN data phase: read to buffer */ - seg->status = WA_SEG_DTI_PENDING; - result = wa_populate_buf_in_urb(buf_in_urb, xfer, seg_idx, - bytes_transferred); - if (result < 0) - goto error_buf_in_populate; - ++(wa->active_buf_in_urbs); - result = usb_submit_urb(buf_in_urb, GFP_ATOMIC); - if (result < 0) { - --(wa->active_buf_in_urbs); - goto error_submit_buf_in; - } - } else { - /* OUT data phase or no data, complete it -- */ - seg->result = bytes_transferred; - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, WA_SEG_DONE); - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - return; - -error_submit_buf_in: - if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { - dev_err(dev, "DTI: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - } - if (printk_ratelimit()) - dev_err(dev, "xfer %p#%u: can't submit DTI data phase: %d\n", - xfer, seg_idx, result); - seg->result = result; - kfree(buf_in_urb->sg); - buf_in_urb->sg = NULL; -error_buf_in_populate: - __wa_xfer_abort(xfer); - seg->status = WA_SEG_ERROR; -error_complete: - xfer->segs_done++; - rpipe_ready = rpipe_avail_inc(rpipe); - wa_complete_remaining_xfer_segs(xfer, seg->index + 1, seg->status); - done = __wa_xfer_is_done(xfer); - /* - * queue work item to clear STALL for control endpoints. - * Otherwise, let endpoint_reset take care of it. - */ - if (((usb_status & 0x3f) == WA_XFER_STATUS_HALTED) && - usb_endpoint_xfer_control(&xfer->ep->desc) && - done) { - - dev_info(dev, "Control EP stall. Queue delayed work.\n"); - spin_lock(&wa->xfer_list_lock); - /* move xfer from xfer_list to xfer_errored_list. */ - list_move_tail(&xfer->list_node, &wa->xfer_errored_list); - spin_unlock(&wa->xfer_list_lock); - spin_unlock_irqrestore(&xfer->lock, flags); - queue_work(wusbd, &wa->xfer_error_work); - } else { - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - } - - return; - -error_bad_seg: - spin_unlock_irqrestore(&xfer->lock, flags); - wa_urb_dequeue(wa, xfer->urb, -ENOENT); - if (printk_ratelimit()) - dev_err(dev, "xfer %p#%u: bad segment\n", xfer, seg_idx); - if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME)) { - dev_err(dev, "DTI: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - } - return; - -segment_aborted: - /* nothing to do, as the aborter did the completion */ - spin_unlock_irqrestore(&xfer->lock, flags); -} - -/* - * Process a isochronous packet status message - * - * inbound transfers: need to schedule a buf_in_urb read - */ -static int wa_process_iso_packet_status(struct wahc *wa, struct urb *urb) -{ - struct device *dev = &wa->usb_iface->dev; - struct wa_xfer_packet_status_hwaiso *packet_status; - struct wa_xfer_packet_status_len_hwaiso *status_array; - struct wa_xfer *xfer; - unsigned long flags; - struct wa_seg *seg; - struct wa_rpipe *rpipe; - unsigned done = 0, dti_busy = 0, data_frame_count = 0, seg_index; - unsigned first_frame_index = 0, rpipe_ready = 0; - size_t expected_size; - - /* We have a xfer result buffer; check it */ - dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n", - urb->actual_length, urb->transfer_buffer); - packet_status = (struct wa_xfer_packet_status_hwaiso *)(wa->dti_buf); - if (packet_status->bPacketType != WA_XFER_ISO_PACKET_STATUS) { - dev_err(dev, "DTI Error: isoc packet status--bad type 0x%02x\n", - packet_status->bPacketType); - goto error_parse_buffer; - } - xfer = wa_xfer_get_by_id(wa, wa->dti_isoc_xfer_in_progress); - if (xfer == NULL) { - dev_err(dev, "DTI Error: isoc packet status--unknown xfer 0x%08x\n", - wa->dti_isoc_xfer_in_progress); - goto error_parse_buffer; - } - spin_lock_irqsave(&xfer->lock, flags); - if (unlikely(wa->dti_isoc_xfer_seg >= xfer->segs)) - goto error_bad_seg; - seg = xfer->seg[wa->dti_isoc_xfer_seg]; - rpipe = xfer->ep->hcpriv; - expected_size = struct_size(packet_status, PacketStatus, - seg->isoc_frame_count); - if (urb->actual_length != expected_size) { - dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d bytes vs %zu needed)\n", - urb->actual_length, expected_size); - goto error_bad_seg; - } - if (le16_to_cpu(packet_status->wLength) != expected_size) { - dev_err(dev, "DTI Error: isoc packet status--bad length %u\n", - le16_to_cpu(packet_status->wLength)); - goto error_bad_seg; - } - /* write isoc packet status and lengths back to the xfer urb. */ - status_array = packet_status->PacketStatus; - xfer->urb->start_frame = - wa->wusb->usb_hcd.driver->get_frame_number(&wa->wusb->usb_hcd); - for (seg_index = 0; seg_index < seg->isoc_frame_count; ++seg_index) { - struct usb_iso_packet_descriptor *iso_frame_desc = - xfer->urb->iso_frame_desc; - const int xfer_frame_index = - seg->isoc_frame_offset + seg_index; - - iso_frame_desc[xfer_frame_index].status = - wa_xfer_status_to_errno( - le16_to_cpu(status_array[seg_index].PacketStatus)); - iso_frame_desc[xfer_frame_index].actual_length = - le16_to_cpu(status_array[seg_index].PacketLength); - /* track the number of frames successfully transferred. */ - if (iso_frame_desc[xfer_frame_index].actual_length > 0) { - /* save the starting frame index for buf_in_urb. */ - if (!data_frame_count) - first_frame_index = seg_index; - ++data_frame_count; - } - } - - if (xfer->is_inbound && data_frame_count) { - int result, total_frames_read = 0, urb_index = 0; - struct urb *buf_in_urb; - - /* IN data phase: read to buffer */ - seg->status = WA_SEG_DTI_PENDING; - - /* start with the first frame with data. */ - seg->isoc_frame_index = first_frame_index; - /* submit up to WA_MAX_BUF_IN_URBS read URBs. */ - do { - int urb_frame_index, urb_frame_count; - struct usb_iso_packet_descriptor *iso_frame_desc; - - buf_in_urb = &(wa->buf_in_urbs[urb_index]); - urb_frame_count = __wa_populate_buf_in_urb_isoc(wa, - buf_in_urb, xfer, seg); - /* advance frame index to start of next read URB. */ - seg->isoc_frame_index += urb_frame_count; - total_frames_read += urb_frame_count; - - ++(wa->active_buf_in_urbs); - result = usb_submit_urb(buf_in_urb, GFP_ATOMIC); - - /* skip 0-byte frames. */ - urb_frame_index = - seg->isoc_frame_offset + seg->isoc_frame_index; - iso_frame_desc = - &(xfer->urb->iso_frame_desc[urb_frame_index]); - while ((seg->isoc_frame_index < - seg->isoc_frame_count) && - (iso_frame_desc->actual_length == 0)) { - ++(seg->isoc_frame_index); - ++iso_frame_desc; - } - ++urb_index; - - } while ((result == 0) && (urb_index < WA_MAX_BUF_IN_URBS) - && (seg->isoc_frame_index < - seg->isoc_frame_count)); - - if (result < 0) { - --(wa->active_buf_in_urbs); - dev_err(dev, "DTI Error: Could not submit buf in URB (%d)", - result); - wa_reset_all(wa); - } else if (data_frame_count > total_frames_read) - /* If we need to read more frames, set DTI busy. */ - dti_busy = 1; - } else { - /* OUT transfer or no more IN data, complete it -- */ - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, WA_SEG_DONE); - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (dti_busy) - wa->dti_state = WA_DTI_BUF_IN_DATA_PENDING; - else - wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING; - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - wa_xfer_put(xfer); - return dti_busy; - -error_bad_seg: - spin_unlock_irqrestore(&xfer->lock, flags); - wa_xfer_put(xfer); -error_parse_buffer: - return dti_busy; -} - -/* - * Callback for the IN data phase - * - * If successful transition state; otherwise, take a note of the - * error, mark this segment done and try completion. - * - * Note we don't access until we are sure that the transfer hasn't - * been cancelled (ECONNRESET, ENOENT), which could mean that - * seg->xfer could be already gone. - */ -static void wa_buf_in_cb(struct urb *urb) -{ - struct wa_seg *seg = urb->context; - struct wa_xfer *xfer = seg->xfer; - struct wahc *wa; - struct device *dev; - struct wa_rpipe *rpipe; - unsigned rpipe_ready = 0, isoc_data_frame_count = 0; - unsigned long flags; - int resubmit_dti = 0, active_buf_in_urbs; - u8 done = 0; - - /* free the sg if it was used. */ - kfree(urb->sg); - urb->sg = NULL; - - spin_lock_irqsave(&xfer->lock, flags); - wa = xfer->wa; - dev = &wa->usb_iface->dev; - --(wa->active_buf_in_urbs); - active_buf_in_urbs = wa->active_buf_in_urbs; - rpipe = xfer->ep->hcpriv; - - if (usb_pipeisoc(xfer->urb->pipe)) { - struct usb_iso_packet_descriptor *iso_frame_desc = - xfer->urb->iso_frame_desc; - int seg_index; - - /* - * Find the next isoc frame with data and count how many - * frames with data remain. - */ - seg_index = seg->isoc_frame_index; - while (seg_index < seg->isoc_frame_count) { - const int urb_frame_index = - seg->isoc_frame_offset + seg_index; - - if (iso_frame_desc[urb_frame_index].actual_length > 0) { - /* save the index of the next frame with data */ - if (!isoc_data_frame_count) - seg->isoc_frame_index = seg_index; - ++isoc_data_frame_count; - } - ++seg_index; - } - } - spin_unlock_irqrestore(&xfer->lock, flags); - - switch (urb->status) { - case 0: - spin_lock_irqsave(&xfer->lock, flags); - - seg->result += urb->actual_length; - if (isoc_data_frame_count > 0) { - int result, urb_frame_count; - - /* submit a read URB for the next frame with data. */ - urb_frame_count = __wa_populate_buf_in_urb_isoc(wa, urb, - xfer, seg); - /* advance index to start of next read URB. */ - seg->isoc_frame_index += urb_frame_count; - ++(wa->active_buf_in_urbs); - result = usb_submit_urb(urb, GFP_ATOMIC); - if (result < 0) { - --(wa->active_buf_in_urbs); - dev_err(dev, "DTI Error: Could not submit buf in URB (%d)", - result); - wa_reset_all(wa); - } - /* - * If we are in this callback and - * isoc_data_frame_count > 0, it means that the dti_urb - * submission was delayed in wa_dti_cb. Once - * we submit the last buf_in_urb, we can submit the - * delayed dti_urb. - */ - resubmit_dti = (isoc_data_frame_count == - urb_frame_count); - } else if (active_buf_in_urbs == 0) { - dev_dbg(dev, - "xfer %p 0x%08X#%u: data in done (%zu bytes)\n", - xfer, wa_xfer_id(xfer), seg->index, - seg->result); - rpipe_ready = rpipe_avail_inc(rpipe); - done = __wa_xfer_mark_seg_as_done(xfer, seg, - WA_SEG_DONE); - } - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - break; - case -ECONNRESET: /* URB unlinked; no need to do anything */ - case -ENOENT: /* as it was done by the who unlinked us */ - break; - default: /* Other errors ... */ - /* - * Error on data buf read. Only resubmit DTI if it hasn't - * already been done by previously hitting this error or by a - * successful completion of the previous buf_in_urb. - */ - resubmit_dti = wa->dti_state != WA_DTI_TRANSFER_RESULT_PENDING; - spin_lock_irqsave(&xfer->lock, flags); - if (printk_ratelimit()) - dev_err(dev, "xfer %p 0x%08X#%u: data in error %d\n", - xfer, wa_xfer_id(xfer), seg->index, - urb->status); - if (edc_inc(&wa->nep_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)){ - dev_err(dev, "DTO: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - } - seg->result = urb->status; - rpipe_ready = rpipe_avail_inc(rpipe); - if (active_buf_in_urbs == 0) - done = __wa_xfer_mark_seg_as_done(xfer, seg, - WA_SEG_ERROR); - else - __wa_xfer_abort(xfer); - spin_unlock_irqrestore(&xfer->lock, flags); - if (done) - wa_xfer_completion(xfer); - if (rpipe_ready) - wa_xfer_delayed_run(rpipe); - } - - if (resubmit_dti) { - int result; - - wa->dti_state = WA_DTI_TRANSFER_RESULT_PENDING; - - result = usb_submit_urb(wa->dti_urb, GFP_ATOMIC); - if (result < 0) { - dev_err(dev, "DTI Error: Could not submit DTI URB (%d)\n", - result); - wa_reset_all(wa); - } - } -} - -/* - * Handle an incoming transfer result buffer - * - * Given a transfer result buffer, it completes the transfer (possibly - * scheduling and buffer in read) and then resubmits the DTI URB for a - * new transfer result read. - * - * - * The xfer_result DTI URB state machine - * - * States: OFF | RXR (Read-Xfer-Result) | RBI (Read-Buffer-In) - * - * We start in OFF mode, the first xfer_result notification [through - * wa_handle_notif_xfer()] moves us to RXR by posting the DTI-URB to - * read. - * - * We receive a buffer -- if it is not a xfer_result, we complain and - * repost the DTI-URB. If it is a xfer_result then do the xfer seg - * request accounting. If it is an IN segment, we move to RBI and post - * a BUF-IN-URB to the right buffer. The BUF-IN-URB callback will - * repost the DTI-URB and move to RXR state. if there was no IN - * segment, it will repost the DTI-URB. - * - * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many - * errors) in the URBs. - */ -static void wa_dti_cb(struct urb *urb) -{ - int result, dti_busy = 0; - struct wahc *wa = urb->context; - struct device *dev = &wa->usb_iface->dev; - u32 xfer_id; - u8 usb_status; - - BUG_ON(wa->dti_urb != urb); - switch (wa->dti_urb->status) { - case 0: - if (wa->dti_state == WA_DTI_TRANSFER_RESULT_PENDING) { - struct wa_xfer_result *xfer_result; - struct wa_xfer *xfer; - - /* We have a xfer result buffer; check it */ - dev_dbg(dev, "DTI: xfer result %d bytes at %p\n", - urb->actual_length, urb->transfer_buffer); - if (urb->actual_length != sizeof(*xfer_result)) { - dev_err(dev, "DTI Error: xfer result--bad size xfer result (%d bytes vs %zu needed)\n", - urb->actual_length, - sizeof(*xfer_result)); - break; - } - xfer_result = (struct wa_xfer_result *)(wa->dti_buf); - if (xfer_result->hdr.bLength != sizeof(*xfer_result)) { - dev_err(dev, "DTI Error: xfer result--bad header length %u\n", - xfer_result->hdr.bLength); - break; - } - if (xfer_result->hdr.bNotifyType != WA_XFER_RESULT) { - dev_err(dev, "DTI Error: xfer result--bad header type 0x%02x\n", - xfer_result->hdr.bNotifyType); - break; - } - xfer_id = le32_to_cpu(xfer_result->dwTransferID); - usb_status = xfer_result->bTransferStatus & 0x3f; - if (usb_status == WA_XFER_STATUS_NOT_FOUND) { - /* taken care of already */ - dev_dbg(dev, "%s: xfer 0x%08X#%u not found.\n", - __func__, xfer_id, - xfer_result->bTransferSegment & 0x7f); - break; - } - xfer = wa_xfer_get_by_id(wa, xfer_id); - if (xfer == NULL) { - /* FIXME: transaction not found. */ - dev_err(dev, "DTI Error: xfer result--unknown xfer 0x%08x (status 0x%02x)\n", - xfer_id, usb_status); - break; - } - wa_xfer_result_chew(wa, xfer, xfer_result); - wa_xfer_put(xfer); - } else if (wa->dti_state == WA_DTI_ISOC_PACKET_STATUS_PENDING) { - dti_busy = wa_process_iso_packet_status(wa, urb); - } else { - dev_err(dev, "DTI Error: unexpected EP state = %d\n", - wa->dti_state); - } - break; - case -ENOENT: /* (we killed the URB)...so, no broadcast */ - case -ESHUTDOWN: /* going away! */ - dev_dbg(dev, "DTI: going down! %d\n", urb->status); - goto out; - default: - /* Unknown error */ - if (edc_inc(&wa->dti_edc, EDC_MAX_ERRORS, - EDC_ERROR_TIMEFRAME)) { - dev_err(dev, "DTI: URB max acceptable errors " - "exceeded, resetting device\n"); - wa_reset_all(wa); - goto out; - } - if (printk_ratelimit()) - dev_err(dev, "DTI: URB error %d\n", urb->status); - break; - } - - /* Resubmit the DTI URB if we are not busy processing isoc in frames. */ - if (!dti_busy) { - result = usb_submit_urb(wa->dti_urb, GFP_ATOMIC); - if (result < 0) { - dev_err(dev, "DTI Error: Could not submit DTI URB (%d)\n", - result); - wa_reset_all(wa); - } - } -out: - return; -} - -/* - * Initialize the DTI URB for reading transfer result notifications and also - * the buffer-in URB, for reading buffers. Then we just submit the DTI URB. - */ -int wa_dti_start(struct wahc *wa) -{ - const struct usb_endpoint_descriptor *dti_epd = wa->dti_epd; - struct device *dev = &wa->usb_iface->dev; - int result = -ENOMEM, index; - - if (wa->dti_urb != NULL) /* DTI URB already started */ - goto out; - - wa->dti_urb = usb_alloc_urb(0, GFP_KERNEL); - if (wa->dti_urb == NULL) - goto error_dti_urb_alloc; - usb_fill_bulk_urb( - wa->dti_urb, wa->usb_dev, - usb_rcvbulkpipe(wa->usb_dev, 0x80 | dti_epd->bEndpointAddress), - wa->dti_buf, wa->dti_buf_size, - wa_dti_cb, wa); - - /* init the buf in URBs */ - for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index) { - usb_fill_bulk_urb( - &(wa->buf_in_urbs[index]), wa->usb_dev, - usb_rcvbulkpipe(wa->usb_dev, - 0x80 | dti_epd->bEndpointAddress), - NULL, 0, wa_buf_in_cb, wa); - } - result = usb_submit_urb(wa->dti_urb, GFP_KERNEL); - if (result < 0) { - dev_err(dev, "DTI Error: Could not submit DTI URB (%d) resetting\n", - result); - goto error_dti_urb_submit; - } -out: - return 0; - -error_dti_urb_submit: - usb_put_urb(wa->dti_urb); - wa->dti_urb = NULL; -error_dti_urb_alloc: - return result; -} -EXPORT_SYMBOL_GPL(wa_dti_start); -/* - * Transfer complete notification - * - * Called from the notif.c code. We get a notification on EP2 saying - * that some endpoint has some transfer result data available. We are - * about to read it. - * - * To speed up things, we always have a URB reading the DTI URB; we - * don't really set it up and start it until the first xfer complete - * notification arrives, which is what we do here. - * - * Follow up in wa_dti_cb(), as that's where the whole state - * machine starts. - * - * @wa shall be referenced - */ -void wa_handle_notif_xfer(struct wahc *wa, struct wa_notif_hdr *notif_hdr) -{ - struct device *dev = &wa->usb_iface->dev; - struct wa_notif_xfer *notif_xfer; - const struct usb_endpoint_descriptor *dti_epd = wa->dti_epd; - - notif_xfer = container_of(notif_hdr, struct wa_notif_xfer, hdr); - BUG_ON(notif_hdr->bNotifyType != WA_NOTIF_TRANSFER); - - if ((0x80 | notif_xfer->bEndpoint) != dti_epd->bEndpointAddress) { - /* FIXME: hardcoded limitation, adapt */ - dev_err(dev, "BUG: DTI ep is %u, not %u (hack me)\n", - notif_xfer->bEndpoint, dti_epd->bEndpointAddress); - goto error; - } - - /* attempt to start the DTI ep processing. */ - if (wa_dti_start(wa) < 0) - goto error; - - return; - -error: - wa_reset_all(wa); -} diff --git a/drivers/staging/wusbcore/wusbhc.c b/drivers/staging/wusbcore/wusbhc.c deleted file mode 100644 index d0b404d258e8..000000000000 --- a/drivers/staging/wusbcore/wusbhc.c +++ /dev/null @@ -1,490 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Host Controller - * sysfs glue, wusbcore module support and life cycle management - * - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * Creation/destruction of wusbhc is split in two parts; that that - * doesn't require the HCD to be added (wusbhc_{create,destroy}) and - * the one that requires (phase B, wusbhc_b_{create,destroy}). - * - * This is so because usb_add_hcd() will start the HC, and thus, all - * the HC specific stuff has to be already initialized (like sysfs - * thingies). - */ -#include <linux/device.h> -#include <linux/module.h> -#include "wusbhc.h" - -/** - * Extract the wusbhc that corresponds to a USB Host Controller class device - * - * WARNING! Apply only if @dev is that of a - * wusbhc.usb_hcd.self->class_dev; otherwise, you loose. - */ -static struct wusbhc *usbhc_dev_to_wusbhc(struct device *dev) -{ - struct usb_bus *usb_bus = dev_get_drvdata(dev); - struct usb_hcd *usb_hcd = bus_to_hcd(usb_bus); - return usb_hcd_to_wusbhc(usb_hcd); -} - -/* - * Show & store the current WUSB trust timeout - * - * We don't do locking--it is an 'atomic' value. - * - * The units that we store/show are always MILLISECONDS. However, the - * value of trust_timeout is jiffies. - */ -static ssize_t wusb_trust_timeout_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - - return scnprintf(buf, PAGE_SIZE, "%u\n", wusbhc->trust_timeout); -} - -static ssize_t wusb_trust_timeout_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - ssize_t result = -ENOSYS; - unsigned trust_timeout; - - result = sscanf(buf, "%u", &trust_timeout); - if (result != 1) { - result = -EINVAL; - goto out; - } - wusbhc->trust_timeout = min_t(unsigned, trust_timeout, 500); - cancel_delayed_work(&wusbhc->keep_alive_timer); - flush_workqueue(wusbd); - queue_delayed_work(wusbd, &wusbhc->keep_alive_timer, - msecs_to_jiffies(wusbhc->trust_timeout / 2)); -out: - return result < 0 ? result : size; -} -static DEVICE_ATTR_RW(wusb_trust_timeout); - -/* - * Show the current WUSB CHID. - */ -static ssize_t wusb_chid_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - const struct wusb_ckhdid *chid; - - if (wusbhc->wuie_host_info != NULL) - chid = &wusbhc->wuie_host_info->CHID; - else - chid = &wusb_ckhdid_zero; - - return sprintf(buf, "%16ph\n", chid->data); -} - -/* - * Store a new CHID. - * - * - Write an all zeros CHID and it will stop the controller - * - Write a non-zero CHID and it will start it. - * - * See wusbhc_chid_set() for more info. - */ -static ssize_t wusb_chid_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - struct wusb_ckhdid chid; - ssize_t result; - - result = sscanf(buf, - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx " - "%02hhx %02hhx %02hhx %02hhx\n", - &chid.data[0] , &chid.data[1] , - &chid.data[2] , &chid.data[3] , - &chid.data[4] , &chid.data[5] , - &chid.data[6] , &chid.data[7] , - &chid.data[8] , &chid.data[9] , - &chid.data[10], &chid.data[11], - &chid.data[12], &chid.data[13], - &chid.data[14], &chid.data[15]); - if (result != 16) { - dev_err(dev, "Unrecognized CHID (need 16 8-bit hex digits): " - "%d\n", (int)result); - return -EINVAL; - } - result = wusbhc_chid_set(wusbhc, &chid); - return result < 0 ? result : size; -} -static DEVICE_ATTR_RW(wusb_chid); - - -static ssize_t wusb_phy_rate_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - - return sprintf(buf, "%d\n", wusbhc->phy_rate); -} - -static ssize_t wusb_phy_rate_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - uint8_t phy_rate; - ssize_t result; - - result = sscanf(buf, "%hhu", &phy_rate); - if (result != 1) - return -EINVAL; - if (phy_rate >= UWB_PHY_RATE_INVALID) - return -EINVAL; - - wusbhc->phy_rate = phy_rate; - return size; -} -static DEVICE_ATTR_RW(wusb_phy_rate); - -static ssize_t wusb_dnts_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - - return sprintf(buf, "num slots: %d\ninterval: %dms\n", - wusbhc->dnts_num_slots, wusbhc->dnts_interval); -} - -static ssize_t wusb_dnts_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - uint8_t num_slots, interval; - ssize_t result; - - result = sscanf(buf, "%hhu %hhu", &num_slots, &interval); - - if (result != 2) - return -EINVAL; - - wusbhc->dnts_num_slots = num_slots; - wusbhc->dnts_interval = interval; - - return size; -} -static DEVICE_ATTR_RW(wusb_dnts); - -static ssize_t wusb_retry_count_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - - return sprintf(buf, "%d\n", wusbhc->retry_count); -} - -static ssize_t wusb_retry_count_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t size) -{ - struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev); - uint8_t retry_count; - ssize_t result; - - result = sscanf(buf, "%hhu", &retry_count); - - if (result != 1) - return -EINVAL; - - wusbhc->retry_count = max_t(uint8_t, retry_count, - WUSB_RETRY_COUNT_MAX); - - return size; -} -static DEVICE_ATTR_RW(wusb_retry_count); - -/* Group all the WUSBHC attributes */ -static struct attribute *wusbhc_attrs[] = { - &dev_attr_wusb_trust_timeout.attr, - &dev_attr_wusb_chid.attr, - &dev_attr_wusb_phy_rate.attr, - &dev_attr_wusb_dnts.attr, - &dev_attr_wusb_retry_count.attr, - NULL, -}; - -static const struct attribute_group wusbhc_attr_group = { - .name = NULL, /* we want them in the same directory */ - .attrs = wusbhc_attrs, -}; - -/* - * Create a wusbhc instance - * - * NOTEs: - * - * - assumes *wusbhc has been zeroed and wusbhc->usb_hcd has been - * initialized but not added. - * - * - fill out ports_max, mmcies_max and mmcie_{add,rm} before calling. - * - * - fill out wusbhc->uwb_rc and refcount it before calling - * - fill out the wusbhc->sec_modes array - */ -int wusbhc_create(struct wusbhc *wusbhc) -{ - int result = 0; - - /* set defaults. These can be overwritten using sysfs attributes. */ - wusbhc->trust_timeout = WUSB_TRUST_TIMEOUT_MS; - wusbhc->phy_rate = UWB_PHY_RATE_INVALID - 1; - wusbhc->dnts_num_slots = 4; - wusbhc->dnts_interval = 2; - wusbhc->retry_count = WUSB_RETRY_COUNT_INFINITE; - - mutex_init(&wusbhc->mutex); - result = wusbhc_mmcie_create(wusbhc); - if (result < 0) - goto error_mmcie_create; - result = wusbhc_devconnect_create(wusbhc); - if (result < 0) - goto error_devconnect_create; - result = wusbhc_rh_create(wusbhc); - if (result < 0) - goto error_rh_create; - result = wusbhc_sec_create(wusbhc); - if (result < 0) - goto error_sec_create; - return 0; - -error_sec_create: - wusbhc_rh_destroy(wusbhc); -error_rh_create: - wusbhc_devconnect_destroy(wusbhc); -error_devconnect_create: - wusbhc_mmcie_destroy(wusbhc); -error_mmcie_create: - return result; -} -EXPORT_SYMBOL_GPL(wusbhc_create); - -static inline struct kobject *wusbhc_kobj(struct wusbhc *wusbhc) -{ - return &wusbhc->usb_hcd.self.controller->kobj; -} - -/* - * Phase B of a wusbhc instance creation - * - * Creates fields that depend on wusbhc->usb_hcd having been - * added. This is where we create the sysfs files in - * /sys/class/usb_host/usb_hostX/. - * - * NOTE: Assumes wusbhc->usb_hcd has been already added by the upper - * layer (hwahc or whci) - */ -int wusbhc_b_create(struct wusbhc *wusbhc) -{ - int result = 0; - struct device *dev = wusbhc->usb_hcd.self.controller; - - result = sysfs_create_group(wusbhc_kobj(wusbhc), &wusbhc_attr_group); - if (result < 0) { - dev_err(dev, "Cannot register WUSBHC attributes: %d\n", - result); - goto error_create_attr_group; - } - - return 0; -error_create_attr_group: - return result; -} -EXPORT_SYMBOL_GPL(wusbhc_b_create); - -void wusbhc_b_destroy(struct wusbhc *wusbhc) -{ - wusbhc_pal_unregister(wusbhc); - sysfs_remove_group(wusbhc_kobj(wusbhc), &wusbhc_attr_group); -} -EXPORT_SYMBOL_GPL(wusbhc_b_destroy); - -void wusbhc_destroy(struct wusbhc *wusbhc) -{ - wusbhc_sec_destroy(wusbhc); - wusbhc_rh_destroy(wusbhc); - wusbhc_devconnect_destroy(wusbhc); - wusbhc_mmcie_destroy(wusbhc); -} -EXPORT_SYMBOL_GPL(wusbhc_destroy); - -struct workqueue_struct *wusbd; -EXPORT_SYMBOL_GPL(wusbd); - -/* - * WUSB Cluster ID allocation map - * - * Each WUSB bus in a channel is identified with a Cluster Id in the - * unauth address pace (WUSB1.0[4.3]). We take the range 0xe0 to 0xff - * (that's space for 31 WUSB controllers, as 0xff can't be taken). We - * start taking from 0xff, 0xfe, 0xfd... (hence the += or -= 0xff). - * - * For each one we taken, we pin it in the bitap - */ -#define CLUSTER_IDS 32 -static DECLARE_BITMAP(wusb_cluster_id_table, CLUSTER_IDS); -static DEFINE_SPINLOCK(wusb_cluster_ids_lock); - -/* - * Get a WUSB Cluster ID - * - * Need to release with wusb_cluster_id_put() when done w/ it. - */ -/* FIXME: coordinate with the choose_addres() from the USB stack */ -/* we want to leave the top of the 128 range for cluster addresses and - * the bottom for device addresses (as we map them one on one with - * ports). */ -u8 wusb_cluster_id_get(void) -{ - u8 id; - spin_lock(&wusb_cluster_ids_lock); - id = find_first_zero_bit(wusb_cluster_id_table, CLUSTER_IDS); - if (id >= CLUSTER_IDS) { - id = 0; - goto out; - } - set_bit(id, wusb_cluster_id_table); - id = (u8) 0xff - id; -out: - spin_unlock(&wusb_cluster_ids_lock); - return id; - -} -EXPORT_SYMBOL_GPL(wusb_cluster_id_get); - -/* - * Release a WUSB Cluster ID - * - * Obtained it with wusb_cluster_id_get() - */ -void wusb_cluster_id_put(u8 id) -{ - id = 0xff - id; - BUG_ON(id >= CLUSTER_IDS); - spin_lock(&wusb_cluster_ids_lock); - WARN_ON(!test_bit(id, wusb_cluster_id_table)); - clear_bit(id, wusb_cluster_id_table); - spin_unlock(&wusb_cluster_ids_lock); -} -EXPORT_SYMBOL_GPL(wusb_cluster_id_put); - -/** - * wusbhc_giveback_urb - return an URB to the USB core - * @wusbhc: the host controller the URB is from. - * @urb: the URB. - * @status: the URB's status. - * - * Return an URB to the USB core doing some additional WUSB specific - * processing. - * - * - After a successful transfer, update the trust timeout timestamp - * for the WUSB device. - * - * - [WUSB] sections 4.13 and 7.5.1 specify the stop retransmission - * condition for the WCONNECTACK_IE is that the host has observed - * the associated device responding to a control transfer. - */ -void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb, int status) -{ - struct wusb_dev *wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, - urb->dev); - - if (status == 0 && wusb_dev) { - wusb_dev->entry_ts = jiffies; - - /* wusbhc_devconnect_acked() can't be called from - atomic context so defer it to a work queue. */ - if (!list_empty(&wusb_dev->cack_node)) - queue_work(wusbd, &wusb_dev->devconnect_acked_work); - else - wusb_dev_put(wusb_dev); - } - - usb_hcd_giveback_urb(&wusbhc->usb_hcd, urb, status); -} -EXPORT_SYMBOL_GPL(wusbhc_giveback_urb); - -/** - * wusbhc_reset_all - reset the HC hardware - * @wusbhc: the host controller to reset. - * - * Request a full hardware reset of the chip. This will also reset - * the radio controller and any other PALs. - */ -void wusbhc_reset_all(struct wusbhc *wusbhc) -{ - if (wusbhc->uwb_rc) - uwb_rc_reset_all(wusbhc->uwb_rc); -} -EXPORT_SYMBOL_GPL(wusbhc_reset_all); - -static struct notifier_block wusb_usb_notifier = { - .notifier_call = wusb_usb_ncb, - .priority = INT_MAX /* Need to be called first of all */ -}; - -static int __init wusbcore_init(void) -{ - int result; - result = wusb_crypto_init(); - if (result < 0) - goto error_crypto_init; - /* WQ is singlethread because we need to serialize notifications */ - wusbd = create_singlethread_workqueue("wusbd"); - if (wusbd == NULL) { - result = -ENOMEM; - printk(KERN_ERR "WUSB-core: Cannot create wusbd workqueue\n"); - goto error_wusbd_create; - } - usb_register_notify(&wusb_usb_notifier); - bitmap_zero(wusb_cluster_id_table, CLUSTER_IDS); - set_bit(0, wusb_cluster_id_table); /* reserve Cluster ID 0xff */ - return 0; - -error_wusbd_create: - wusb_crypto_exit(); -error_crypto_init: - return result; - -} -module_init(wusbcore_init); - -static void __exit wusbcore_exit(void) -{ - clear_bit(0, wusb_cluster_id_table); - if (!bitmap_empty(wusb_cluster_id_table, CLUSTER_IDS)) { - printk(KERN_ERR "BUG: WUSB Cluster IDs not released on exit: %*pb\n", - CLUSTER_IDS, wusb_cluster_id_table); - WARN_ON(1); - } - usb_unregister_notify(&wusb_usb_notifier); - destroy_workqueue(wusbd); - wusb_crypto_exit(); -} -module_exit(wusbcore_exit); - -MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); -MODULE_DESCRIPTION("Wireless USB core"); -MODULE_LICENSE("GPL"); diff --git a/drivers/staging/wusbcore/wusbhc.h b/drivers/staging/wusbcore/wusbhc.h deleted file mode 100644 index 716244a2ec44..000000000000 --- a/drivers/staging/wusbcore/wusbhc.h +++ /dev/null @@ -1,487 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Wireless USB Host Controller - * Common infrastructure for WHCI and HWA WUSB-HC drivers - * - * - * Copyright (C) 2005-2006 Intel Corporation - * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> - * - * This driver implements parts common to all Wireless USB Host - * Controllers (struct wusbhc, embedding a struct usb_hcd) and is used - * by: - * - * - hwahc: HWA, USB-dongle that implements a Wireless USB host - * controller, (Wireless USB 1.0 Host-Wire-Adapter specification). - * - * - whci: WHCI, a PCI card with a wireless host controller - * (Wireless Host Controller Interface 1.0 specification). - * - * Check out the Design-overview.txt file in the source documentation - * for other details on the implementation. - * - * Main blocks: - * - * rh Root Hub emulation (part of the HCD glue) - * - * devconnect Handle all the issues related to device connection, - * authentication, disconnection, timeout, reseting, - * keepalives, etc. - * - * mmc MMC IE broadcasting handling - * - * A host controller driver just initializes its stuff and as part of - * that, creates a 'struct wusbhc' instance that handles all the - * common WUSB mechanisms. Links in the function ops that are specific - * to it and then registers the host controller. Ready to run. - */ - -#ifndef __WUSBHC_H__ -#define __WUSBHC_H__ - -#include <linux/usb.h> -#include <linux/list.h> -#include <linux/mutex.h> -#include <linux/kref.h> -#include <linux/workqueue.h> -#include <linux/usb/hcd.h> -#include "../uwb/uwb.h" -#include "include/wusb.h" - -/* - * Time from a WUSB channel stop request to the last transmitted MMC. - * - * This needs to be > 4.096 ms in case no MMCs can be transmitted in - * zone 0. - */ -#define WUSB_CHANNEL_STOP_DELAY_MS 8 -#define WUSB_RETRY_COUNT_MAX 15 -#define WUSB_RETRY_COUNT_INFINITE 0 - -/** - * Wireless USB device - * - * Describe a WUSB device connected to the cluster. This struct - * belongs to the 'struct wusb_port' it is attached to and it is - * responsible for putting and clearing the pointer to it. - * - * Note this "complements" the 'struct usb_device' that the usb_hcd - * keeps for each connected USB device. However, it extends some - * information that is not available (there is no hcpriv ptr in it!) - * *and* most importantly, it's life cycle is different. It is created - * as soon as we get a DN_Connect (connect request notification) from - * the device through the WUSB host controller; the USB stack doesn't - * create the device until we authenticate it. FIXME: this will - * change. - * - * @bos: This is allocated when the BOS descriptors are read from - * the device and freed upon the wusb_dev struct dying. - * @wusb_cap_descr: points into @bos, and has been verified to be size - * safe. - */ -struct wusb_dev { - struct kref refcnt; - struct wusbhc *wusbhc; - struct list_head cack_node; /* Connect-Ack list */ - struct list_head rekey_node; /* GTK rekey list */ - u8 port_idx; - u8 addr; - u8 beacon_type:4; - struct usb_encryption_descriptor ccm1_etd; - struct wusb_ckhdid cdid; - unsigned long entry_ts; - struct usb_bos_descriptor *bos; - struct usb_wireless_cap_descriptor *wusb_cap_descr; - struct uwb_mas_bm availability; - struct work_struct devconnect_acked_work; - struct usb_device *usb_dev; -}; - -#define WUSB_DEV_ADDR_UNAUTH 0x80 - -static inline void wusb_dev_init(struct wusb_dev *wusb_dev) -{ - kref_init(&wusb_dev->refcnt); - /* no need to init the cack_node */ -} - -extern void wusb_dev_destroy(struct kref *_wusb_dev); - -static inline struct wusb_dev *wusb_dev_get(struct wusb_dev *wusb_dev) -{ - kref_get(&wusb_dev->refcnt); - return wusb_dev; -} - -static inline void wusb_dev_put(struct wusb_dev *wusb_dev) -{ - kref_put(&wusb_dev->refcnt, wusb_dev_destroy); -} - -/** - * Wireless USB Host Controller root hub "fake" ports - * (state and device information) - * - * Wireless USB is wireless, so there are no ports; but we - * fake'em. Each RC can connect a max of devices at the same time - * (given in the Wireless Adapter descriptor, bNumPorts or WHCI's - * caps), referred to in wusbhc->ports_max. - * - * See rh.c for more information. - * - * The @status and @change use the same bits as in USB2.0[11.24.2.7], - * so we don't have to do much when getting the port's status. - * - * WUSB1.0[7.1], USB2.0[11.24.2.7.1,fig 11-10], - * include/linux/usb_ch9.h (#define USB_PORT_STAT_*) - */ -struct wusb_port { - u16 status; - u16 change; - struct wusb_dev *wusb_dev; /* connected device's info */ - u32 ptk_tkid; -}; - -/** - * WUSB Host Controller specifics - * - * All fields that are common to all Wireless USB controller types - * (HWA and WHCI) are grouped here. Host Controller - * functions/operations that only deal with general Wireless USB HC - * issues use this data type to refer to the host. - * - * @usb_hcd Instantiation of a USB host controller - * (initialized by upper layer [HWA=HC or WHCI]. - * - * @dev Device that implements this; initialized by the - * upper layer (HWA-HC, WHCI...); this device should - * have a refcount. - * - * @trust_timeout After this time without hearing for device - * activity, we consider the device gone and we have to - * re-authenticate. - * - * Can be accessed w/o locking--however, read to a - * local variable then use. - * - * @chid WUSB Cluster Host ID: this is supposed to be a - * unique value that doesn't change across reboots (so - * that your devices do not require re-association). - * - * Read/Write protected by @mutex - * - * @dev_info This array has ports_max elements. It is used to - * give the HC information about the WUSB devices (see - * 'struct wusb_dev_info'). - * - * For HWA we need to allocate it in heap; for WHCI it - * needs to be permanently mapped, so we keep it for - * both and make it easy. Call wusbhc->dev_info_set() - * to update an entry. - * - * @ports_max Number of simultaneous device connections (fake - * ports) this HC will take. Read-only. - * - * @port Array of port status for each fake root port. Guaranteed to - * always be the same length during device existence - * [this allows for some unlocked but referenced reading]. - * - * @mmcies_max Max number of Information Elements this HC can send - * in its MMC. Read-only. - * - * @start Start the WUSB channel. - * - * @stop Stop the WUSB channel after the specified number of - * milliseconds. Channel Stop IEs should be transmitted - * as required by [WUSB] 4.16.2.1. - * - * @mmcie_add HC specific operation (WHCI or HWA) for adding an - * MMCIE. - * - * @mmcie_rm HC specific operation (WHCI or HWA) for removing an - * MMCIE. - * - * @set_ptk: Set the PTK and enable encryption for a device. Or, if - * the supplied key is NULL, disable encryption for that - * device. - * - * @set_gtk: Set the GTK to be used for all future broadcast packets - * (i.e., MMCs). With some hardware, setting the GTK may start - * MMC transmission. - * - * NOTE: - * - * - If wusb_dev->usb_dev is not NULL, then usb_dev is valid - * (wusb_dev has a refcount on it). Likewise, if usb_dev->wusb_dev - * is not NULL, usb_dev->wusb_dev is valid (usb_dev keeps a - * refcount on it). - * - * Most of the times when you need to use it, it will be non-NULL, - * so there is no real need to check for it (wusb_dev will - * disappear before usb_dev). - * - * - The following fields need to be filled out before calling - * wusbhc_create(): ports_max, mmcies_max, mmcie_{add,rm}. - * - * - there is no wusbhc_init() method, we do everything in - * wusbhc_create(). - * - * - Creation is done in two phases, wusbhc_create() and - * wusbhc_create_b(); b are the parts that need to be called after - * calling usb_hcd_add(&wusbhc->usb_hcd). - */ -struct wusbhc { - struct usb_hcd usb_hcd; /* HAS TO BE 1st */ - struct device *dev; - struct uwb_rc *uwb_rc; - struct uwb_pal pal; - - unsigned trust_timeout; /* in jiffies */ - struct wusb_ckhdid chid; - uint8_t phy_rate; - uint8_t dnts_num_slots; - uint8_t dnts_interval; - uint8_t retry_count; - struct wuie_host_info *wuie_host_info; - - struct mutex mutex; /* locks everything else */ - u16 cluster_id; /* Wireless USB Cluster ID */ - struct wusb_port *port; /* Fake port status handling */ - struct wusb_dev_info *dev_info; /* for Set Device Info mgmt */ - u8 ports_max; - unsigned active:1; /* currently xmit'ing MMCs */ - struct wuie_keep_alive keep_alive_ie; /* protected by mutex */ - struct delayed_work keep_alive_timer; - struct list_head cack_list; /* Connect acknowledging */ - size_t cack_count; /* protected by 'mutex' */ - struct wuie_connect_ack cack_ie; - struct uwb_rsv *rsv; /* cluster bandwidth reservation */ - - struct mutex mmcie_mutex; /* MMC WUIE handling */ - struct wuie_hdr **mmcie; /* WUIE array */ - u8 mmcies_max; - /* FIXME: make wusbhc_ops? */ - int (*start)(struct wusbhc *wusbhc); - void (*stop)(struct wusbhc *wusbhc, int delay); - int (*mmcie_add)(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt, - u8 handle, struct wuie_hdr *wuie); - int (*mmcie_rm)(struct wusbhc *wusbhc, u8 handle); - int (*dev_info_set)(struct wusbhc *, struct wusb_dev *wusb_dev); - int (*bwa_set)(struct wusbhc *wusbhc, s8 stream_index, - const struct uwb_mas_bm *); - int (*set_ptk)(struct wusbhc *wusbhc, u8 port_idx, - u32 tkid, const void *key, size_t key_size); - int (*set_gtk)(struct wusbhc *wusbhc, - u32 tkid, const void *key, size_t key_size); - int (*set_num_dnts)(struct wusbhc *wusbhc, u8 interval, u8 slots); - - struct { - struct usb_key_descriptor descr; - u8 data[16]; /* GTK key data */ - } __attribute__((packed)) gtk; - u8 gtk_index; - u32 gtk_tkid; - - /* workqueue for WUSB security related tasks. */ - struct workqueue_struct *wq_security; - struct work_struct gtk_rekey_work; - - struct usb_encryption_descriptor *ccm1_etd; -}; - -#define usb_hcd_to_wusbhc(u) container_of((u), struct wusbhc, usb_hcd) - - -extern int wusbhc_create(struct wusbhc *); -extern int wusbhc_b_create(struct wusbhc *); -extern void wusbhc_b_destroy(struct wusbhc *); -extern void wusbhc_destroy(struct wusbhc *); -extern int wusb_dev_sysfs_add(struct wusbhc *, struct usb_device *, - struct wusb_dev *); -extern void wusb_dev_sysfs_rm(struct wusb_dev *); -extern int wusbhc_sec_create(struct wusbhc *); -extern int wusbhc_sec_start(struct wusbhc *); -extern void wusbhc_sec_stop(struct wusbhc *); -extern void wusbhc_sec_destroy(struct wusbhc *); -extern void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb, - int status); -void wusbhc_reset_all(struct wusbhc *wusbhc); - -int wusbhc_pal_register(struct wusbhc *wusbhc); -void wusbhc_pal_unregister(struct wusbhc *wusbhc); - -/* - * Return @usb_dev's @usb_hcd (properly referenced) or NULL if gone - * - * @usb_dev: USB device, UNLOCKED and referenced (or otherwise, safe ptr) - * - * This is a safe assumption as @usb_dev->bus is referenced all the - * time during the @usb_dev life cycle. - */ -static inline -struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev) -{ - struct usb_hcd *usb_hcd; - usb_hcd = bus_to_hcd(usb_dev->bus); - return usb_get_hcd(usb_hcd); -} - -/* - * Increment the reference count on a wusbhc. - * - * @wusbhc's life cycle is identical to that of the underlying usb_hcd. - */ -static inline struct wusbhc *wusbhc_get(struct wusbhc *wusbhc) -{ - return usb_get_hcd(&wusbhc->usb_hcd) ? wusbhc : NULL; -} - -/* - * Return the wusbhc associated to a @usb_dev - * - * @usb_dev: USB device, UNLOCKED and referenced (or otherwise, safe ptr) - * - * @returns: wusbhc for @usb_dev; NULL if the @usb_dev is being torn down. - * WARNING: referenced at the usb_hcd level, unlocked - * - * FIXME: move offline - */ -static inline struct wusbhc *wusbhc_get_by_usb_dev(struct usb_device *usb_dev) -{ - struct wusbhc *wusbhc = NULL; - struct usb_hcd *usb_hcd; - if (usb_dev->devnum > 1 && !usb_dev->wusb) { - /* but root hubs */ - dev_err(&usb_dev->dev, "devnum %d wusb %d\n", usb_dev->devnum, - usb_dev->wusb); - BUG_ON(usb_dev->devnum > 1 && !usb_dev->wusb); - } - usb_hcd = usb_hcd_get_by_usb_dev(usb_dev); - if (usb_hcd == NULL) - return NULL; - BUG_ON(usb_hcd->wireless == 0); - return wusbhc = usb_hcd_to_wusbhc(usb_hcd); -} - - -static inline void wusbhc_put(struct wusbhc *wusbhc) -{ - usb_put_hcd(&wusbhc->usb_hcd); -} - -int wusbhc_start(struct wusbhc *wusbhc); -void wusbhc_stop(struct wusbhc *wusbhc); -extern int wusbhc_chid_set(struct wusbhc *, const struct wusb_ckhdid *); - -/* Device connect handling */ -extern int wusbhc_devconnect_create(struct wusbhc *); -extern void wusbhc_devconnect_destroy(struct wusbhc *); -extern int wusbhc_devconnect_start(struct wusbhc *wusbhc); -extern void wusbhc_devconnect_stop(struct wusbhc *wusbhc); -extern void wusbhc_handle_dn(struct wusbhc *, u8 srcaddr, - struct wusb_dn_hdr *dn_hdr, size_t size); -extern void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port); -extern int wusb_usb_ncb(struct notifier_block *nb, unsigned long val, - void *priv); -extern int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, - u8 addr); - -/* Wireless USB fake Root Hub methods */ -extern int wusbhc_rh_create(struct wusbhc *); -extern void wusbhc_rh_destroy(struct wusbhc *); - -extern int wusbhc_rh_status_data(struct usb_hcd *, char *); -extern int wusbhc_rh_control(struct usb_hcd *, u16, u16, u16, char *, u16); -extern int wusbhc_rh_start_port_reset(struct usb_hcd *, unsigned); - -/* MMC handling */ -extern int wusbhc_mmcie_create(struct wusbhc *); -extern void wusbhc_mmcie_destroy(struct wusbhc *); -extern int wusbhc_mmcie_set(struct wusbhc *, u8 interval, u8 repeat_cnt, - struct wuie_hdr *); -extern void wusbhc_mmcie_rm(struct wusbhc *, struct wuie_hdr *); - -/* Bandwidth reservation */ -int wusbhc_rsv_establish(struct wusbhc *wusbhc); -void wusbhc_rsv_terminate(struct wusbhc *wusbhc); - -/* - * I've always said - * I wanted a wedding in a church... - * - * but lately I've been thinking about - * the Botanical Gardens. - * - * We could do it by the tulips. - * It'll be beautiful - * - * --Security! - */ -extern int wusb_dev_sec_add(struct wusbhc *, struct usb_device *, - struct wusb_dev *); -extern void wusb_dev_sec_rm(struct wusb_dev *) ; -extern int wusb_dev_4way_handshake(struct wusbhc *, struct wusb_dev *, - struct wusb_ckhdid *ck); -void wusbhc_gtk_rekey(struct wusbhc *wusbhc); -int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev); - - -/* WUSB Cluster ID handling */ -extern u8 wusb_cluster_id_get(void); -extern void wusb_cluster_id_put(u8); - -/* - * wusb_port_by_idx - return the port associated to a zero-based port index - * - * NOTE: valid without locking as long as wusbhc is referenced (as the - * number of ports doesn't change). The data pointed to has to - * be verified though :) - */ -static inline struct wusb_port *wusb_port_by_idx(struct wusbhc *wusbhc, - u8 port_idx) -{ - return &wusbhc->port[port_idx]; -} - -/* - * wusb_port_no_to_idx - Convert port number (per usb_dev->portnum) to - * a port_idx. - * - * USB stack USB ports are 1 based!! - * - * NOTE: only valid for WUSB devices!!! - */ -static inline u8 wusb_port_no_to_idx(u8 port_no) -{ - return port_no - 1; -} - -extern struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *, - struct usb_device *); - -/* - * Return a referenced wusb_dev given a @usb_dev - * - * Returns NULL if the usb_dev is being torn down. - * - * FIXME: move offline - */ -static inline -struct wusb_dev *wusb_dev_get_by_usb_dev(struct usb_device *usb_dev) -{ - struct wusbhc *wusbhc; - struct wusb_dev *wusb_dev; - wusbhc = wusbhc_get_by_usb_dev(usb_dev); - if (wusbhc == NULL) - return NULL; - mutex_lock(&wusbhc->mutex); - wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev); - mutex_unlock(&wusbhc->mutex); - wusbhc_put(wusbhc); - return wusb_dev; -} - -/* Misc */ - -extern struct workqueue_struct *wusbd; -#endif /* #ifndef __WUSBHC_H__ */ |