1219820Sjeff/*
2219820Sjeff * Copyright (c) 2006 Cisco Systems, Inc.  All rights reserved.
3219820Sjeff *
4219820Sjeff * This software is available to you under a choice of one of two
5219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
6219820Sjeff * General Public License (GPL) Version 2, available from the file
7219820Sjeff * COPYING in the main directory of this source tree, or the
8219820Sjeff * OpenIB.org BSD license below:
9219820Sjeff *
10219820Sjeff *     Redistribution and use in source and binary forms, with or
11219820Sjeff *     without modification, are permitted provided that the following
12219820Sjeff *     conditions are met:
13219820Sjeff *
14219820Sjeff *      - Redistributions of source code must retain the above
15219820Sjeff *        copyright notice, this list of conditions and the following
16219820Sjeff *        disclaimer.
17219820Sjeff *
18219820Sjeff *      - Redistributions in binary form must reproduce the above
19219820Sjeff *        copyright notice, this list of conditions and the following
20219820Sjeff *        disclaimer in the documentation and/or other materials
21219820Sjeff *        provided with the distribution.
22219820Sjeff *
23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30219820Sjeff * SOFTWARE.
31219820Sjeff */
32219820Sjeff
33219820Sjeff#ifndef MLX4_DRIVER_H
34219820Sjeff#define MLX4_DRIVER_H
35219820Sjeff
36255932Salfred#include <linux/mlx4/device.h>
37219820Sjeff
38219820Sjeffstruct mlx4_dev;
39219820Sjeff
40255932Salfred#define MLX4_MAC_MASK	   0xffffffffffffULL
41255932Salfred#define MLX4_BE_SHORT_MASK cpu_to_be16(0xffff)
42255932Salfred#define MLX4_BE_WORD_MASK  cpu_to_be32(0xffffffff)
43255932Salfred
44219820Sjeffenum mlx4_dev_event {
45219820Sjeff	MLX4_DEV_EVENT_CATASTROPHIC_ERROR,
46219820Sjeff	MLX4_DEV_EVENT_PORT_UP,
47219820Sjeff	MLX4_DEV_EVENT_PORT_DOWN,
48219820Sjeff	MLX4_DEV_EVENT_PORT_REINIT,
49255932Salfred	MLX4_DEV_EVENT_PORT_MGMT_CHANGE,
50255932Salfred	MLX4_DEV_EVENT_SLAVE_INIT,
51255932Salfred	MLX4_DEV_EVENT_SLAVE_SHUTDOWN,
52219820Sjeff};
53219820Sjeff
54219820Sjeffstruct mlx4_interface {
55219820Sjeff	void *			(*add)	 (struct mlx4_dev *dev);
56219820Sjeff	void			(*remove)(struct mlx4_dev *dev, void *context);
57219820Sjeff	void			(*event) (struct mlx4_dev *dev, void *context,
58255932Salfred					  enum mlx4_dev_event event, unsigned long param);
59255932Salfred	void *			(*get_dev)(struct mlx4_dev *dev, void *context, u8 port);
60219820Sjeff	struct list_head	list;
61255932Salfred	enum mlx4_protocol	protocol;
62219820Sjeff};
63219820Sjeff
64272407Shselaskyenum {
65272407Shselasky	MLX4_MAX_DEVICES	= 32,
66272407Shselasky	MLX4_DEVS_TBL_SIZE	= MLX4_MAX_DEVICES + 1,
67272407Shselasky	MLX4_DBDF2VAL_STR_SIZE	= 512,
68272407Shselasky	MLX4_STR_NAME_SIZE	= 64,
69272407Shselasky	MLX4_MAX_BDF_VALS	= 2,
70272407Shselasky	MLX4_ENDOF_TBL		= -1LL
71272407Shselasky};
72272407Shselasky
73272407Shselaskystruct mlx4_dbdf2val {
74272407Shselasky	u64 dbdf;
75272407Shselasky	int val[MLX4_MAX_BDF_VALS];
76272407Shselasky};
77272407Shselasky
78272407Shselaskystruct mlx4_range {
79272407Shselasky	int min;
80272407Shselasky	int max;
81272407Shselasky};
82272407Shselasky
83272407Shselasky/*
84272407Shselasky * mlx4_dbdf2val_lst struct holds all the data needed to convert
85272407Shselasky * dbdf-to-value-list string into dbdf-to-value table.
86272407Shselasky * dbdf-to-value-list string is a comma separated list of dbdf-to-value strings.
87272407Shselasky * the format of dbdf-to-value string is: "[mmmm:]bb:dd.f-v1[;v2]"
88272407Shselasky * mmmm - Domain number (optional)
89272407Shselasky * bb - Bus number
90272407Shselasky * dd - device number
91272407Shselasky * f  - Function number
92272407Shselasky * v1 - First value related to the domain-bus-device-function.
93272407Shselasky * v2 - Second value related to the domain-bus-device-function (optional).
94272407Shselasky * bb, dd - Two hexadecimal digits without preceding 0x.
95272407Shselasky * mmmm - Four hexadecimal digits without preceding 0x.
96272407Shselasky * f  - One hexadecimal without preceding 0x.
97272407Shselasky * v1,v2 - Number with normal convention (e.g 100, 0xd3).
98272407Shselasky * dbdf-to-value-list string format:
99272407Shselasky *     "[mmmm:]bb:dd.f-v1[;v2],[mmmm:]bb:dd.f-v1[;v2],..."
100272407Shselasky *
101272407Shselasky */
102272407Shselaskystruct mlx4_dbdf2val_lst {
103272407Shselasky	char		name[MLX4_STR_NAME_SIZE];    /* String name */
104272407Shselasky	char		str[MLX4_DBDF2VAL_STR_SIZE]; /* dbdf2val list str */
105272407Shselasky	struct mlx4_dbdf2val tbl[MLX4_DEVS_TBL_SIZE];/* dbdf to value table */
106272407Shselasky	int		num_vals;		     /* # of vals per dbdf */
107272407Shselasky	int		def_val[MLX4_MAX_BDF_VALS];  /* Default values */
108272407Shselasky	struct mlx4_range range;		     /* Valid values range */
109272407Shselasky};
110272407Shselasky
111272407Shselaskyint mlx4_fill_dbdf2val_tbl(struct mlx4_dbdf2val_lst *dbdf2val_lst);
112272407Shselaskyint mlx4_get_val(struct mlx4_dbdf2val *tbl, struct pci_dev *pdev, int idx,
113272407Shselasky		 int *val);
114272407Shselasky
115219820Sjeffint mlx4_register_interface(struct mlx4_interface *intf);
116219820Sjeffvoid mlx4_unregister_interface(struct mlx4_interface *intf);
117219820Sjeff
118272407Shselaskyvoid *mlx4_get_protocol_dev(struct mlx4_dev *dev, enum mlx4_protocol proto,
119272407Shselasky			    int port);
120219820Sjeff
121255932Salfred#ifndef ETH_ALEN
122255932Salfred#define ETH_ALEN	6
123255932Salfred#endif
124273246Shselaskystatic inline u64 mlx4_mac_to_u64(const u8 *addr)
125255932Salfred{
126255932Salfred	u64 mac = 0;
127255932Salfred	int i;
128255932Salfred
129255932Salfred	for (i = 0; i < ETH_ALEN; i++) {
130255932Salfred		mac <<= 8;
131255932Salfred		mac |= addr[i];
132255932Salfred	}
133255932Salfred	return mac;
134255932Salfred}
135255932Salfred
136219820Sjeff#endif /* MLX4_DRIVER_H */
137