- more 2.6.17 port work (still does not build)
[linux-flexiantxendom0-3.2.10.git] / drivers / scsi / sas / sas_common.c
1 /*
2  * Serial Attached SCSI (SAS) class common functions
3  *
4  * Copyright (C) 2005 Adaptec, Inc.  All rights reserved.
5  * Copyright (C) 2005 Luben Tuikov <luben_tuikov@adaptec.com>
6  *
7  * This file is licensed under GPLv2.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  *
24  * $Id: //depot/sas-class/sas_common.c#9 $
25  */
26
27 #include <scsi/sas/sas_class.h>
28 #include "sas_internal.h"
29
30 int sas_show_class(enum sas_class class, char *buf)
31 {
32         static const char *class_str[] = {
33                 [SAS] = "SAS",
34                 [EXPANDER] = "EXPANDER",
35         };
36         return sprintf(buf, "%s\n", class_str[class]);
37 }
38
39 int sas_show_proto(enum sas_proto proto, char *page)
40 {
41         static const char *proto_str[] = {
42                 [SATA_PROTO] = "SATA",
43                 [SAS_PROTO_SMP] = "SMP",
44                 [SAS_PROTO_STP] = "STP",
45                 [SAS_PROTO_SSP] = "SSP",
46         };
47         int  v;
48         char *buf = page;
49
50         for (v = 1; proto != 0 && v <= SAS_PROTO_SSP; v <<= 1) {
51                 if (v & proto) {
52                         buf += sprintf(buf, "%s", proto_str[v]);
53
54                         if (proto & ~((v<<1)-1))
55                                 buf += sprintf(buf, "|");
56                         else
57                                 buf += sprintf(buf, "\n");
58                 }
59         }
60         return buf-page;
61 }
62
63 int sas_show_linkrate(enum sas_phy_linkrate linkrate, char *page)
64 {
65         static const char *phy_linkrate_str[] = {
66                 [PHY_LINKRATE_NONE] = "",
67                 [PHY_DISABLED] = "disabled",
68                 [PHY_RESET_PROBLEM] = "phy reset problem",
69                 [PHY_SPINUP_HOLD] = "phy spinup hold",
70                 [PHY_PORT_SELECTOR] = "phy port selector",
71                 [PHY_LINKRATE_1_5] = "1,5 GB/s",
72                 [PHY_LINKRATE_3]  = "3,0 GB/s",
73                 [PHY_LINKRATE_6] = "6,0 GB/s",
74         };
75         return sprintf(page, "%s\n", phy_linkrate_str[linkrate]);
76 }
77
78 int sas_show_oob_mode(enum sas_oob_mode oob_mode, char *buf)
79 {
80         switch (oob_mode) {
81         case OOB_NOT_CONNECTED:
82                 return sprintf(buf, "%s", "");
83                 break;
84         case SATA_OOB_MODE:
85                 return sprintf(buf, "%s\n", "SATA");
86                 break;
87         case SAS_OOB_MODE:
88                 return sprintf(buf, "%s\n", "SAS");
89                 break;
90         }
91         return 0;
92 }
93
94 void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
95 {
96         const u32 poly = 0x00DB2777;
97         u32     r = 0;
98         int     i;
99
100         for (i = 0; i < 8; i++) {
101                 int b;
102                 for (b = 7; b >= 0; b--) {
103                         r <<= 1;
104                         if ((1 << b) & sas_addr[i]) {
105                                 if (!(r & 0x01000000))
106                                         r ^= poly;
107                         } else if (r & 0x01000000)
108                                 r ^= poly;
109                 }
110         }
111
112         hashed[0] = (r >> 16) & 0xFF;
113         hashed[1] = (r >> 8) & 0xFF ;
114         hashed[2] = r & 0xFF;
115 }