/* * Driver for the Solomon SSD1307 OLED controller * * Copyright 2012 Free Electrons * * Licensed under the GPLv2 or later. */ #include #include #include #include #include #include #include #include #include #include #define SSD1307FB_DATA 0x40 #define SSD1307FB_COMMAND 0x80 #define SSD1307FB_SET_ADDRESS_MODE 0x20 #define SSD1307FB_SET_ADDRESS_MODE_HORIZONTAL (0x00) #define SSD1307FB_SET_ADDRESS_MODE_VERTICAL (0x01) #define SSD1307FB_SET_ADDRESS_MODE_PAGE (0x02) #define SSD1307FB_SET_COL_RANGE 0x21 #define SSD1307FB_SET_PAGE_RANGE 0x22 #define SSD1307FB_CONTRAST 0x81 #define SSD1307FB_CHARGE_PUMP 0x8d #define SSD1307FB_SEG_REMAP_ON 0xa1 #define SSD1307FB_DISPLAY_OFF 0xae #define SSD1307FB_SET_MULTIPLEX_RATIO 0xa8 #define SSD1307FB_DISPLAY_ON 0xaf #define SSD1307FB_START_PAGE_ADDRESS 0xb0 #define SSD1307FB_SET_DISPLAY_OFFSET 0xd3 #define SSD1307FB_SET_CLOCK_FREQ 0xd5 #define SSD1307FB_SET_PRECHARGE_PERIOD 0xd9 #define SSD1307FB_SET_COM_PINS_CONFIG 0xda #define SSD1307FB_SET_VCOMH 0xdb #define MAX_CONTRAST 255 #define REFRESHRATE 1 static u_int refreshrate = REFRESHRATE; module_param(refreshrate, uint, 0); struct ssd1307fb_par; struct ssd1307fb_deviceinfo { u32 default_vcomh; u32 default_dclk_div; u32 default_dclk_frq; int need_pwm; int need_chargepump; }; struct ssd1307fb_par { u32 com_invdir; u32 com_lrremap; u32 com_offset; u32 com_seq; u32 contrast; u32 dclk_div; u32 dclk_frq; const struct ssd1307fb_deviceinfo *device_info; struct i2c_client *client; u32 height; struct fb_info *info; u32 page_offset; u32 prechargep1; u32 prechargep2; struct pwm_device *pwm; u32 pwm_period; int reset; u32 seg_remap; u32 vcomh; u32 width; }; struct ssd1307fb_array { u8 type; u8 data[0]; }; static const struct fb_fix_screeninfo ssd1307fb_fix = { .id = "Solomon SSD1307", .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_MONO10, .xpanstep = 0, .ypanstep = 0, .ywrapstep = 0, .accel = FB_ACCEL_NONE, }; static const struct fb_var_screeninfo ssd1307fb_var = { .bits_per_pixel = 1, }; static struct ssd1307fb_array *ssd1307fb_alloc_array(u32 len, u8 type) { struct ssd1307fb_array *array; array = kzalloc(sizeof(struct ssd1307fb_array) + len, GFP_KERNEL); if (!array) return NULL; array->type = type; return array; } static int ssd1307fb_write_array(struct i2c_client *client, struct ssd1307fb_array *array, u32 len) { int ret; len += sizeof(struct ssd1307fb_array); ret = i2c_master_send(client, (u8 *)array, len); if (ret != len) { dev_err(&client->dev, "Couldn't send I2C command.\n"); return ret; } return 0; } static inline int ssd1307fb_write_cmd(struct i2c_client *client, u8 cmd) { struct ssd1307fb_array *array; int ret; array = ssd1307fb_alloc_array(1, SSD1307FB_COMMAND); if (!array) return -ENOMEM; array->data[0] = cmd; ret = ssd1307fb_write_array(client, array, 1); kfree(array); return ret; } static void ssd1307fb_update_display(struct ssd1307fb_par *par) { struct ssd1307fb_array *array; u8 *vmem = par->info->screen_base; int i, j, k; array = ssd1307fb_alloc_array(par->width * par->height / 8, SSD1307FB_DATA); if (!array) return; /* * The screen is divided in pages, each having a height of 8 * pixels, and the width of the screen. When sending a byte of * data to the controller, it gives the 8 bits for the current * column. I.e, the first byte are the 8 bits of the first * column, then the 8 bits for the second column, etc. * * * Representation of the screen, assuming it is 5 bits * wide. Each letter-number combination is a bit that controls * one pixel. * * A0 A1 A2 A3 A4 * B0 B1 B2 B3 B4 * C0 C1 C2 C3 C4 * D0 D1 D2 D3 D4 * E0 E1 E2 E3 E4 * F0 F1 F2 F3 F4 * G0 G1 G2 G3 G4 * H0 H1 H2 H3 H4 * * If you want to update this screen, you need to send 5 bytes: * (1) A0 B0 C0 D0 E0 F0 G0 H0 * (2) A1 B1 C1 D1 E1 F1 G1 H1 * (3) A2 B2 C2 D2 E2 F2 G2 H2 * (4) A3 B3 C3 D3 E3 F3 G3 H3 * (5) A4 B4 C4 D4 E4 F4 G4 H4 */ for (i = 0; i < (par->height / 8); i++) { for (j = 0; j < par->width; j++) { u32 array_idx = i * par->width + j; array->data[array_idx] = 0; for (k = 0; k < 8; k++) { u32 page_length = par->width * i; u32 index = page_length + (par->width * k + j) / 8; u8 byte = *(vmem + index); u8 bit = byte & (1 << (j % 8)); bit = bit >> (j % 8); array->data[array_idx] |= bit << k; } } } ssd1307fb_write_array(par->client, array, par->width * par->height / 8); kfree(array); } static ssize_t ssd1307fb_write(struct fb_info *info, const char __user *buf, size_t count, loff_t *ppos) { struct ssd1307fb_par *par = info->par; unsigned long total_size; unsigned long p = *ppos; u8 __iomem *dst; total_size = info->fix.smem_len; if (p > total_size) return -EINVAL; if (count + p > total_size) count = total_size - p; if (!count) return -EINVAL; dst = (void __force *) (info->screen_base + p); if (copy_from_user(dst, buf, count)) return -EFAULT; ssd1307fb_update_display(par); *ppos += count; return count; } static int ssd1307fb_blank(int blank_mode, struct fb_info *info) { struct ssd1307fb_par *par = info->par; if (blank_mode != FB_BLANK_UNBLANK) return ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_OFF); else return ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_ON); } static void ssd1307fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) { struct ssd1307fb_par *par = info->par; sys_fillrect(info, rect); ssd1307fb_update_display(par); } static void ssd1307fb_copyarea(struct fb_info *info, const struct fb_copyarea *area) { struct ssd1307fb_par *par = info->par; sys_copyarea(info, area); ssd1307fb_update_display(par); } static void ssd1307fb_imageblit(struct fb_info *info, const struct fb_image *image) { struct ssd1307fb_par *par = info->par; sys_imageblit(info, image); ssd1307fb_update_display(par); } static struct fb_ops ssd1307fb_ops = { .owner = THIS_MODULE, .fb_read = fb_sys_read, .fb_write = ssd1307fb_write, .fb_blank = ssd1307fb_blank, .fb_fillrect = ssd1307fb_fillrect, .fb_copyarea = ssd1307fb_copyarea, .fb_imageblit = ssd1307fb_imageblit, }; static void ssd1307fb_deferred_io(struct fb_info *info, struct list_head *pagelist) { ssd1307fb_update_display(info->par); } static int ssd1307fb_init(struct ssd1307fb_par *par) { int ret; u32 precharge, dclk, com_invdir, compins; struct pwm_args pargs; if (par->device_info->need_pwm) { par->pwm = pwm_get(&par->client->dev, NULL); if (IS_ERR(par->pwm)) { dev_err(&par->client->dev, "Could not get PWM from device tree!\n"); return PTR_ERR(par->pwm); } /* * FIXME: pwm_apply_args() should be removed when switching to * the atomic PWM API. */ pwm_apply_args(par->pwm); pwm_get_args(par->pwm, &pargs); par->pwm_period = pargs.period; /* Enable the PWM */ pwm_config(par->pwm, par->pwm_period / 2, par->pwm_period); pwm_enable(par->pwm); dev_dbg(&par->client->dev, "Using PWM%d with a %dns period.\n", par->pwm->pwm, par->pwm_period); }; /* Set initial contrast */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CONTRAST); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->contrast); if (ret < 0) return ret; /* Set segment re-map */ if (par->seg_remap) { ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SEG_REMAP_ON); if (ret < 0) return ret; }; /* Set COM direction */ com_invdir = 0xc0 | (par->com_invdir & 0x1) << 3; ret = ssd1307fb_write_cmd(par->client, com_invdir); if (ret < 0) return ret; /* Set multiplex ratio value */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_MULTIPLEX_RATIO); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->height - 1); if (ret < 0) return ret; /* set display offset value */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_DISPLAY_OFFSET); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->com_offset); if (ret < 0) return ret; /* Set clock frequency */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_CLOCK_FREQ); if (ret < 0) return ret; dclk = ((par->dclk_div - 1) & 0xf) | (par->dclk_frq & 0xf) << 4; ret = ssd1307fb_write_cmd(par->client, dclk); if (ret < 0) return ret; /* Set precharge period in number of ticks from the internal clock */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PRECHARGE_PERIOD); if (ret < 0) return ret; precharge = (par->prechargep1 & 0xf) | (par->prechargep2 & 0xf) << 4; ret = ssd1307fb_write_cmd(par->client, precharge); if (ret < 0) return ret; /* Set COM pins configuration */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COM_PINS_CONFIG); if (ret < 0) return ret; compins = 0x02 | !(par->com_seq & 0x1) << 4 | (par->com_lrremap & 0x1) << 5; ret = ssd1307fb_write_cmd(par->client, compins); if (ret < 0) return ret; /* Set VCOMH */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_VCOMH); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->vcomh); if (ret < 0) return ret; /* Turn on the DC-DC Charge Pump */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CHARGE_PUMP); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, BIT(4) | (par->device_info->need_chargepump ? BIT(2) : 0)); if (ret < 0) return ret; /* Switch to horizontal addressing mode */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_ADDRESS_MODE); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_ADDRESS_MODE_HORIZONTAL); if (ret < 0) return ret; /* Set column range */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_COL_RANGE); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, 0x0); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->width - 1); if (ret < 0) return ret; /* Set page range */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_SET_PAGE_RANGE); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, 0x0); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->page_offset + (par->height / 8) - 1); if (ret < 0) return ret; /* Turn on the display */ ret = ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_ON); if (ret < 0) return ret; return 0; } static int ssd1307fb_update_bl(struct backlight_device *bdev) { struct ssd1307fb_par *par = bl_get_data(bdev); int ret; int brightness = bdev->props.brightness; par->contrast = brightness; ret = ssd1307fb_write_cmd(par->client, SSD1307FB_CONTRAST); if (ret < 0) return ret; ret = ssd1307fb_write_cmd(par->client, par->contrast); if (ret < 0) return ret; return 0; } static int ssd1307fb_get_brightness(struct backlight_device *bdev) { struct ssd1307fb_par *par = bl_get_data(bdev); return par->contrast; } static int ssd1307fb_check_fb(struct backlight_device *bdev, struct fb_info *info) { return (info->bl_dev == bdev); } static const struct backlight_ops ssd1307fb_bl_ops = { .options = BL_CORE_SUSPENDRESUME, .update_status = ssd1307fb_update_bl, .get_brightness = ssd1307fb_get_brightness, .check_fb = ssd1307fb_check_fb, }; static struct ssd1307fb_deviceinfo ssd1307fb_ssd1305_deviceinfo = { .default_vcomh = 0x34, .default_dclk_div = 1, .default_dclk_frq = 7, }; static struct ssd1307fb_deviceinfo ssd1307fb_ssd1306_deviceinfo = { .default_vcomh = 0x20, .default_dclk_div = 1, .default_dclk_frq = 8, .need_chargepump = 1, }; static struct ssd1307fb_deviceinfo ssd1307fb_ssd1307_deviceinfo = { .default_vcomh = 0x20, .default_dclk_div = 2, .default_dclk_frq = 12, .need_pwm = 1, }; static struct ssd1307fb_deviceinfo ssd1307fb_ssd1309_deviceinfo = { .default_vcomh = 0x34, .default_dclk_div = 1, .default_dclk_frq = 10, }; static const struct of_device_id ssd1307fb_of_match[] = { { .compatible = "solomon,ssd1305fb-i2c", .data = (void *)&ssd1307fb_ssd1305_deviceinfo, }, { .compatible = "solomon,ssd1306fb-i2c", .data = (void *)&ssd1307fb_ssd1306_deviceinfo, }, { .compatible = "solomon,ssd1307fb-i2c", .data = (void *)&ssd1307fb_ssd1307_deviceinfo, }, { .compatible = "solomon,ssd1309fb-i2c", .data = (void *)&ssd1307fb_ssd1309_deviceinfo, }, {}, }; MODULE_DEVICE_TABLE(of, ssd1307fb_of_match); static int ssd1307fb_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct backlight_device *bl; char bl_name[12]; struct fb_info *info; struct device_node *node = client->dev.of_node; struct fb_deferred_io *ssd1307fb_defio; u32 vmem_size; struct ssd1307fb_par *par; u8 *vmem; int ret; if (!node) { dev_err(&client->dev, "No device tree data found!\n"); return -EINVAL; } info = framebuffer_alloc(sizeof(struct ssd1307fb_par), &client->dev); if (!info) { dev_err(&client->dev, "Couldn't allocate framebuffer.\n"); return -ENOMEM; } par = info->par; par->info = info; par->client = client; par->device_info = of_device_get_match_data(&client->dev); par->reset = of_get_named_gpio(client->dev.of_node, "reset-gpios", 0); if (!gpio_is_valid(par->reset)) { ret = -EINVAL; goto fb_alloc_error; } if (of_property_read_u32(node, "solomon,width", &par->width)) par->width = 96; if (of_property_read_u32(node, "solomon,height", &par->height)) par->height = 16; if (of_property_read_u32(node, "solomon,page-offset", &par->page_offset)) par->page_offset = 1; if (of_property_read_u32(node, "solomon,com-offset", &par->com_offset)) par->com_offset = 0; if (of_property_read_u32(node, "solomon,prechargep1", &par->prechargep1)) par->prechargep1 = 2; if (of_property_read_u32(node, "solomon,prechargep2", &par->prechargep2)) par->prechargep2 = 2; par->seg_remap = !of_property_read_bool(node, "solomon,segment-no-remap"); par->com_seq = of_property_read_bool(node, "solomon,com-seq"); par->com_lrremap = of_property_read_bool(node, "solomon,com-lrremap"); par->com_invdir = of_property_read_bool(node, "solomon,com-invdir"); par->contrast = 127; par->vcomh = par->device_info->default_vcomh; /* Setup display timing */ par->dclk_div = par->device_info->default_dclk_div; par->dclk_frq = par->device_info->default_dclk_frq; vmem_size = par->width * par->height / 8; vmem = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, get_order(vmem_size)); if (!vmem) { dev_err(&client->dev, "Couldn't allocate graphical memory.\n"); ret = -ENOMEM; goto fb_alloc_error; } ssd1307fb_defio = devm_kzalloc(&client->dev, sizeof(struct fb_deferred_io), GFP_KERNEL); if (!ssd1307fb_defio) { dev_err(&client->dev, "Couldn't allocate deferred io.\n"); ret = -ENOMEM; goto fb_alloc_error; } ssd1307fb_defio->delay = HZ / refreshrate; ssd1307fb_defio->deferred_io = ssd1307fb_deferred_io; info->fbops = &ssd1307fb_ops; info->fix = ssd1307fb_fix; info->fix.line_length = par->width / 8; info->fbdefio = ssd1307fb_defio; info->var = ssd1307fb_var; info->var.xres = par->width; info->var.xres_virtual = par->width; info->var.yres = par->height; info->var.yres_virtual = par->height; info->var.red.length = 1; info->var.red.offset = 0; info->var.green.length = 1; info->var.green.offset = 0; info->var.blue.length = 1; info->var.blue.offset = 0; info->screen_base = (u8 __force __iomem *)vmem; info->fix.smem_start = __pa(vmem); info->fix.smem_len = vmem_size; fb_deferred_io_init(info); ret = devm_gpio_request_one(&client->dev, par->reset, GPIOF_OUT_INIT_HIGH, "oled-reset"); if (ret) { dev_err(&client->dev, "failed to request gpio %d: %d\n", par->reset, ret); goto reset_oled_error; } i2c_set_clientdata(client, info); /* Reset the screen */ gpio_set_value(par->reset, 0); udelay(4); gpio_set_value(par->reset, 1); udelay(4); ret = ssd1307fb_init(par); if (ret) goto reset_oled_error; ret = register_framebuffer(info); if (ret) { dev_err(&client->dev, "Couldn't register the framebuffer\n"); goto panel_init_error; } snprintf(bl_name, sizeof(bl_name), "ssd1307fb%d", info->node); bl = backlight_device_register(bl_name, &client->dev, par, &ssd1307fb_bl_ops, NULL); if (IS_ERR(bl)) { ret = PTR_ERR(bl); dev_err(&client->dev, "unable to register backlight device: %d\n", ret); goto bl_init_error; } bl->props.brightness = par->contrast; bl->props.max_brightness = MAX_CONTRAST; info->bl_dev = bl; dev_info(&client->dev, "fb%d: %s framebuffer device registered, using %d bytes of video memory\n", info->node, info->fix.id, vmem_size); return 0; bl_init_error: unregister_framebuffer(info); panel_init_error: if (par->device_info->need_pwm) { pwm_disable(par->pwm); pwm_put(par->pwm); }; reset_oled_error: fb_deferred_io_cleanup(info); fb_alloc_error: framebuffer_release(info); return ret; } static int ssd1307fb_remove(struct i2c_client *client) { struct fb_info *info = i2c_get_clientdata(client); struct ssd1307fb_par *par = info->par; ssd1307fb_write_cmd(par->client, SSD1307FB_DISPLAY_OFF); backlight_device_unregister(info->bl_dev); unregister_framebuffer(info); if (par->device_info->need_pwm) { pwm_disable(par->pwm); pwm_put(par->pwm); }; fb_deferred_io_cleanup(info); __free_pages(__va(info->fix.smem_start), get_order(info->fix.smem_len)); framebuffer_release(info); return 0; } static const struct i2c_device_id ssd1307fb_i2c_id[] = { { "ssd1305fb", 0 }, { "ssd1306fb", 0 }, { "ssd1307fb", 0 }, { "ssd1309fb", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, ssd1307fb_i2c_id); static struct i2c_driver ssd1307fb_driver = { .probe = ssd1307fb_probe, .remove = ssd1307fb_remove, .id_table = ssd1307fb_i2c_id, .driver = { .name = "ssd1307fb", .of_match_table = ssd1307fb_of_match, }, }; module_i2c_driver(ssd1307fb_driver); MODULE_DESCRIPTION("FB driver for the Solomon SSD1307 OLED controller"); MODULE_AUTHOR("Maxime Ripard "); MODULE_LICENSE("GPL"); ri Pirko <jiri@mellanox.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-10sched: rename tcf_destroy to tcf_destroy_protoJiri Pirko2-6/+6 This function destroys TC filter protocol, not TC filter. So name it accordingly. Signed-off-by: Jiri Pirko <jiri@mellanox.com> Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-10ipv4: fib: Add events for FIB replace and appendIdo Schimmel1-13/+14 The FIB notification chain currently uses the NLM_F_{REPLACE,APPEND} flags to signal routes being replaced or appended. Instead of using netlink flags for in-kernel notifications we can simply introduce two new events in the FIB notification chain. This has the added advantage of making the API cleaner, thereby making it clear that these events should be supported by listeners of the notification chain. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> CC: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-10ipv4: fib: Send notification before deleting FIB aliasIdo Schimmel1-7/+7 When a FIB alias is replaced following NLM_F_REPLACE, the ENTRY_ADD notification is sent after the reference on the previous FIB info was dropped. This is problematic as potential listeners might need to access it in their notification blocks. Solve this by sending the notification prior to the deletion of the replaced FIB alias. This is consistent with ENTRY_DEL notifications. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> CC: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-10ipv4: fib: Send deletion notification with actual FIB alias typeIdo Schimmel1-2/+2 When a FIB alias is removed, a notification is sent using the type passed from user space - can be RTN_UNSPEC - instead of the actual type of the removed alias. This is problematic for listeners of the FIB notification chain, as several FIB aliases can exist with matching parameters, but the type. Solve this by passing the actual type of the removed FIB alias. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> CC: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-10ipv4: fib: Only flush FIB aliases belonging to currently flushed tableIdo Schimmel1-1/+2 In case the MAIN table is flushed and its trie is shared with the LOCAL table, then we might be flushing FIB aliases belonging to the latter. This can lead to FIB_ENTRY_DEL notifications sent with the wrong table ID. The above doesn't affect current listeners, as the table ID is ignored during entry deletion, but this will change later in the patchset. When flushing a particular table, skip any aliases belonging to a different one. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> CC: Alexander Duyck <alexander.h.duyck@intel.com> CC: Patrick McHardy <kaber@trash.net> Reviewed-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Pack struct sw_flow_key.Jarno Rajahalme4-34/+39 struct sw_flow_key has two 16-bit holes. Move the most matched conntrack match fields there. In some typical cases this reduces the size of the key that needs to be hashed into half and into one cache line. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Add force commit.Jarno Rajahalme1-2/+24 Stateful network admission policy may allow connections to one direction and reject connections initiated in the other direction. After policy change it is possible that for a new connection an overlapping conntrack entry already exists, where the original direction of the existing connection is opposed to the new connection's initial packet. Most importantly, conntrack state relating to the current packet gets the "reply" designation based on whether the original direction tuple or the reply direction tuple matched. If this "directionality" is wrong w.r.t. to the stateful network admission policy it may happen that packets in neither direction are correctly admitted. This patch adds a new "force commit" option to the OVS conntrack action that checks the original direction of an existing conntrack entry. If that direction is opposed to the current packet, the existing conntrack entry is deleted and a new one is subsequently created in the correct direction. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Add original direction conntrack tuple to sw_flow_key.Jarno Rajahalme7-46/+227 Add the fields of the conntrack original direction 5-tuple to struct sw_flow_key. The new fields are initially marked as non-existent, and are populated whenever a conntrack action is executed and either finds or generates a conntrack entry. This means that these fields exist for all packets that were not rejected by conntrack as untrackable. The original tuple fields in the sw_flow_key are filled from the original direction tuple of the conntrack entry relating to the current packet, or from the original direction tuple of the master conntrack entry, if the current conntrack entry has a master. Generally, expected connections of connections having an assigned helper (e.g., FTP), have a master conntrack entry. The main purpose of the new conntrack original tuple fields is to allow matching on them for policy decision purposes, with the premise that the admissibility of tracked connections reply packets (as well as original direction packets), and both direction packets of any related connections may be based on ACL rules applying to the master connection's original direction 5-tuple. This also makes it easier to make policy decisions when the actual packet headers might have been transformed by NAT, as the original direction 5-tuple represents the packet headers before any such transformation. When using the original direction 5-tuple the admissibility of return and/or related packets need not be based on the mere existence of a conntrack entry, allowing separation of admission policy from the established conntrack state. While existence of a conntrack entry is required for admission of the return or related packets, policy changes can render connections that were initially admitted to be rejected or dropped afterwards. If the admission of the return and related packets was based on mere conntrack state (e.g., connection being in an established state), a policy change that would make the connection rejected or dropped would need to find and delete all conntrack entries affected by such a change. When using the original direction 5-tuple matching the affected conntrack entries can be allowed to time out instead, as the established state of the connection would not need to be the basis for packet admission any more. It should be noted that the directionality of related connections may be the same or different than that of the master connection, and neither the original direction 5-tuple nor the conntrack state bits carry this information. If needed, the directionality of the master connection can be stored in master's conntrack mark or labels, which are automatically inherited by the expected related connections. The fact that neither ARP nor ND packets are trackable by conntrack allows mutual exclusion between ARP/ND and the new conntrack original tuple fields. Hence, the IP addresses are overlaid in union with ARP and ND fields. This allows the sw_flow_key to not grow much due to this patch, but it also means that we must be careful to never use the new key fields with ARP or ND packets. ARP is easy to distinguish and keep mutually exclusive based on the ethernet type, but ND being an ICMPv6 protocol requires a bit more attention. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Inherit master's labels.Jarno Rajahalme1-14/+31 We avoid calling into nf_conntrack_in() for expected connections, as that would remove the expectation that we want to stick around until we are ready to commit the connection. Instead, we do a lookup in the expectation table directly. However, after a successful expectation lookup we have set the flow key label field from the master connection, whereas nf_conntrack_in() does not do this. This leads to master's labels being inherited after an expectation lookup, but those labels not being inherited after the corresponding conntrack action with a commit flag. This patch resolves the problem by changing the commit code path to also inherit the master's labels to the expected connection. Resolving this conflict in favor of inheriting the labels allows more information be passed from the master connection to related connections, which would otherwise be much harder if the 32 bits in the connmark are not enough. Labels can still be set explicitly, so this change only affects the default values of the labels in presense of a master connection. Fixes: 7f8a436eaa2c ("openvswitch: Add conntrack action") Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Refactor labels initialization.Jarno Rajahalme1-42/+62 Refactoring conntrack labels initialization makes changes in later patches easier to review. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Simplify labels length logic.Jarno Rajahalme1-11/+9 Since 23014011ba42 ("netfilter: conntrack: support a fixed size of 128 distinct labels"), the size of conntrack labels extension has fixed to 128 bits, so we do not need to check for labels sizes shorter than 128 at run-time. This patch simplifies labels length logic accordingly, but allows the conntrack labels size to be increased in the future without breaking the build. In the event of conntrack labels increasing in size OVS would still be able to deal with the 128 first label bits. Suggested-by: Joe Stringer <joe@ovn.org> Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Unionize ovs_key_ct_label with a u32 array.Jarno Rajahalme1-7/+8 Make the array of labels in struct ovs_key_ct_label an union, adding a u32 array of the same byte size as the existing u8 array. It is faster to loop through the labels 32 bits at the time, which is also the alignment of netlink attributes. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Do not trigger events for unconfirmed connections.Jarno Rajahalme1-6/+22 Receiving change events before the 'new' event for the connection has been received can be confusing. Avoid triggering change events for setting conntrack mark or labels before the conntrack entry has been confirmed. Fixes: 182e3042e15d ("openvswitch: Allow matching on conntrack mark") Fixes: c2ac66735870 ("openvswitch: Allow matching on conntrack label") Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Use inverted tuple in ovs_ct_find_existing() if NATted.Jarno Rajahalme1-2/+22 The conntrack lookup for existing connections fails to invert the packet 5-tuple for NATted packets, and therefore fails to find the existing conntrack entry. Conntrack only stores 5-tuples for incoming packets, and there are various situations where a lookup on a packet that has already been transformed by NAT needs to be made. Looking up an existing conntrack entry upon executing packet received from the userspace is one of them. This patch fixes ovs_ct_find_existing() to invert the packet 5-tuple for the conntrack lookup whenever the packet has already been transformed by conntrack from its input form as evidenced by one of the NAT flags being set in the conntrack state metadata. Fixes: 05752523e565 ("openvswitch: Interface with NAT.") Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09openvswitch: Fix comments for skb->_nfctJarno Rajahalme1-7/+7 Fix comments referring to skb 'nfct' and 'nfctinfo' fields now that they are combined into '_nfct'. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Pravin B Shelar <pshelar@ovn.org> Acked-by: Joe Stringer <joe@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09net: dsa: Fix duplicate object ruleFlorian Fainelli1-1/+0 While adding switch.o to the list of DSA object files, we essentially duplicated the previous obj-y line and just added switch.o, remove the duplicate. Fixes: f515f192ab4f ("net: dsa: add switch notifier") Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09sctp: implement sender-side procedures for Add Incoming/Outgoing Streams ↵Xin Long2-0/+106 Request Parameter This patch is to implement Sender-Side Procedures for the Add Outgoing and Incoming Streams Request Parameter described in rfc6525 section 5.1.5-5.1.6. It is also to add sockopt SCTP_ADD_STREAMS in rfc6525 section 6.3.4 for users. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09sctp: add support for generating stream reconf add incoming/outgoing streams ↵Xin Long1-0/+46 request chunk This patch is to define Add Incoming/Outgoing Streams Request Parameter described in rfc6525 section 4.5 and 4.6. They can be in one same chunk trunk as rfc6525 section 3.1-7 describes, so make them in one function. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09sctp: implement sender-side procedures for SSN/TSN Reset Request ParameterXin Long2-0/+69 This patch is to implement Sender-Side Procedures for the SSN/TSN Reset Request Parameter descibed in rfc6525 section 5.1.4. It is also to add sockopt SCTP_RESET_ASSOC in rfc6525 section 6.3.3 for users. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09sctp: add support for generating stream reconf ssn/tsn reset request chunkXin Long1-0/+29 This patch is to define SSN/TSN Reset Request Parameter described in rfc6525 section 4.3. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-09sctp: streams should be recovered when it fails to send request.Xin Long1-2/+17 Now when sending stream reset request, it closes the streams to block further xmit of data until this request is completed, then calls sctp_send_reconf to send the chunk. But if sctp_send_reconf returns err, and it doesn't recover the streams' states back, which means the request chunk would not be queued and sent, so the asoc will get stuck, streams are closed and no packet is even queued. This patch is to fix it by recovering the streams' states when it fails to send the request, it is also to fix a return value. Fixes: 7f9d68ac944e ("sctp: implement sender-side procedures for SSN Reset Request Parameter") Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-08ipv4: fib: Notify about nexthop status changesIdo Schimmel1-0/+33 When a multipath route is hit the kernel doesn't consider nexthops that are DEAD or LINKDOWN when IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN is set. Devices that offload multipath routes need to be made aware of nexthop status changes. Otherwise, the device will keep forwarding packets to non-functional nexthops. Add the FIB_EVENT_NH_{ADD,DEL} events to the fib notification chain, which notify capable devices when they should add or delete a nexthop from their tables. Cc: Roopa Prabhu <roopa@cumulusnetworks.com> Cc: David Ahern <dsa@cumulusnetworks.com> Cc: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Andy Gospodarek <gospo@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-08bridge: vlan tunnel id info range fill size calc cleanupsRoopa Prabhu1-18/+16 This fixes a bug and cleans up tunnelid range size calculation code by using consistent variable names and checks in size calculation and fill functions. tested for a few cases of vlan-vni range mappings: (output from patched iproute2): $bridge vlan showtunnel port vid tunid vxlan0 100-105 1000-1005 200 2000 210 2100 211-213 2100-2102 214 2104 216-217 2108-2109 219 2119 Fixes: efa5356b0d97 ("bridge: per vlan dst_metadata netlink support") Reported-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-08gro_cells: move to net/core/gro_cells.cEric Dumazet6-0/+100 We have many gro cells users, so lets move the code to avoid duplication. This creates a CONFIG_GRO_CELLS option. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> 2017-02-07Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller