@@ -116,6 +116,8 @@ static void fc_lport_enter_ns(struct fc_lport *, enum fc_lport_state);
116116static void fc_lport_enter_scr (struct fc_lport * );
117117static void fc_lport_enter_ready (struct fc_lport * );
118118static void fc_lport_enter_logo (struct fc_lport * );
119+ static void fc_lport_enter_fdmi (struct fc_lport * lport );
120+ static void fc_lport_enter_ms (struct fc_lport * , enum fc_lport_state );
119121
120122static const char * fc_lport_state_names [] = {
121123 [LPORT_ST_DISABLED ] = "disabled" ,
@@ -126,6 +128,11 @@ static const char *fc_lport_state_names[] = {
126128 [LPORT_ST_RSPN_ID ] = "RSPN_ID" ,
127129 [LPORT_ST_RFT_ID ] = "RFT_ID" ,
128130 [LPORT_ST_RFF_ID ] = "RFF_ID" ,
131+ [LPORT_ST_FDMI ] = "FDMI" ,
132+ [LPORT_ST_RHBA ] = "RHBA" ,
133+ [LPORT_ST_RPA ] = "RPA" ,
134+ [LPORT_ST_DHBA ] = "DHBA" ,
135+ [LPORT_ST_DPRT ] = "DPRT" ,
129136 [LPORT_ST_SCR ] = "SCR" ,
130137 [LPORT_ST_READY ] = "Ready" ,
131138 [LPORT_ST_LOGO ] = "LOGO" ,
@@ -183,11 +190,14 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
183190 if (lport -> state == LPORT_ST_DNS ) {
184191 lport -> dns_rdata = rdata ;
185192 fc_lport_enter_ns (lport , LPORT_ST_RNN_ID );
193+ } else if (lport -> state == LPORT_ST_FDMI ) {
194+ lport -> ms_rdata = rdata ;
195+ fc_lport_enter_ms (lport , LPORT_ST_DHBA );
186196 } else {
187197 FC_LPORT_DBG (lport , "Received an READY event "
188198 "on port (%6.6x) for the directory "
189199 "server, but the lport is not "
190- "in the DNS state, it's in the "
200+ "in the DNS or FDMI state, it's in the "
191201 "%d state" , rdata -> ids .port_id ,
192202 lport -> state );
193203 lport -> tt .rport_logoff (rdata );
@@ -196,7 +206,10 @@ static void fc_lport_rport_callback(struct fc_lport *lport,
196206 case RPORT_EV_LOGO :
197207 case RPORT_EV_FAILED :
198208 case RPORT_EV_STOP :
199- lport -> dns_rdata = NULL ;
209+ if (rdata -> ids .port_id == FC_FID_DIR_SERV )
210+ lport -> dns_rdata = NULL ;
211+ else if (rdata -> ids .port_id == FC_FID_MGMT_SERV )
212+ lport -> ms_rdata = NULL ;
200213 break ;
201214 case RPORT_EV_NONE :
202215 break ;
@@ -1148,7 +1161,10 @@ static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp,
11481161 fc_lport_enter_ns (lport , LPORT_ST_RFF_ID );
11491162 break ;
11501163 case LPORT_ST_RFF_ID :
1151- fc_lport_enter_scr (lport );
1164+ if (lport -> fdmi_enabled )
1165+ fc_lport_enter_fdmi (lport );
1166+ else
1167+ fc_lport_enter_scr (lport );
11521168 break ;
11531169 default :
11541170 /* should have already been caught by state checks */
@@ -1162,6 +1178,85 @@ static void fc_lport_ns_resp(struct fc_seq *sp, struct fc_frame *fp,
11621178 mutex_unlock (& lport -> lp_mutex );
11631179}
11641180
1181+ /**
1182+ * fc_lport_ms_resp() - Handle response to a management server
1183+ * exchange
1184+ * @sp: current sequence in exchange
1185+ * @fp: response frame
1186+ * @lp_arg: Fibre Channel host port instance
1187+ *
1188+ * Locking Note: This function will be called without the lport lock
1189+ * held, but it will lock, call an _enter_* function or fc_lport_error()
1190+ * and then unlock the lport.
1191+ */
1192+ static void fc_lport_ms_resp (struct fc_seq * sp , struct fc_frame * fp ,
1193+ void * lp_arg )
1194+ {
1195+ struct fc_lport * lport = lp_arg ;
1196+ struct fc_frame_header * fh ;
1197+ struct fc_ct_hdr * ct ;
1198+
1199+ FC_LPORT_DBG (lport , "Received a ms %s\n" , fc_els_resp_type (fp ));
1200+
1201+ if (fp == ERR_PTR (- FC_EX_CLOSED ))
1202+ return ;
1203+
1204+ mutex_lock (& lport -> lp_mutex );
1205+
1206+ if (lport -> state < LPORT_ST_RHBA || lport -> state > LPORT_ST_DPRT ) {
1207+ FC_LPORT_DBG (lport , "Received a management server response, "
1208+ "but in state %s\n" , fc_lport_state (lport ));
1209+ if (IS_ERR (fp ))
1210+ goto err ;
1211+ goto out ;
1212+ }
1213+
1214+ if (IS_ERR (fp )) {
1215+ fc_lport_error (lport , fp );
1216+ goto err ;
1217+ }
1218+
1219+ fh = fc_frame_header_get (fp );
1220+ ct = fc_frame_payload_get (fp , sizeof (* ct ));
1221+
1222+ if (fh && ct && fh -> fh_type == FC_TYPE_CT &&
1223+ ct -> ct_fs_type == FC_FST_MGMT &&
1224+ ct -> ct_fs_subtype == FC_FDMI_SUBTYPE ) {
1225+ FC_LPORT_DBG (lport , "Received a management server response, "
1226+ "reason=%d explain=%d\n" ,
1227+ ct -> ct_reason ,
1228+ ct -> ct_explan );
1229+
1230+ switch (lport -> state ) {
1231+ case LPORT_ST_RHBA :
1232+ if (ntohs (ct -> ct_cmd ) == FC_FS_ACC )
1233+ fc_lport_enter_ms (lport , LPORT_ST_RPA );
1234+ else /* Error Skip RPA */
1235+ fc_lport_enter_scr (lport );
1236+ break ;
1237+ case LPORT_ST_RPA :
1238+ fc_lport_enter_scr (lport );
1239+ break ;
1240+ case LPORT_ST_DPRT :
1241+ fc_lport_enter_ms (lport , LPORT_ST_RHBA );
1242+ break ;
1243+ case LPORT_ST_DHBA :
1244+ fc_lport_enter_ms (lport , LPORT_ST_DPRT );
1245+ break ;
1246+ default :
1247+ /* should have already been caught by state checks */
1248+ break ;
1249+ }
1250+ } else {
1251+ /* Invalid Frame? */
1252+ fc_lport_error (lport , fp );
1253+ }
1254+ out :
1255+ fc_frame_free (fp );
1256+ err :
1257+ mutex_unlock (& lport -> lp_mutex );
1258+ }
1259+
11651260/**
11661261 * fc_lport_scr_resp() - Handle response to State Change Register (SCR) request
11671262 * @sp: current sequence in SCR exchange
@@ -1338,6 +1433,123 @@ static void fc_lport_enter_dns(struct fc_lport *lport)
13381433 fc_lport_error (lport , NULL );
13391434}
13401435
1436+ /**
1437+ * fc_lport_enter_ms() - management server commands
1438+ * @lport: Fibre Channel local port to register
1439+ *
1440+ * Locking Note: The lport lock is expected to be held before calling
1441+ * this routine.
1442+ */
1443+ static void fc_lport_enter_ms (struct fc_lport * lport , enum fc_lport_state state )
1444+ {
1445+ struct fc_frame * fp ;
1446+ enum fc_fdmi_req cmd ;
1447+ int size = sizeof (struct fc_ct_hdr );
1448+ size_t len ;
1449+ int numattrs ;
1450+
1451+ FC_LPORT_DBG (lport , "Entered %s state from %s state\n" ,
1452+ fc_lport_state_names [state ],
1453+ fc_lport_state (lport ));
1454+
1455+ fc_lport_state_enter (lport , state );
1456+
1457+ switch (state ) {
1458+ case LPORT_ST_RHBA :
1459+ cmd = FC_FDMI_RHBA ;
1460+ /* Number of HBA Attributes */
1461+ numattrs = 10 ;
1462+ len = sizeof (struct fc_fdmi_rhba );
1463+ len -= sizeof (struct fc_fdmi_attr_entry );
1464+ len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN );
1465+ len += FC_FDMI_HBA_ATTR_NODENAME_LEN ;
1466+ len += FC_FDMI_HBA_ATTR_MANUFACTURER_LEN ;
1467+ len += FC_FDMI_HBA_ATTR_SERIALNUMBER_LEN ;
1468+ len += FC_FDMI_HBA_ATTR_MODEL_LEN ;
1469+ len += FC_FDMI_HBA_ATTR_MODELDESCR_LEN ;
1470+ len += FC_FDMI_HBA_ATTR_HARDWAREVERSION_LEN ;
1471+ len += FC_FDMI_HBA_ATTR_DRIVERVERSION_LEN ;
1472+ len += FC_FDMI_HBA_ATTR_OPTIONROMVERSION_LEN ;
1473+ len += FC_FDMI_HBA_ATTR_FIRMWAREVERSION_LEN ;
1474+ len += FC_FDMI_HBA_ATTR_OSNAMEVERSION_LEN ;
1475+
1476+ size += len ;
1477+ break ;
1478+ case LPORT_ST_RPA :
1479+ cmd = FC_FDMI_RPA ;
1480+ /* Number of Port Attributes */
1481+ numattrs = 6 ;
1482+ len = sizeof (struct fc_fdmi_rpa );
1483+ len -= sizeof (struct fc_fdmi_attr_entry );
1484+ len += (numattrs * FC_FDMI_ATTR_ENTRY_HEADER_LEN );
1485+ len += FC_FDMI_PORT_ATTR_FC4TYPES_LEN ;
1486+ len += FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN ;
1487+ len += FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN ;
1488+ len += FC_FDMI_PORT_ATTR_MAXFRAMESIZE_LEN ;
1489+ len += FC_FDMI_PORT_ATTR_OSDEVICENAME_LEN ;
1490+ len += FC_FDMI_PORT_ATTR_HOSTNAME_LEN ;
1491+
1492+ size += len ;
1493+ break ;
1494+ case LPORT_ST_DPRT :
1495+ cmd = FC_FDMI_DPRT ;
1496+ len = sizeof (struct fc_fdmi_dprt );
1497+ size += len ;
1498+ break ;
1499+ case LPORT_ST_DHBA :
1500+ cmd = FC_FDMI_DHBA ;
1501+ len = sizeof (struct fc_fdmi_dhba );
1502+ size += len ;
1503+ break ;
1504+ default :
1505+ fc_lport_error (lport , NULL );
1506+ return ;
1507+ }
1508+
1509+ FC_LPORT_DBG (lport , "Cmd=0x%x Len %d size %d\n" ,
1510+ cmd , (int )len , size );
1511+ fp = fc_frame_alloc (lport , size );
1512+ if (!fp ) {
1513+ fc_lport_error (lport , fp );
1514+ return ;
1515+ }
1516+
1517+ if (!lport -> tt .elsct_send (lport , FC_FID_MGMT_SERV , fp , cmd ,
1518+ fc_lport_ms_resp ,
1519+ lport , 3 * lport -> r_a_tov ))
1520+ fc_lport_error (lport , fp );
1521+ }
1522+
1523+ /**
1524+ * fc_rport_enter_fdmi() - Create a fc_rport for the management server
1525+ * @lport: The local port requesting a remote port for the management server
1526+ *
1527+ * Locking Note: The lport lock is expected to be held before calling
1528+ * this routine.
1529+ */
1530+ static void fc_lport_enter_fdmi (struct fc_lport * lport )
1531+ {
1532+ struct fc_rport_priv * rdata ;
1533+
1534+ FC_LPORT_DBG (lport , "Entered FDMI state from %s state\n" ,
1535+ fc_lport_state (lport ));
1536+
1537+ fc_lport_state_enter (lport , LPORT_ST_FDMI );
1538+
1539+ mutex_lock (& lport -> disc .disc_mutex );
1540+ rdata = lport -> tt .rport_create (lport , FC_FID_MGMT_SERV );
1541+ mutex_unlock (& lport -> disc .disc_mutex );
1542+ if (!rdata )
1543+ goto err ;
1544+
1545+ rdata -> ops = & fc_lport_rport_ops ;
1546+ lport -> tt .rport_login (rdata );
1547+ return ;
1548+
1549+ err :
1550+ fc_lport_error (lport , NULL );
1551+ }
1552+
13411553/**
13421554 * fc_lport_timeout() - Handler for the retry_work timer
13431555 * @work: The work struct of the local port
@@ -1371,6 +1583,15 @@ static void fc_lport_timeout(struct work_struct *work)
13711583 case LPORT_ST_RFF_ID :
13721584 fc_lport_enter_ns (lport , lport -> state );
13731585 break ;
1586+ case LPORT_ST_FDMI :
1587+ fc_lport_enter_fdmi (lport );
1588+ break ;
1589+ case LPORT_ST_RHBA :
1590+ case LPORT_ST_RPA :
1591+ case LPORT_ST_DHBA :
1592+ case LPORT_ST_DPRT :
1593+ fc_lport_enter_ms (lport , lport -> state );
1594+ break ;
13741595 case LPORT_ST_SCR :
13751596 fc_lport_enter_scr (lport );
13761597 break ;
0 commit comments