]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/dsa/mv88e6xxx/chip.h
822286250aff504ec03b381d65044349fd794bad
[linux.git] / drivers / net / dsa / mv88e6xxx / chip.h
1 /*
2  * Marvell 88E6xxx Ethernet switch single-chip definition
3  *
4  * Copyright (c) 2008 Marvell Semiconductor
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11
12 #ifndef _MV88E6XXX_CHIP_H
13 #define _MV88E6XXX_CHIP_H
14
15 #include <linux/if_vlan.h>
16 #include <linux/irq.h>
17 #include <linux/gpio/consumer.h>
18 #include <linux/phy.h>
19 #include <net/dsa.h>
20
21 #ifndef UINT64_MAX
22 #define UINT64_MAX              (u64)(~((u64)0))
23 #endif
24
25 #define SMI_CMD                 0x00
26 #define SMI_CMD_BUSY            BIT(15)
27 #define SMI_CMD_CLAUSE_22       BIT(12)
28 #define SMI_CMD_OP_22_WRITE     ((1 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
29 #define SMI_CMD_OP_22_READ      ((2 << 10) | SMI_CMD_BUSY | SMI_CMD_CLAUSE_22)
30 #define SMI_CMD_OP_45_WRITE_ADDR        ((0 << 10) | SMI_CMD_BUSY)
31 #define SMI_CMD_OP_45_WRITE_DATA        ((1 << 10) | SMI_CMD_BUSY)
32 #define SMI_CMD_OP_45_READ_DATA         ((2 << 10) | SMI_CMD_BUSY)
33 #define SMI_CMD_OP_45_READ_DATA_INC     ((3 << 10) | SMI_CMD_BUSY)
34 #define SMI_DATA                0x01
35
36 #define MV88E6XXX_N_FID         4096
37
38 /* PVT limits for 4-bit port and 5-bit switch */
39 #define MV88E6XXX_MAX_PVT_SWITCHES      32
40 #define MV88E6XXX_MAX_PVT_PORTS         16
41
42 enum mv88e6xxx_egress_mode {
43         MV88E6XXX_EGRESS_MODE_UNMODIFIED,
44         MV88E6XXX_EGRESS_MODE_UNTAGGED,
45         MV88E6XXX_EGRESS_MODE_TAGGED,
46         MV88E6XXX_EGRESS_MODE_ETHERTYPE,
47 };
48
49 enum mv88e6xxx_frame_mode {
50         MV88E6XXX_FRAME_MODE_NORMAL,
51         MV88E6XXX_FRAME_MODE_DSA,
52         MV88E6XXX_FRAME_MODE_PROVIDER,
53         MV88E6XXX_FRAME_MODE_ETHERTYPE,
54 };
55
56 /* List of supported models */
57 enum mv88e6xxx_model {
58         MV88E6085,
59         MV88E6095,
60         MV88E6097,
61         MV88E6123,
62         MV88E6131,
63         MV88E6141,
64         MV88E6161,
65         MV88E6165,
66         MV88E6171,
67         MV88E6172,
68         MV88E6175,
69         MV88E6176,
70         MV88E6185,
71         MV88E6190,
72         MV88E6190X,
73         MV88E6191,
74         MV88E6240,
75         MV88E6290,
76         MV88E6320,
77         MV88E6321,
78         MV88E6341,
79         MV88E6350,
80         MV88E6351,
81         MV88E6352,
82         MV88E6390,
83         MV88E6390X,
84 };
85
86 enum mv88e6xxx_family {
87         MV88E6XXX_FAMILY_NONE,
88         MV88E6XXX_FAMILY_6065,  /* 6031 6035 6061 6065 */
89         MV88E6XXX_FAMILY_6095,  /* 6092 6095 */
90         MV88E6XXX_FAMILY_6097,  /* 6046 6085 6096 6097 */
91         MV88E6XXX_FAMILY_6165,  /* 6123 6161 6165 */
92         MV88E6XXX_FAMILY_6185,  /* 6108 6121 6122 6131 6152 6155 6182 6185 */
93         MV88E6XXX_FAMILY_6320,  /* 6320 6321 */
94         MV88E6XXX_FAMILY_6341,  /* 6141 6341 */
95         MV88E6XXX_FAMILY_6351,  /* 6171 6175 6350 6351 */
96         MV88E6XXX_FAMILY_6352,  /* 6172 6176 6240 6352 */
97         MV88E6XXX_FAMILY_6390,  /* 6190 6190X 6191 6290 6390 6390X */
98 };
99
100 enum mv88e6xxx_cap {
101         /* Energy Efficient Ethernet.
102          */
103         MV88E6XXX_CAP_EEE,
104
105         /* Multi-chip Addressing Mode.
106          * Some chips respond to only 2 registers of its own SMI device address
107          * when it is non-zero, and use indirect access to internal registers.
108          */
109         MV88E6XXX_CAP_SMI_CMD,          /* (0x00) SMI Command */
110         MV88E6XXX_CAP_SMI_DATA,         /* (0x01) SMI Data */
111
112         /* Switch Global 2 Registers.
113          * The device contains a second set of global 16-bit registers.
114          */
115         MV88E6XXX_CAP_GLOBAL2,
116 };
117
118 /* Bitmask of capabilities */
119 #define MV88E6XXX_FLAG_EEE              BIT_ULL(MV88E6XXX_CAP_EEE)
120
121 #define MV88E6XXX_FLAG_SMI_CMD          BIT_ULL(MV88E6XXX_CAP_SMI_CMD)
122 #define MV88E6XXX_FLAG_SMI_DATA         BIT_ULL(MV88E6XXX_CAP_SMI_DATA)
123
124 #define MV88E6XXX_FLAG_GLOBAL2          BIT_ULL(MV88E6XXX_CAP_GLOBAL2)
125
126 /* Multi-chip Addressing Mode */
127 #define MV88E6XXX_FLAGS_MULTI_CHIP      \
128         (MV88E6XXX_FLAG_SMI_CMD |       \
129          MV88E6XXX_FLAG_SMI_DATA)
130
131 #define MV88E6XXX_FLAGS_FAMILY_6095     \
132         (MV88E6XXX_FLAG_GLOBAL2 |       \
133          MV88E6XXX_FLAGS_MULTI_CHIP)
134
135 #define MV88E6XXX_FLAGS_FAMILY_6097     \
136         (MV88E6XXX_FLAG_GLOBAL2 |       \
137          MV88E6XXX_FLAGS_MULTI_CHIP)
138
139 #define MV88E6XXX_FLAGS_FAMILY_6165     \
140         (MV88E6XXX_FLAG_GLOBAL2 |       \
141          MV88E6XXX_FLAGS_MULTI_CHIP)
142
143 #define MV88E6XXX_FLAGS_FAMILY_6185     \
144         (MV88E6XXX_FLAG_GLOBAL2 |       \
145          MV88E6XXX_FLAGS_MULTI_CHIP)
146
147 #define MV88E6XXX_FLAGS_FAMILY_6320     \
148         (MV88E6XXX_FLAG_EEE |           \
149          MV88E6XXX_FLAG_GLOBAL2 |       \
150          MV88E6XXX_FLAGS_MULTI_CHIP)
151
152 #define MV88E6XXX_FLAGS_FAMILY_6341     \
153         (MV88E6XXX_FLAG_EEE |           \
154          MV88E6XXX_FLAG_GLOBAL2 |       \
155          MV88E6XXX_FLAGS_MULTI_CHIP)
156
157 #define MV88E6XXX_FLAGS_FAMILY_6351     \
158         (MV88E6XXX_FLAG_GLOBAL2 |       \
159          MV88E6XXX_FLAGS_MULTI_CHIP)
160
161 #define MV88E6XXX_FLAGS_FAMILY_6352     \
162         (MV88E6XXX_FLAG_EEE |           \
163          MV88E6XXX_FLAG_GLOBAL2 |       \
164          MV88E6XXX_FLAGS_MULTI_CHIP)
165
166 #define MV88E6XXX_FLAGS_FAMILY_6390     \
167         (MV88E6XXX_FLAG_EEE |           \
168          MV88E6XXX_FLAG_GLOBAL2 |       \
169          MV88E6XXX_FLAGS_MULTI_CHIP)
170
171 struct mv88e6xxx_ops;
172
173 struct mv88e6xxx_info {
174         enum mv88e6xxx_family family;
175         u16 prod_num;
176         const char *name;
177         unsigned int num_databases;
178         unsigned int num_ports;
179         unsigned int max_vid;
180         unsigned int port_base_addr;
181         unsigned int global1_addr;
182         unsigned int age_time_coeff;
183         unsigned int g1_irqs;
184         unsigned int g2_irqs;
185         bool pvt;
186         enum dsa_tag_protocol tag_protocol;
187         unsigned long long flags;
188
189         /* Mask for FromPort and ToPort value of PortVec used in ATU Move
190          * operation. 0 means that the ATU Move operation is not supported.
191          */
192         u8 atu_move_port_mask;
193         const struct mv88e6xxx_ops *ops;
194 };
195
196 struct mv88e6xxx_atu_entry {
197         u8      state;
198         bool    trunk;
199         u16     portvec;
200         u8      mac[ETH_ALEN];
201 };
202
203 struct mv88e6xxx_vtu_entry {
204         u16     vid;
205         u16     fid;
206         u8      sid;
207         bool    valid;
208         u8      member[DSA_MAX_PORTS];
209         u8      state[DSA_MAX_PORTS];
210 };
211
212 struct mv88e6xxx_bus_ops;
213 struct mv88e6xxx_irq_ops;
214
215 struct mv88e6xxx_irq {
216         u16 masked;
217         struct irq_chip chip;
218         struct irq_domain *domain;
219         unsigned int nirqs;
220 };
221
222 struct mv88e6xxx_chip {
223         const struct mv88e6xxx_info *info;
224
225         /* The dsa_switch this private structure is related to */
226         struct dsa_switch *ds;
227
228         /* The device this structure is associated to */
229         struct device *dev;
230
231         /* This mutex protects the access to the switch registers */
232         struct mutex reg_lock;
233
234         /* The MII bus and the address on the bus that is used to
235          * communication with the switch
236          */
237         const struct mv88e6xxx_bus_ops *smi_ops;
238         struct mii_bus *bus;
239         int sw_addr;
240
241         /* Handles automatic disabling and re-enabling of the PHY
242          * polling unit.
243          */
244         const struct mv88e6xxx_bus_ops *phy_ops;
245         struct mutex            ppu_mutex;
246         int                     ppu_disabled;
247         struct work_struct      ppu_work;
248         struct timer_list       ppu_timer;
249
250         /* This mutex serialises access to the statistics unit.
251          * Hold this mutex over snapshot + dump sequences.
252          */
253         struct mutex    stats_mutex;
254
255         /* A switch may have a GPIO line tied to its reset pin. Parse
256          * this from the device tree, and use it before performing
257          * switch soft reset.
258          */
259         struct gpio_desc *reset;
260
261         /* set to size of eeprom if supported by the switch */
262         int             eeprom_len;
263
264         /* List of mdio busses */
265         struct list_head mdios;
266
267         /* There can be two interrupt controllers, which are chained
268          * off a GPIO as interrupt source
269          */
270         struct mv88e6xxx_irq g1_irq;
271         struct mv88e6xxx_irq g2_irq;
272         int irq;
273         int device_irq;
274         int watchdog_irq;
275 };
276
277 struct mv88e6xxx_bus_ops {
278         int (*read)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
279         int (*write)(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
280 };
281
282 struct mv88e6xxx_mdio_bus {
283         struct mii_bus *bus;
284         struct mv88e6xxx_chip *chip;
285         struct list_head list;
286         bool external;
287 };
288
289 struct mv88e6xxx_ops {
290         /* Ingress Rate Limit unit (IRL) operations */
291         int (*irl_init_all)(struct mv88e6xxx_chip *chip, int port);
292
293         int (*get_eeprom)(struct mv88e6xxx_chip *chip,
294                           struct ethtool_eeprom *eeprom, u8 *data);
295         int (*set_eeprom)(struct mv88e6xxx_chip *chip,
296                           struct ethtool_eeprom *eeprom, u8 *data);
297
298         int (*set_switch_mac)(struct mv88e6xxx_chip *chip, u8 *addr);
299
300         int (*phy_read)(struct mv88e6xxx_chip *chip,
301                         struct mii_bus *bus,
302                         int addr, int reg, u16 *val);
303         int (*phy_write)(struct mv88e6xxx_chip *chip,
304                          struct mii_bus *bus,
305                          int addr, int reg, u16 val);
306
307         /* Priority Override Table operations */
308         int (*pot_clear)(struct mv88e6xxx_chip *chip);
309
310         /* PHY Polling Unit (PPU) operations */
311         int (*ppu_enable)(struct mv88e6xxx_chip *chip);
312         int (*ppu_disable)(struct mv88e6xxx_chip *chip);
313
314         /* Switch Software Reset */
315         int (*reset)(struct mv88e6xxx_chip *chip);
316
317         /* RGMII Receive/Transmit Timing Control
318          * Add delay on PHY_INTERFACE_MODE_RGMII_*ID, no delay otherwise.
319          */
320         int (*port_set_rgmii_delay)(struct mv88e6xxx_chip *chip, int port,
321                                     phy_interface_t mode);
322
323 #define LINK_FORCED_DOWN        0
324 #define LINK_FORCED_UP          1
325 #define LINK_UNFORCED           -2
326
327         /* Port's MAC link state
328          * Use LINK_FORCED_UP or LINK_FORCED_DOWN to force link up or down,
329          * or LINK_UNFORCED for normal link detection.
330          */
331         int (*port_set_link)(struct mv88e6xxx_chip *chip, int port, int link);
332
333 #define DUPLEX_UNFORCED         -2
334
335         /* Port's MAC duplex mode
336          *
337          * Use DUPLEX_HALF or DUPLEX_FULL to force half or full duplex,
338          * or DUPLEX_UNFORCED for normal duplex detection.
339          */
340         int (*port_set_duplex)(struct mv88e6xxx_chip *chip, int port, int dup);
341
342 #define SPEED_MAX               INT_MAX
343 #define SPEED_UNFORCED          -2
344
345         /* Port's MAC speed (in Mbps)
346          *
347          * Depending on the chip, 10, 100, 200, 1000, 2500, 10000 are valid.
348          * Use SPEED_UNFORCED for normal detection, SPEED_MAX for max value.
349          */
350         int (*port_set_speed)(struct mv88e6xxx_chip *chip, int port, int speed);
351
352         int (*port_tag_remap)(struct mv88e6xxx_chip *chip, int port);
353
354         int (*port_set_frame_mode)(struct mv88e6xxx_chip *chip, int port,
355                                    enum mv88e6xxx_frame_mode mode);
356         int (*port_set_egress_floods)(struct mv88e6xxx_chip *chip, int port,
357                                       bool unicast, bool multicast);
358         int (*port_set_ether_type)(struct mv88e6xxx_chip *chip, int port,
359                                    u16 etype);
360         int (*port_set_jumbo_size)(struct mv88e6xxx_chip *chip, int port,
361                                    size_t size);
362
363         int (*port_egress_rate_limiting)(struct mv88e6xxx_chip *chip, int port);
364         int (*port_pause_limit)(struct mv88e6xxx_chip *chip, int port, u8 in,
365                                 u8 out);
366         int (*port_disable_learn_limit)(struct mv88e6xxx_chip *chip, int port);
367         int (*port_disable_pri_override)(struct mv88e6xxx_chip *chip, int port);
368
369         /* CMODE control what PHY mode the MAC will use, eg. SGMII, RGMII, etc.
370          * Some chips allow this to be configured on specific ports.
371          */
372         int (*port_set_cmode)(struct mv88e6xxx_chip *chip, int port,
373                               phy_interface_t mode);
374
375         /* Some devices have a per port register indicating what is
376          * the upstream port this port should forward to.
377          */
378         int (*port_set_upstream_port)(struct mv88e6xxx_chip *chip, int port,
379                                       int upstream_port);
380
381         /* Snapshot the statistics for a port. The statistics can then
382          * be read back a leisure but still with a consistent view.
383          */
384         int (*stats_snapshot)(struct mv88e6xxx_chip *chip, int port);
385
386         /* Set the histogram mode for statistics, when the control registers
387          * are separated out of the STATS_OP register.
388          */
389         int (*stats_set_histogram)(struct mv88e6xxx_chip *chip);
390
391         /* Return the number of strings describing statistics */
392         int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip);
393         void (*stats_get_strings)(struct mv88e6xxx_chip *chip,  uint8_t *data);
394         void (*stats_get_stats)(struct mv88e6xxx_chip *chip,  int port,
395                                 uint64_t *data);
396         int (*set_cpu_port)(struct mv88e6xxx_chip *chip, int port);
397         int (*set_egress_port)(struct mv88e6xxx_chip *chip, int port);
398         const struct mv88e6xxx_irq_ops *watchdog_ops;
399
400         int (*mgmt_rsvd2cpu)(struct mv88e6xxx_chip *chip);
401
402         /* Power on/off a SERDES interface */
403         int (*serdes_power)(struct mv88e6xxx_chip *chip, int port, bool on);
404
405         /* VLAN Translation Unit operations */
406         int (*vtu_getnext)(struct mv88e6xxx_chip *chip,
407                            struct mv88e6xxx_vtu_entry *entry);
408         int (*vtu_loadpurge)(struct mv88e6xxx_chip *chip,
409                              struct mv88e6xxx_vtu_entry *entry);
410 };
411
412 struct mv88e6xxx_irq_ops {
413         /* Action to be performed when the interrupt happens */
414         int (*irq_action)(struct mv88e6xxx_chip *chip, int irq);
415         /* Setup the hardware to generate the interrupt */
416         int (*irq_setup)(struct mv88e6xxx_chip *chip);
417         /* Reset the hardware to stop generating the interrupt */
418         void (*irq_free)(struct mv88e6xxx_chip *chip);
419 };
420
421 #define STATS_TYPE_PORT         BIT(0)
422 #define STATS_TYPE_BANK0        BIT(1)
423 #define STATS_TYPE_BANK1        BIT(2)
424
425 struct mv88e6xxx_hw_stat {
426         char string[ETH_GSTRING_LEN];
427         int sizeof_stat;
428         int reg;
429         int type;
430 };
431
432 static inline bool mv88e6xxx_has(struct mv88e6xxx_chip *chip,
433                                  unsigned long flags)
434 {
435         return (chip->info->flags & flags) == flags;
436 }
437
438 static inline bool mv88e6xxx_has_pvt(struct mv88e6xxx_chip *chip)
439 {
440         return chip->info->pvt;
441 }
442
443 static inline unsigned int mv88e6xxx_num_databases(struct mv88e6xxx_chip *chip)
444 {
445         return chip->info->num_databases;
446 }
447
448 static inline unsigned int mv88e6xxx_num_ports(struct mv88e6xxx_chip *chip)
449 {
450         return chip->info->num_ports;
451 }
452
453 static inline u16 mv88e6xxx_port_mask(struct mv88e6xxx_chip *chip)
454 {
455         return GENMASK(mv88e6xxx_num_ports(chip) - 1, 0);
456 }
457
458 int mv88e6xxx_read(struct mv88e6xxx_chip *chip, int addr, int reg, u16 *val);
459 int mv88e6xxx_write(struct mv88e6xxx_chip *chip, int addr, int reg, u16 val);
460 int mv88e6xxx_update(struct mv88e6xxx_chip *chip, int addr, int reg,
461                      u16 update);
462 int mv88e6xxx_wait(struct mv88e6xxx_chip *chip, int addr, int reg, u16 mask);
463 struct mii_bus *mv88e6xxx_default_mdio_bus(struct mv88e6xxx_chip *chip);
464
465 #endif /* _MV88E6XXX_CHIP_H */