1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
14 * FBI board dependent Driver for SMT and LLC
20 #include "h/supern_2.h"
21 #include "h/skfbiinc.h"
22 #include <linux/bitrev.h>
23 #include <linux/pci_regs.h>
26 static const char ID_sccs[] = "@(#)drvfbi.c 1.63 99/02/11 (C) SK " ;
34 #define LED_Y_ON 0x11 /* Used for ring up/down indication */
35 #define LED_Y_OFF 0x10
38 #define MS2BCLK(x) ((x)*12500L)
41 * valid configuration values are:
48 * | --------------------- the patched POS_ID of the Adapter
49 * | xxxx = (Vendor ID low byte,
50 * | Vendor ID high byte,
51 * | Device ID low byte,
52 * | Device ID high byte)
53 * +------------------------------ the patched oem_id must be
54 * 'S' for SK or 'I' for IBM
55 * this is a short id for the driver.
59 const u_char oem_id[] = "xPOS_ID:xxxx" ;
60 #else /* OEM_CONCEPT */
61 const u_char oem_id[] = OEM_ID ;
62 #endif /* OEM_CONCEPT */
64 #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
66 const struct s_oem_ids oem_ids[] = {
70 #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
73 /* Prototypes of external functions */
75 extern int AIX_vpdReadByte() ;
79 /* Prototype of a local function. */
80 static void smt_stop_watchdog(struct s_smc *smc);
85 static void card_start(struct s_smc *smc)
93 smt_stop_watchdog(smc) ;
97 * make sure no transfer activity is pending
99 outpw(FM_A(FM_MDREG1),FM_MINIT) ;
100 outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
101 hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
103 * now reset everything
105 outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
106 i = (int) inp(ADDR(B0_CTRL)) ; /* do dummy read */
107 SK_UNUSED(i) ; /* Make LINT happy. */
108 outp(ADDR(B0_CTRL), CTRL_RST_CLR) ;
111 * Reset all bits in the PCI STATUS register
113 outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_ON) ; /* enable for writes */
114 word = inpw(PCI_C(PCI_STATUS)) ;
115 outpw(PCI_C(PCI_STATUS), word | PCI_ERRBITS) ;
116 outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_OFF) ; /* disable writes */
119 * Release the reset of all the State machines
120 * Release Master_Reset
121 * Release HPI_SM_Reset
123 outp(ADDR(B0_CTRL), CTRL_MRST_CLR|CTRL_HPI_CLR) ;
126 * determine the adapter type
127 * Note: Do it here, because some drivers may call card_start() once
128 * at very first before any other initialization functions is
131 rev_id = inp(PCI_C(PCI_REVISION_ID)) ;
132 if ((rev_id & 0xf0) == SK_ML_ID_1 || (rev_id & 0xf0) == SK_ML_ID_2) {
133 smc->hw.hw_is_64bit = TRUE ;
135 smc->hw.hw_is_64bit = FALSE ;
139 * Watermark initialization
141 if (!smc->hw.hw_is_64bit) {
142 outpd(ADDR(B4_R1_F), RX_WATERMARK) ;
143 outpd(ADDR(B5_XA_F), TX_WATERMARK) ;
144 outpd(ADDR(B5_XS_F), TX_WATERMARK) ;
147 outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* clear the reset chips */
148 outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_ON|LED_GB_OFF) ; /* ye LED on */
150 /* init the timer value for the watch dog 2,5 minutes */
151 outpd(ADDR(B2_WDOG_INI),0x6FC23AC0) ;
153 /* initialize the ISR mask */
154 smc->hw.is_imask = ISR_MASK ;
155 smc->hw.hw_state = STOPPED ;
157 GET_PAGE(0) ; /* necessary for BOOT */
160 void card_stop(struct s_smc *smc)
162 smt_stop_watchdog(smc) ;
163 smc->hw.mac_ring_is_up = 0 ; /* ring down */
167 * make sure no transfer activity is pending
169 outpw(FM_A(FM_MDREG1),FM_MINIT) ;
170 outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
171 hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
173 * now reset everything
175 outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
176 outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* reset for all chips */
177 outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_OFF|LED_GB_OFF) ; /* all LEDs off */
178 smc->hw.hw_state = STOPPED ;
181 /*--------------------------- ISR handling ----------------------------------*/
183 void mac1_irq(struct s_smc *smc, u_short stu, u_short stl)
189 * parity error: note encoding error is not possible in tag mode
191 if (stl & (FM_SPCEPDS | /* parity err. syn.q.*/
192 FM_SPCEPDA0 | /* parity err. a.q.0 */
193 FM_SPCEPDA1)) { /* parity err. a.q.1 */
194 SMT_PANIC(smc,SMT_E0134, SMT_E0134_MSG) ;
197 * buffer underrun: can only occur if a tx threshold is specified
199 if (stl & (FM_STBURS | /* tx buffer underrun syn.q.*/
200 FM_STBURA0 | /* tx buffer underrun a.q.0 */
201 FM_STBURA1)) { /* tx buffer underrun a.q.2 */
202 SMT_PANIC(smc,SMT_E0133, SMT_E0133_MSG) ;
205 if ( (stu & (FM_SXMTABT | /* transmit abort */
206 FM_STXABRS | /* syn. tx abort */
207 FM_STXABRA0)) || /* asyn. tx abort */
208 (stl & (FM_SQLCKS | /* lock for syn. q. */
209 FM_SQLCKA0)) ) { /* lock for asyn. q. */
210 formac_tx_restart(smc) ; /* init tx */
212 stu = inpw(FM_A(FM_ST1U)) ;
213 stl = inpw(FM_A(FM_ST1L)) ;
214 stu &= ~ (FM_STECFRMA0 | FM_STEFRMA0 | FM_STEFRMS) ;
219 if (stu & (FM_STEFRMA0 | /* end of asyn tx */
220 FM_STEFRMS)) { /* end of sync tx */
225 llc_restart_tx(smc) ;
229 * interrupt source= plc1
230 * this function is called in nwfbisr.asm
232 void plc1_irq(struct s_smc *smc)
234 u_short st = inpw(PLC(PB,PL_INTR_EVENT)) ;
240 * interrupt source= plc2
241 * this function is called in nwfbisr.asm
243 void plc2_irq(struct s_smc *smc)
245 u_short st = inpw(PLC(PA,PL_INTR_EVENT)) ;
252 * interrupt source= timer
254 void timer_irq(struct s_smc *smc)
257 smc->hw.t_stop = smc->hw.t_start;
258 smt_timer_done(smc) ;
262 * return S-port (PA or PB)
264 int pcm_get_s_port(struct s_smc *smc)
271 * Station Label = "FDDI-XYZ" where
277 #define STATION_LABEL_CONNECTOR_OFFSET 5
278 #define STATION_LABEL_PMD_OFFSET 6
279 #define STATION_LABEL_PORT_OFFSET 7
281 void read_address(struct s_smc *smc, u_char *mac_addr)
288 for (i = 0; i < 6; i++) { /* read mac address from board */
289 smc->hw.fddi_phys_addr.a[i] =
290 bitrev8(inp(ADDR(B2_MAC_0+i)));
294 ConnectorType = inp(ADDR(B2_CONN_TYP)) ;
295 PmdType = inp(ADDR(B2_PMD_TYP)) ;
297 smc->y[PA].pmd_type[PMD_SK_CONN] =
298 smc->y[PB].pmd_type[PMD_SK_CONN] = ConnectorType ;
299 smc->y[PA].pmd_type[PMD_SK_PMD ] =
300 smc->y[PB].pmd_type[PMD_SK_PMD ] = PmdType ;
303 for (i = 0; i < 6 ;i++) {
304 smc->hw.fddi_canon_addr.a[i] = mac_addr[i] ;
305 smc->hw.fddi_home_addr.a[i] = bitrev8(mac_addr[i]);
309 smc->hw.fddi_home_addr = smc->hw.fddi_phys_addr ;
311 for (i = 0; i < 6 ;i++) {
312 smc->hw.fddi_canon_addr.a[i] =
313 bitrev8(smc->hw.fddi_phys_addr.a[i]);
318 * FDDI card soft reset
320 void init_board(struct s_smc *smc, u_char *mac_addr)
323 read_address(smc,mac_addr) ;
325 if (!(inp(ADDR(B0_DAS)) & DAS_AVAIL))
326 smc->s.sas = SMT_SAS ; /* Single att. station */
328 smc->s.sas = SMT_DAS ; /* Dual att. station */
330 if (!(inp(ADDR(B0_DAS)) & DAS_BYP_ST))
331 smc->mib.fddiSMTBypassPresent = 0 ;
332 /* without opt. bypass */
334 smc->mib.fddiSMTBypassPresent = 1 ;
335 /* with opt. bypass */
339 * insert or deinsert optical bypass (called by ECM)
341 void sm_pm_bypass_req(struct s_smc *smc, int mode)
343 DB_ECMN(1, "ECM : sm_pm_bypass_req(%s)",
344 mode == BP_INSERT ? "BP_INSERT" : "BP_DEINSERT");
346 if (smc->s.sas != SMT_DAS)
352 outp(ADDR(B0_DAS),DAS_BYP_INS) ; /* insert station */
355 outp(ADDR(B0_DAS),DAS_BYP_RMV) ; /* bypass station */
362 * check if bypass connected
364 int sm_pm_bypass_present(struct s_smc *smc)
366 return (inp(ADDR(B0_DAS)) & DAS_BYP_ST) ? TRUE : FALSE;
369 void plc_clear_irq(struct s_smc *smc, int p)
378 * led_indication called by rmt_indication() and
384 * 0 Only switch green LEDs according to their respective PCM state
385 * LED_Y_OFF just switch yellow LED off
386 * LED_Y_ON just switch yello LED on
388 static void led_indication(struct s_smc *smc, int led_event)
390 /* use smc->hw.mac_ring_is_up == TRUE
391 * as indication for Ring Operational
395 struct fddi_mib_p *mib_a ;
396 struct fddi_mib_p *mib_b ;
406 /* Ring up = yellow led OFF*/
407 if (led_event == LED_Y_ON) {
408 led_state |= LED_MY_ON ;
410 else if (led_event == LED_Y_OFF) {
411 led_state |= LED_MY_OFF ;
413 else { /* PCM state changed */
414 /* Link at Port A/S = green led A ON */
415 if (mib_a->fddiPORTPCMState == PC8_ACTIVE) {
416 led_state |= LED_GA_ON ;
419 led_state |= LED_GA_OFF ;
422 /* Link at Port B = green led B ON */
423 if (mib_b->fddiPORTPCMState == PC8_ACTIVE) {
424 led_state |= LED_GB_ON ;
427 led_state |= LED_GB_OFF ;
431 outp(ADDR(B0_LED), led_state) ;
437 void pcm_state_change(struct s_smc *smc, int plc, int p_state)
440 * the current implementation of pcm_state_change() in the driver
441 * parts must be renamed to drv_pcm_state_change() which will be called
442 * now after led_indication.
444 DRV_PCM_STATE_CHANGE(smc,plc,p_state) ;
446 led_indication(smc,0) ;
450 void rmt_indication(struct s_smc *smc, int i)
452 /* Call a driver special function if defined */
453 DRV_RMT_INDICATION(smc,i) ;
455 led_indication(smc, i ? LED_Y_OFF : LED_Y_ON) ;
460 * llc_recover_tx called by init_tx (fplus.c)
462 void llc_recover_tx(struct s_smc *smc)
465 extern int load_gen_flag ;
470 smc->hw.n_a_send= 0 ;
477 static int is_equal_num(char comp1[], char comp2[], int num)
481 for (i = 0 ; i < num ; i++) {
482 if (comp1[i] != comp2[i])
490 * set the OEM ID defaults, and test the contents of the OEM data base
491 * The default OEM is the first ACTIVE entry in the OEM data base
494 * 1 error in data base
498 int set_oi_id_def(struct s_smc *smc)
506 act_entries = FALSE ;
508 smc->hw.oem_min_status = OI_STAT_ACTIVE ;
510 /* check OEM data base */
511 while (oem_ids[i].oi_status) {
512 switch (oem_ids[i].oi_status) {
514 act_entries = TRUE ; /* we have active IDs */
516 sel_id = i ; /* save the first active ID */
518 case OI_STAT_PRESENT:
520 break ; /* entry ok */
522 return 1; /* invalid oi_status */
531 /* ok, we have a valid OEM data base with an active entry */
532 smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[sel_id] ;
535 #endif /* MULT_OEM */
537 void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr)
541 for (i = 0 ; i < 6 ; i++)
542 bia_addr->a[i] = bitrev8(smc->hw.fddi_phys_addr.a[i]);
545 void smt_start_watchdog(struct s_smc *smc)
547 SK_UNUSED(smc) ; /* Make LINT happy. */
552 if (smc->hw.wdog_used) {
553 outpw(ADDR(B2_WDOG_CRTL),TIM_START) ; /* Start timer. */
560 static void smt_stop_watchdog(struct s_smc *smc)
562 SK_UNUSED(smc) ; /* Make LINT happy. */
566 if (smc->hw.wdog_used) {
567 outpw(ADDR(B2_WDOG_CRTL),TIM_STOP) ; /* Stop timer. */
576 void mac_do_pci_fix(struct s_smc *smc)