66#include <fcntl.h>
77#include <string.h>
88#include <errno.h>
9+ #include <asm/types.h>
10+ #include <strings.h>
11+ #include <stdint.h>
912
10- char blob_name [] = "isci_firmware.bin" ;
11- char id [] = "#SCU MAGIC#" ;
12- unsigned char version = 1 ;
13- unsigned char sub_version = 0 ;
14-
15-
16- /*
17- * For all defined arrays:
18- * elements 0-3 are for SCU0, ports 0-3
19- * elements 4-7 are for SCU1, ports 0-3
20- *
21- * valid configurations for one SCU are:
22- * P0 P1 P2 P3
23- * ----------------
24- * 0xF,0x0,0x0,0x0 # 1 x4 port
25- * 0x3,0x0,0x4,0x8 # Phys 0 and 1 are a x2 port, phy 2 and phy 3 are each x1
26- * # ports
27- * 0x1,0x2,0xC,0x0 # Phys 0 and 1 are each x1 ports, phy 2 and phy 3 are a x2
28- * # port
29- * 0x3,0x0,0xC,0x0 # Phys 0 and 1 are a x2 port, phy 2 and phy 3 are a x2 port
30- * 0x1,0x2,0x4,0x8 # Each phy is a x1 port (this is the default configuration)
31- *
32- * if there is a port/phy on which you do not wish to override the default
33- * values, use the value assigned to UNINIT_PARAM (255).
34- */
35- unsigned int phy_mask [] = { 1 , 2 , 4 , 8 , 1 , 2 , 4 , 8 };
36-
37-
38- /* denotes SAS generation. i.e. 3: SAS Gen 3 6G */
39- unsigned int phy_gen [] = { 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 };
40-
41- /*
42- * if there is a port/phy on which you do not wish to override the default
43- * values, use the value "0000000000000000". SAS address of zero's is
44- * considered invalid and will not be used.
45- */
46- unsigned long long sas_addr [] = { 0x5FCFFFFFF0000000ULL ,
47- 0x5FCFFFFFF1000000ULL ,
48- 0x5FCFFFFFF2000000ULL ,
49- 0x5FCFFFFFF3000000ULL ,
50- 0x5FCFFFFFF4000000ULL ,
51- 0x5FCFFFFFF5000000ULL ,
52- 0x5FCFFFFFF6000000ULL ,
53- 0x5FCFFFFFF7000000ULL };
54-
55- int write_blob (void )
13+ #include "create_fw.h"
14+ #include "../probe_roms.h"
15+
16+ int write_blob (struct isci_orom * isci_orom )
5617{
5718 FILE * fd ;
5819 int err ;
20+ size_t count ;
5921
6022 fd = fopen (blob_name , "w+" );
6123 if (!fd ) {
6224 perror ("Open file for write failed" );
25+ fclose (fd );
6326 return - EIO ;
6427 }
6528
66- /* write id */
67- err = fwrite ((void * )id , sizeof (char ), strlen (id )+ 1 , fd );
68- if (err == 0 ) {
69- perror ("write id failed" );
70- return err ;
71- }
72-
73- /* write version */
74- err = fwrite ((void * )& version , sizeof (version ), 1 , fd );
75- if (err == 0 ) {
76- perror ("write version failed" );
77- return err ;
78- }
79-
80- /* write sub version */
81- err = fwrite ((void * )& sub_version , sizeof (sub_version ), 1 , fd );
82- if (err == 0 ) {
83- perror ("write subversion failed" );
84- return err ;
85- }
86-
87- /* write phy mask header */
88- err = fputc (0x1 , fd );
89- if (err == EOF ) {
90- perror ("write phy mask header failed" );
91- return - EIO ;
92- }
93-
94- /* write size */
95- err = fputc (8 , fd );
96- if (err == EOF ) {
97- perror ("write phy mask size failed" );
98- return - EIO ;
99- }
100-
101- /* write phy masks */
102- err = fwrite ((void * )phy_mask , 1 , sizeof (phy_mask ), fd );
103- if (err == 0 ) {
104- perror ("write phy_mask failed" );
105- return err ;
106- }
107-
108- /* write phy gen header */
109- err = fputc (0x2 , fd );
110- if (err == EOF ) {
111- perror ("write phy gen header failed" );
112- return - EIO ;
113- }
114-
115- /* write size */
116- err = fputc (8 , fd );
117- if (err == EOF ) {
118- perror ("write phy gen size failed" );
119- return - EIO ;
120- }
121-
122- /* write phy_gen */
123- err = fwrite ((void * )phy_gen ,
124- 1 ,
125- sizeof (phy_gen ),
126- fd );
127- if (err == 0 ) {
128- perror ("write phy_gen failed" );
129- return err ;
130- }
131-
132- /* write phy gen header */
133- err = fputc (0x3 , fd );
134- if (err == EOF ) {
135- perror ("write sas addr header failed" );
136- return - EIO ;
137- }
138-
139- /* write size */
140- err = fputc (8 , fd );
141- if (err == EOF ) {
142- perror ("write sas addr size failed" );
143- return - EIO ;
144- }
145-
146- /* write sas_addr */
147- err = fwrite ((void * )sas_addr ,
148- 1 ,
149- sizeof (sas_addr ),
150- fd );
151- if (err == 0 ) {
152- perror ("write sas_addr failed" );
153- return err ;
154- }
155-
156- /* write end header */
157- err = fputc (0xff , fd );
158- if (err == EOF ) {
159- perror ("write end header failed" );
29+ count = fwrite (isci_orom , sizeof (struct isci_orom ), 1 , fd );
30+ if (count != 1 ) {
31+ perror ("Write data failed" );
32+ fclose (fd );
16033 return - EIO ;
16134 }
16235
@@ -165,13 +38,53 @@ int write_blob(void)
16538 return 0 ;
16639}
16740
41+ void set_binary_values (struct isci_orom * isci_orom )
42+ {
43+ int ctrl_idx , phy_idx , port_idx ;
44+
45+ /* setting OROM signature */
46+ strncpy (isci_orom -> hdr .signature , sig , strlen (sig ));
47+ isci_orom -> hdr .version = 0x10 ;
48+ isci_orom -> hdr .total_block_length = sizeof (struct isci_orom );
49+ isci_orom -> hdr .hdr_length = sizeof (struct sci_bios_oem_param_block_hdr );
50+ isci_orom -> hdr .num_elements = num_elements ;
51+
52+ for (ctrl_idx = 0 ; ctrl_idx < 2 ; ctrl_idx ++ ) {
53+ isci_orom -> ctrl [ctrl_idx ].controller .mode_type = mode_type ;
54+ isci_orom -> ctrl [ctrl_idx ].controller .max_concurrent_dev_spin_up =
55+ max_num_concurrent_dev_spin_up ;
56+ isci_orom -> ctrl [ctrl_idx ].controller .do_enable_ssc =
57+ enable_ssc ;
58+
59+ for (port_idx = 0 ; port_idx < 4 ; port_idx ++ )
60+ isci_orom -> ctrl [ctrl_idx ].ports [port_idx ].phy_mask =
61+ phy_mask [ctrl_idx ][port_idx ];
62+
63+ for (phy_idx = 0 ; phy_idx < 4 ; phy_idx ++ ) {
64+ isci_orom -> ctrl [ctrl_idx ].phys [phy_idx ].sas_address .high =
65+ (__u32 )(sas_addr [ctrl_idx ][phy_idx ] >> 32 );
66+ isci_orom -> ctrl [ctrl_idx ].phys [phy_idx ].sas_address .low =
67+ (__u32 )(sas_addr [ctrl_idx ][phy_idx ]);
68+ }
69+ }
70+ }
71+
16872int main (void )
16973{
17074 int err ;
75+ struct isci_orom * isci_orom ;
76+
77+ isci_orom = malloc (sizeof (struct isci_orom ));
78+ memset (isci_orom , 0 , sizeof (struct isci_orom ));
17179
172- err = write_blob ();
173- if (err < 0 )
80+ set_binary_values (isci_orom );
81+
82+ err = write_blob (isci_orom );
83+ if (err < 0 ) {
84+ free (isci_orom );
17485 return err ;
86+ }
17587
88+ free (isci_orom );
17689 return 0 ;
17790}
0 commit comments