Changeset 21714


Ignore:
Timestamp:
2010-06-08T22:18:20+02:00 (6 years ago)
Author:
juhosg
Message:

ip17xx: Introduce indirection of low-level operations

This patch introduces seperation between low-level and high-level parts
of the driver. The low-level functions are now called via pointers stored
in struct ip175c_regs.

The only functional changes are:

o correct_vlan_state() is now called as a part of every update_state().

o The order of setting of MODE_REG and resetting switch ports

has changed. (These are independent actions, so it should not matter.)

o ip175c_set_tagged() sets the tags via update_state() instead of writing

directly to the registers.

o The same for ip175c_set_pvid().

The only gaps in this abstraction are operations on ports (get_port_speed
and friends), which access PHY registers directly.

Signed-off-by: Martin Mares <mj@…>
Signed-off-by: Patrick Horn <patrick.horn@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/target/linux/generic-2.6/files/drivers/net/phy/ip175c.c

    r21713 r21714  
    4141#define REG_SUPP(x) (((x).m != ((u16)-1)) && ((x).p != (u16)-1)) 
    4242 
     43struct ip175c_state; 
     44 
    4345/*********** CONSTANTS ***********/ 
    4446struct register_mappings { 
     
    9799        // set to 1 for 178C, 0 for 175C. 
    98100        bitnum SIMPLE_VLAN_REGISTERS;   // 175C has two vlans per register but 178C has only one. 
     101 
     102        // Pointers to functions which manipulate hardware state 
     103        int (*get_flags)(struct ip175c_state *state); 
     104        int (*get_state)(struct ip175c_state *state); 
     105        int (*update_state)(struct ip175c_state *state); 
     106        int (*set_vlan_mode)(struct ip175c_state *state); 
     107        int (*reset)(struct ip175c_state *state); 
    99108}; 
     109 
     110static int ip175c_get_flags(struct ip175c_state *state); 
     111static int ip175c_get_state(struct ip175c_state *state); 
     112static int ip175c_update_state(struct ip175c_state *state); 
     113static int ip175c_set_vlan_mode(struct ip175c_state *state); 
     114static int ip175c_do_reset(struct ip175c_state *state); 
    100115 
    101116static const struct register_mappings IP178C = { 
     
    141156        .MII_REGISTER_EN = NOTSUPPORTED, 
    142157 
     158        .get_flags = ip175c_get_flags, 
     159        .get_state = ip175c_get_state, 
     160        .update_state = ip175c_update_state, 
     161        .set_vlan_mode = ip175c_set_vlan_mode, 
     162        .reset = ip175c_do_reset, 
    143163}; 
    144164 
     
    185205        .MII_REGISTER_EN = NOTSUPPORTED, 
    186206 
     207        .get_flags = ip175c_get_flags, 
     208        .get_state = ip175c_get_state, 
     209        .update_state = ip175c_update_state, 
     210        .set_vlan_mode = ip175c_set_vlan_mode, 
     211        .reset = ip175c_do_reset, 
    187212}; 
    188213 
     
    229254        .MII_REGISTER_EN = {0, 18}, 
    230255        .MII_REGISTER_EN_BIT = 7, 
     256 
     257        .get_flags = ip175c_get_flags, 
     258        .get_state = ip175c_get_state, 
     259        .update_state = ip175c_update_state, 
     260        .set_vlan_mode = ip175c_set_vlan_mode, 
     261        .reset = ip175c_do_reset, 
    231262}; 
    232263 
     
    386417 
    387418/** Get only the vlan and router flags on the router **/ 
    388 static int get_flags(struct ip175c_state *state) 
     419static int ip175c_get_flags(struct ip175c_state *state) 
    389420{ 
    390421        int val; 
     
    422453 
    423454/** Get all state variables for VLAN mappings and port-based tagging **/ 
    424 static int get_state(struct ip175c_state *state) 
     455static int ip175c_get_state(struct ip175c_state *state) 
    425456{ 
    426457        int i, j; 
    427458        int ret; 
    428         ret = get_flags(state); 
     459 
     460        ret = ip175c_get_flags(state); 
    429461        if (ret < 0) { 
    430462                return ret; 
    431463        } 
     464 
    432465        GET_PORT_BITS(state, state->remove_tag, 
    433466                                  state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT); 
     
    520553} 
    521554 
    522 /** Only update vlan and router flags in the switch **/ 
    523 static int update_flags(struct ip175c_state *state) 
     555/** Only set vlan and router flags in the switch **/ 
     556static int ip175c_set_flags(struct ip175c_state *state) 
    524557{ 
    525558        int val; 
     
    558591} 
    559592 
    560 /** Update all VLAN and port state.  Usually you should call "correct_vlan_state" first. **/ 
    561 static int update_state(struct ip175c_state *state) 
     593/** Set all VLAN and port state.  Usually you should call "correct_vlan_state" first. **/ 
     594static int ip175c_set_state(struct ip175c_state *state) 
    562595{ 
    563596        int j; 
     
    632665        } 
    633666 
    634         return update_flags(state); 
     667        return ip175c_set_flags(state); 
    635668} 
    636669 
     
    639672 *  which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids. 
    640673 */ 
    641 static void correct_vlan_state(struct ip175c_state *state) 
     674static void ip175c_correct_vlan_state(struct ip175c_state *state) 
    642675{ 
    643676        int i, j; 
     
    665698} 
    666699 
     700static int ip175c_update_state(struct ip175c_state *state) 
     701{ 
     702        ip175c_correct_vlan_state(state); 
     703        return ip175c_set_state(state); 
     704} 
     705 
     706static int ip175c_set_vlan_mode(struct ip175c_state *state) 
     707{ 
     708        return ip175c_update_state(state); 
     709} 
     710 
     711static int ip175c_do_reset(struct ip175c_state *state) 
     712{ 
     713        int err; 
     714 
     715        if (REG_SUPP(state->regs->MODE_REG)) { 
     716                err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL); 
     717                if (err < 0) 
     718                        return err; 
     719                err = getPhy(state, state->regs->MODE_REG); 
     720                if (err < 0) 
     721                        return err; 
     722        } 
     723 
     724        return 0; 
     725} 
     726 
    667727static int ip175c_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val) 
    668728{ 
     
    670730        int err; 
    671731 
    672         err = get_state(state); // May be set in get_state. 
     732        err = state->regs->get_state(state); // May be set in get_state. 
    673733        if (err < 0) 
    674734                return err; 
     
    684744        int i; 
    685745 
    686         err = get_state(state); 
     746        err = state->regs->get_state(state); 
    687747        if (err < 0) 
    688748                return err; 
     
    698758        state->remove_tag = 0x0000; 
    699759        state->add_tag = 0x0000; 
    700         for (i = 0; i < MAX_PORTS; i++) 
    701                 state->ports[i].shareports = 0xffff; 
    702  
    703760        for (i = 0; i < MAX_VLANS; i++) 
    704761                state->vlan_ports[i] = 0x0; 
    705762 
    706         if (state->vlan_enabled) { 
    707                 // Updates other fields only based off vlan_ports and add_tag fields. 
    708                 // Note that by default, no ports are in any vlans. 
    709                 correct_vlan_state(state); 
    710         } 
    711         // Ensure sane defaults? 
    712         return update_state(state); 
     763        return state->regs->set_vlan_mode(state); 
    713764} 
    714765 
     
    724775                return -EINVAL; 
    725776 
    726         err = get_state(state); 
     777        err = state->regs->get_state(state); 
    727778        if (err<0) 
    728779                return err; 
     
    755806                return -EINVAL; 
    756807 
    757         err = get_state(state); 
     808        err = state->regs->get_state(state); 
    758809        if (err < 0) 
    759810                return err; 
     
    770821        } 
    771822 
    772         correct_vlan_state(state); 
    773         err = update_state(state); 
    774  
    775         return err; 
     823        return state->regs->update_state(state); 
    776824} 
    777825 
     
    781829        int err; 
    782830 
    783         err = get_flags(state); 
     831        err = state->regs->get_flags(state); 
    784832        if (err < 0) 
    785833                return err; 
     
    801849        int i, err; 
    802850 
    803         err = get_flags(state); 
     851        err = state->regs->get_flags(state); 
    804852        if (err < 0) 
    805853                return err; 
     
    819867        } 
    820868 
    821         if (REG_SUPP(state->regs->MODE_REG)) { 
    822                 err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL); 
    823                 if (err < 0) 
    824                         return err; 
    825                 err = getPhy(state, state->regs->MODE_REG); 
    826         } 
    827  
    828869        /* reset switch ports */ 
    829870        for (i = 0; i < state->regs->NUM_PORTS-1; i++) { 
     
    833874        } 
    834875 
    835         return 0; 
     876        return state->regs->reset(state); 
    836877} 
    837878 
     
    841882        int err; 
    842883 
    843         err = get_state(state); 
     884        err = state->regs->get_state(state); 
    844885        if (err < 0) 
    845886                return err; 
     
    864905        int err; 
    865906 
    866         err = get_state(state); 
     907        err = state->regs->get_state(state); 
    867908        if (err < 0) 
    868909                return err; 
     
    876917                state->add_tag |= (1<<val->port_vlan); 
    877918 
    878         SET_PORT_BITS(state, state->add_tag, 
    879                                   state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT); 
    880         SET_PORT_BITS(state, state->remove_tag, 
    881                                   state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT); 
    882  
    883         return err; 
     919        return state->regs->update_state(state); 
    884920} 
    885921 
     
    10831119{ 
    10841120        struct ip175c_state *state = dev->priv; 
     1121        int err; 
     1122 
     1123        if (val < 0 || val >= MAX_VLANS) 
     1124                return -EINVAL; 
     1125 
     1126        err = state->regs->get_state(state); 
     1127        if (err < 0) 
     1128                return err; 
    10851129 
    10861130        state->ports[port].pvid = val; 
    10871131 
    1088         if (!REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[port])) 
    1089                 return 0; 
    1090  
    1091         return setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[port], val); 
     1132        return state->regs->update_state(state); 
    10921133} 
    10931134 
Note: See TracChangeset for help on using the changeset viewer.