port.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * BSD LICENSE
  25. *
  26. * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
  27. * All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions
  31. * are met:
  32. *
  33. * * Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * * Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in
  37. * the documentation and/or other materials provided with the
  38. * distribution.
  39. * * Neither the name of Intel Corporation nor the names of its
  40. * contributors may be used to endorse or promote products derived
  41. * from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  44. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  45. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  46. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  47. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  49. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include "isci.h"
  56. #include "port.h"
  57. #include "request.h"
  58. #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
  59. #define SCU_DUMMY_INDEX (0xFFFF)
  60. #undef C
  61. #define C(a) (#a)
  62. const char *port_state_name(enum sci_port_states state)
  63. {
  64. static const char * const strings[] = PORT_STATES;
  65. return strings[state];
  66. }
  67. #undef C
  68. static struct device *sciport_to_dev(struct isci_port *iport)
  69. {
  70. int i = iport->physical_port_index;
  71. struct isci_port *table;
  72. struct isci_host *ihost;
  73. if (i == SCIC_SDS_DUMMY_PORT)
  74. i = SCI_MAX_PORTS+1;
  75. table = iport - i;
  76. ihost = container_of(table, typeof(*ihost), ports[0]);
  77. return &ihost->pdev->dev;
  78. }
  79. static void sci_port_get_protocols(struct isci_port *iport, struct sci_phy_proto *proto)
  80. {
  81. u8 index;
  82. proto->all = 0;
  83. for (index = 0; index < SCI_MAX_PHYS; index++) {
  84. struct isci_phy *iphy = iport->phy_table[index];
  85. if (!iphy)
  86. continue;
  87. sci_phy_get_protocols(iphy, proto);
  88. }
  89. }
  90. static u32 sci_port_get_phys(struct isci_port *iport)
  91. {
  92. u32 index;
  93. u32 mask;
  94. mask = 0;
  95. for (index = 0; index < SCI_MAX_PHYS; index++)
  96. if (iport->phy_table[index])
  97. mask |= (1 << index);
  98. return mask;
  99. }
  100. /**
  101. * sci_port_get_properties() - This method simply returns the properties
  102. * regarding the port, such as: physical index, protocols, sas address, etc.
  103. * @port: this parameter specifies the port for which to retrieve the physical
  104. * index.
  105. * @properties: This parameter specifies the properties structure into which to
  106. * copy the requested information.
  107. *
  108. * Indicate if the user specified a valid port. SCI_SUCCESS This value is
  109. * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
  110. * value is returned if the specified port is not valid. When this value is
  111. * returned, no data is copied to the properties output parameter.
  112. */
  113. enum sci_status sci_port_get_properties(struct isci_port *iport,
  114. struct sci_port_properties *prop)
  115. {
  116. if (!iport || iport->logical_port_index == SCIC_SDS_DUMMY_PORT)
  117. return SCI_FAILURE_INVALID_PORT;
  118. prop->index = iport->logical_port_index;
  119. prop->phy_mask = sci_port_get_phys(iport);
  120. sci_port_get_sas_address(iport, &prop->local.sas_address);
  121. sci_port_get_protocols(iport, &prop->local.protocols);
  122. sci_port_get_attached_sas_address(iport, &prop->remote.sas_address);
  123. return SCI_SUCCESS;
  124. }
  125. static void sci_port_bcn_enable(struct isci_port *iport)
  126. {
  127. struct isci_phy *iphy;
  128. u32 val;
  129. int i;
  130. for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
  131. iphy = iport->phy_table[i];
  132. if (!iphy)
  133. continue;
  134. val = readl(&iphy->link_layer_registers->link_layer_control);
  135. /* clear the bit by writing 1. */
  136. writel(val, &iphy->link_layer_registers->link_layer_control);
  137. }
  138. }
  139. static void isci_port_bc_change_received(struct isci_host *ihost,
  140. struct isci_port *iport,
  141. struct isci_phy *iphy)
  142. {
  143. dev_dbg(&ihost->pdev->dev,
  144. "%s: isci_phy = %p, sas_phy = %p\n",
  145. __func__, iphy, &iphy->sas_phy);
  146. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  147. sci_port_bcn_enable(iport);
  148. }
  149. static void isci_port_link_up(struct isci_host *isci_host,
  150. struct isci_port *iport,
  151. struct isci_phy *iphy)
  152. {
  153. unsigned long flags;
  154. struct sci_port_properties properties;
  155. unsigned long success = true;
  156. dev_dbg(&isci_host->pdev->dev,
  157. "%s: isci_port = %p\n",
  158. __func__, iport);
  159. spin_lock_irqsave(&iphy->sas_phy.frame_rcvd_lock, flags);
  160. sci_port_get_properties(iport, &properties);
  161. if (iphy->protocol == SAS_PROTOCOL_SATA) {
  162. u64 attached_sas_address;
  163. iphy->sas_phy.oob_mode = SATA_OOB_MODE;
  164. iphy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  165. /*
  166. * For direct-attached SATA devices, the SCI core will
  167. * automagically assign a SAS address to the end device
  168. * for the purpose of creating a port. This SAS address
  169. * will not be the same as assigned to the PHY and needs
  170. * to be obtained from struct sci_port_properties properties.
  171. */
  172. attached_sas_address = properties.remote.sas_address.high;
  173. attached_sas_address <<= 32;
  174. attached_sas_address |= properties.remote.sas_address.low;
  175. swab64s(&attached_sas_address);
  176. memcpy(&iphy->sas_phy.attached_sas_addr,
  177. &attached_sas_address, sizeof(attached_sas_address));
  178. } else if (iphy->protocol == SAS_PROTOCOL_SSP) {
  179. iphy->sas_phy.oob_mode = SAS_OOB_MODE;
  180. iphy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  181. /* Copy the attached SAS address from the IAF */
  182. memcpy(iphy->sas_phy.attached_sas_addr,
  183. iphy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  184. } else {
  185. dev_err(&isci_host->pdev->dev, "%s: unknown target\n", __func__);
  186. success = false;
  187. }
  188. iphy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(iphy);
  189. spin_unlock_irqrestore(&iphy->sas_phy.frame_rcvd_lock, flags);
  190. /* Notify libsas that we have an address frame, if indeed
  191. * we've found an SSP, SMP, or STP target */
  192. if (success)
  193. isci_host->sas_ha.notify_port_event(&iphy->sas_phy,
  194. PORTE_BYTES_DMAED);
  195. }
  196. /**
  197. * isci_port_link_down() - This function is called by the sci core when a link
  198. * becomes inactive.
  199. * @isci_host: This parameter specifies the isci host object.
  200. * @phy: This parameter specifies the isci phy with the active link.
  201. * @port: This parameter specifies the isci port with the active link.
  202. *
  203. */
  204. static void isci_port_link_down(struct isci_host *isci_host,
  205. struct isci_phy *isci_phy,
  206. struct isci_port *isci_port)
  207. {
  208. struct isci_remote_device *isci_device;
  209. dev_dbg(&isci_host->pdev->dev,
  210. "%s: isci_port = %p\n", __func__, isci_port);
  211. if (isci_port) {
  212. /* check to see if this is the last phy on this port. */
  213. if (isci_phy->sas_phy.port &&
  214. isci_phy->sas_phy.port->num_phys == 1) {
  215. /* change the state for all devices on this port. The
  216. * next task sent to this device will be returned as
  217. * SAS_TASK_UNDELIVERED, and the scsi mid layer will
  218. * remove the target
  219. */
  220. list_for_each_entry(isci_device,
  221. &isci_port->remote_dev_list,
  222. node) {
  223. dev_dbg(&isci_host->pdev->dev,
  224. "%s: isci_device = %p\n",
  225. __func__, isci_device);
  226. set_bit(IDEV_GONE, &isci_device->flags);
  227. }
  228. }
  229. }
  230. /* Notify libsas of the borken link, this will trigger calls to our
  231. * isci_port_deformed and isci_dev_gone functions.
  232. */
  233. sas_phy_disconnected(&isci_phy->sas_phy);
  234. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  235. PHYE_LOSS_OF_SIGNAL);
  236. dev_dbg(&isci_host->pdev->dev,
  237. "%s: isci_port = %p - Done\n", __func__, isci_port);
  238. }
  239. static bool is_port_ready_state(enum sci_port_states state)
  240. {
  241. switch (state) {
  242. case SCI_PORT_READY:
  243. case SCI_PORT_SUB_WAITING:
  244. case SCI_PORT_SUB_OPERATIONAL:
  245. case SCI_PORT_SUB_CONFIGURING:
  246. return true;
  247. default:
  248. return false;
  249. }
  250. }
  251. /* flag dummy rnc hanling when exiting a ready state */
  252. static void port_state_machine_change(struct isci_port *iport,
  253. enum sci_port_states state)
  254. {
  255. struct sci_base_state_machine *sm = &iport->sm;
  256. enum sci_port_states old_state = sm->current_state_id;
  257. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  258. iport->ready_exit = true;
  259. sci_change_state(sm, state);
  260. iport->ready_exit = false;
  261. }
  262. /**
  263. * isci_port_hard_reset_complete() - This function is called by the sci core
  264. * when the hard reset complete notification has been received.
  265. * @port: This parameter specifies the sci port with the active link.
  266. * @completion_status: This parameter specifies the core status for the reset
  267. * process.
  268. *
  269. */
  270. static void isci_port_hard_reset_complete(struct isci_port *isci_port,
  271. enum sci_status completion_status)
  272. {
  273. struct isci_host *ihost = isci_port->owning_controller;
  274. dev_dbg(&ihost->pdev->dev,
  275. "%s: isci_port = %p, completion_status=%x\n",
  276. __func__, isci_port, completion_status);
  277. /* Save the status of the hard reset from the port. */
  278. isci_port->hard_reset_status = completion_status;
  279. if (completion_status != SCI_SUCCESS) {
  280. /* The reset failed. The port state is now SCI_PORT_FAILED. */
  281. if (isci_port->active_phy_mask == 0) {
  282. int phy_idx = isci_port->last_active_phy;
  283. struct isci_phy *iphy = &ihost->phys[phy_idx];
  284. /* Generate the link down now to the host, since it
  285. * was intercepted by the hard reset state machine when
  286. * it really happened.
  287. */
  288. isci_port_link_down(ihost, iphy, isci_port);
  289. }
  290. /* Advance the port state so that link state changes will be
  291. * noticed.
  292. */
  293. port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING);
  294. }
  295. clear_bit(IPORT_RESET_PENDING, &isci_port->state);
  296. wake_up(&ihost->eventq);
  297. }
  298. /* This method will return a true value if the specified phy can be assigned to
  299. * this port The following is a list of phys for each port that are allowed: -
  300. * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
  301. * doesn't preclude all configurations. It merely ensures that a phy is part
  302. * of the allowable set of phy identifiers for that port. For example, one
  303. * could assign phy 3 to port 0 and no other phys. Please refer to
  304. * sci_port_is_phy_mask_valid() for information regarding whether the
  305. * phy_mask for a port can be supported. bool true if this is a valid phy
  306. * assignment for the port false if this is not a valid phy assignment for the
  307. * port
  308. */
  309. bool sci_port_is_valid_phy_assignment(struct isci_port *iport, u32 phy_index)
  310. {
  311. struct isci_host *ihost = iport->owning_controller;
  312. struct sci_user_parameters *user = &ihost->user_parameters;
  313. /* Initialize to invalid value. */
  314. u32 existing_phy_index = SCI_MAX_PHYS;
  315. u32 index;
  316. if ((iport->physical_port_index == 1) && (phy_index != 1))
  317. return false;
  318. if (iport->physical_port_index == 3 && phy_index != 3)
  319. return false;
  320. if (iport->physical_port_index == 2 &&
  321. (phy_index == 0 || phy_index == 1))
  322. return false;
  323. for (index = 0; index < SCI_MAX_PHYS; index++)
  324. if (iport->phy_table[index] && index != phy_index)
  325. existing_phy_index = index;
  326. /* Ensure that all of the phys in the port are capable of
  327. * operating at the same maximum link rate.
  328. */
  329. if (existing_phy_index < SCI_MAX_PHYS &&
  330. user->phys[phy_index].max_speed_generation !=
  331. user->phys[existing_phy_index].max_speed_generation)
  332. return false;
  333. return true;
  334. }
  335. /**
  336. *
  337. * @sci_port: This is the port object for which to determine if the phy mask
  338. * can be supported.
  339. *
  340. * This method will return a true value if the port's phy mask can be supported
  341. * by the SCU. The following is a list of valid PHY mask configurations for
  342. * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
  343. * - Port 3 - [3] This method returns a boolean indication specifying if the
  344. * phy mask can be supported. true if this is a valid phy assignment for the
  345. * port false if this is not a valid phy assignment for the port
  346. */
  347. static bool sci_port_is_phy_mask_valid(
  348. struct isci_port *iport,
  349. u32 phy_mask)
  350. {
  351. if (iport->physical_port_index == 0) {
  352. if (((phy_mask & 0x0F) == 0x0F)
  353. || ((phy_mask & 0x03) == 0x03)
  354. || ((phy_mask & 0x01) == 0x01)
  355. || (phy_mask == 0))
  356. return true;
  357. } else if (iport->physical_port_index == 1) {
  358. if (((phy_mask & 0x02) == 0x02)
  359. || (phy_mask == 0))
  360. return true;
  361. } else if (iport->physical_port_index == 2) {
  362. if (((phy_mask & 0x0C) == 0x0C)
  363. || ((phy_mask & 0x04) == 0x04)
  364. || (phy_mask == 0))
  365. return true;
  366. } else if (iport->physical_port_index == 3) {
  367. if (((phy_mask & 0x08) == 0x08)
  368. || (phy_mask == 0))
  369. return true;
  370. }
  371. return false;
  372. }
  373. /*
  374. * This method retrieves a currently active (i.e. connected) phy contained in
  375. * the port. Currently, the lowest order phy that is connected is returned.
  376. * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
  377. * returned if there are no currently active (i.e. connected to a remote end
  378. * point) phys contained in the port. All other values specify a struct sci_phy
  379. * object that is active in the port.
  380. */
  381. static struct isci_phy *sci_port_get_a_connected_phy(struct isci_port *iport)
  382. {
  383. u32 index;
  384. struct isci_phy *iphy;
  385. for (index = 0; index < SCI_MAX_PHYS; index++) {
  386. /* Ensure that the phy is both part of the port and currently
  387. * connected to the remote end-point.
  388. */
  389. iphy = iport->phy_table[index];
  390. if (iphy && sci_port_active_phy(iport, iphy))
  391. return iphy;
  392. }
  393. return NULL;
  394. }
  395. static enum sci_status sci_port_set_phy(struct isci_port *iport, struct isci_phy *iphy)
  396. {
  397. /* Check to see if we can add this phy to a port
  398. * that means that the phy is not part of a port and that the port does
  399. * not already have a phy assinged to the phy index.
  400. */
  401. if (!iport->phy_table[iphy->phy_index] &&
  402. !phy_get_non_dummy_port(iphy) &&
  403. sci_port_is_valid_phy_assignment(iport, iphy->phy_index)) {
  404. /* Phy is being added in the stopped state so we are in MPC mode
  405. * make logical port index = physical port index
  406. */
  407. iport->logical_port_index = iport->physical_port_index;
  408. iport->phy_table[iphy->phy_index] = iphy;
  409. sci_phy_set_port(iphy, iport);
  410. return SCI_SUCCESS;
  411. }
  412. return SCI_FAILURE;
  413. }
  414. static enum sci_status sci_port_clear_phy(struct isci_port *iport, struct isci_phy *iphy)
  415. {
  416. /* Make sure that this phy is part of this port */
  417. if (iport->phy_table[iphy->phy_index] == iphy &&
  418. phy_get_non_dummy_port(iphy) == iport) {
  419. struct isci_host *ihost = iport->owning_controller;
  420. /* Yep it is assigned to this port so remove it */
  421. sci_phy_set_port(iphy, &ihost->ports[SCI_MAX_PORTS]);
  422. iport->phy_table[iphy->phy_index] = NULL;
  423. return SCI_SUCCESS;
  424. }
  425. return SCI_FAILURE;
  426. }
  427. void sci_port_get_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
  428. {
  429. u32 index;
  430. sas->high = 0;
  431. sas->low = 0;
  432. for (index = 0; index < SCI_MAX_PHYS; index++)
  433. if (iport->phy_table[index])
  434. sci_phy_get_sas_address(iport->phy_table[index], sas);
  435. }
  436. void sci_port_get_attached_sas_address(struct isci_port *iport, struct sci_sas_address *sas)
  437. {
  438. struct isci_phy *iphy;
  439. /*
  440. * Ensure that the phy is both part of the port and currently
  441. * connected to the remote end-point.
  442. */
  443. iphy = sci_port_get_a_connected_phy(iport);
  444. if (iphy) {
  445. if (iphy->protocol != SAS_PROTOCOL_SATA) {
  446. sci_phy_get_attached_sas_address(iphy, sas);
  447. } else {
  448. sci_phy_get_sas_address(iphy, sas);
  449. sas->low += iphy->phy_index;
  450. }
  451. } else {
  452. sas->high = 0;
  453. sas->low = 0;
  454. }
  455. }
  456. /**
  457. * sci_port_construct_dummy_rnc() - create dummy rnc for si workaround
  458. *
  459. * @sci_port: logical port on which we need to create the remote node context
  460. * @rni: remote node index for this remote node context.
  461. *
  462. * This routine will construct a dummy remote node context data structure
  463. * This structure will be posted to the hardware to work around a scheduler
  464. * error in the hardware.
  465. */
  466. static void sci_port_construct_dummy_rnc(struct isci_port *iport, u16 rni)
  467. {
  468. union scu_remote_node_context *rnc;
  469. rnc = &iport->owning_controller->remote_node_context_table[rni];
  470. memset(rnc, 0, sizeof(union scu_remote_node_context));
  471. rnc->ssp.remote_sas_address_hi = 0;
  472. rnc->ssp.remote_sas_address_lo = 0;
  473. rnc->ssp.remote_node_index = rni;
  474. rnc->ssp.remote_node_port_width = 1;
  475. rnc->ssp.logical_port_index = iport->physical_port_index;
  476. rnc->ssp.nexus_loss_timer_enable = false;
  477. rnc->ssp.check_bit = false;
  478. rnc->ssp.is_valid = true;
  479. rnc->ssp.is_remote_node_context = true;
  480. rnc->ssp.function_number = 0;
  481. rnc->ssp.arbitration_wait_time = 0;
  482. }
  483. /*
  484. * construct a dummy task context data structure. This
  485. * structure will be posted to the hardwre to work around a scheduler error
  486. * in the hardware.
  487. */
  488. static void sci_port_construct_dummy_task(struct isci_port *iport, u16 tag)
  489. {
  490. struct isci_host *ihost = iport->owning_controller;
  491. struct scu_task_context *task_context;
  492. task_context = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  493. memset(task_context, 0, sizeof(struct scu_task_context));
  494. task_context->initiator_request = 1;
  495. task_context->connection_rate = 1;
  496. task_context->logical_port_index = iport->physical_port_index;
  497. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  498. task_context->task_index = ISCI_TAG_TCI(tag);
  499. task_context->valid = SCU_TASK_CONTEXT_VALID;
  500. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  501. task_context->remote_node_index = iport->reserved_rni;
  502. task_context->do_not_dma_ssp_good_response = 1;
  503. task_context->task_phase = 0x01;
  504. }
  505. static void sci_port_destroy_dummy_resources(struct isci_port *iport)
  506. {
  507. struct isci_host *ihost = iport->owning_controller;
  508. if (iport->reserved_tag != SCI_CONTROLLER_INVALID_IO_TAG)
  509. isci_free_tag(ihost, iport->reserved_tag);
  510. if (iport->reserved_rni != SCU_DUMMY_INDEX)
  511. sci_remote_node_table_release_remote_node_index(&ihost->available_remote_nodes,
  512. 1, iport->reserved_rni);
  513. iport->reserved_rni = SCU_DUMMY_INDEX;
  514. iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
  515. }
  516. void sci_port_setup_transports(struct isci_port *iport, u32 device_id)
  517. {
  518. u8 index;
  519. for (index = 0; index < SCI_MAX_PHYS; index++) {
  520. if (iport->active_phy_mask & (1 << index))
  521. sci_phy_setup_transport(iport->phy_table[index], device_id);
  522. }
  523. }
  524. static void sci_port_resume_phy(struct isci_port *iport, struct isci_phy *iphy)
  525. {
  526. sci_phy_resume(iphy);
  527. iport->enabled_phy_mask |= 1 << iphy->phy_index;
  528. }
  529. static void sci_port_activate_phy(struct isci_port *iport,
  530. struct isci_phy *iphy,
  531. u8 flags)
  532. {
  533. struct isci_host *ihost = iport->owning_controller;
  534. if (iphy->protocol != SAS_PROTOCOL_SATA && (flags & PF_RESUME))
  535. sci_phy_resume(iphy);
  536. iport->active_phy_mask |= 1 << iphy->phy_index;
  537. sci_controller_clear_invalid_phy(ihost, iphy);
  538. if (flags & PF_NOTIFY)
  539. isci_port_link_up(ihost, iport, iphy);
  540. }
  541. void sci_port_deactivate_phy(struct isci_port *iport, struct isci_phy *iphy,
  542. bool do_notify_user)
  543. {
  544. struct isci_host *ihost = iport->owning_controller;
  545. iport->active_phy_mask &= ~(1 << iphy->phy_index);
  546. iport->enabled_phy_mask &= ~(1 << iphy->phy_index);
  547. if (!iport->active_phy_mask)
  548. iport->last_active_phy = iphy->phy_index;
  549. iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  550. /* Re-assign the phy back to the LP as if it were a narrow port for APC
  551. * mode. For MPC mode, the phy will remain in the port.
  552. */
  553. if (iport->owning_controller->oem_parameters.controller.mode_type ==
  554. SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE)
  555. writel(iphy->phy_index,
  556. &iport->port_pe_configuration_register[iphy->phy_index]);
  557. if (do_notify_user == true)
  558. isci_port_link_down(ihost, iphy, iport);
  559. }
  560. static void sci_port_invalid_link_up(struct isci_port *iport, struct isci_phy *iphy)
  561. {
  562. struct isci_host *ihost = iport->owning_controller;
  563. /*
  564. * Check to see if we have alreay reported this link as bad and if
  565. * not go ahead and tell the SCI_USER that we have discovered an
  566. * invalid link.
  567. */
  568. if ((ihost->invalid_phy_mask & (1 << iphy->phy_index)) == 0) {
  569. ihost->invalid_phy_mask |= 1 << iphy->phy_index;
  570. dev_warn(&ihost->pdev->dev, "Invalid link up!\n");
  571. }
  572. }
  573. /**
  574. * sci_port_general_link_up_handler - phy can be assigned to port?
  575. * @sci_port: sci_port object for which has a phy that has gone link up.
  576. * @sci_phy: This is the struct isci_phy object that has gone link up.
  577. * @flags: PF_RESUME, PF_NOTIFY to sci_port_activate_phy
  578. *
  579. * Determine if this phy can be assigned to this port . If the phy is
  580. * not a valid PHY for this port then the function will notify the user.
  581. * A PHY can only be part of a port if it's attached SAS ADDRESS is the
  582. * same as all other PHYs in the same port.
  583. */
  584. static void sci_port_general_link_up_handler(struct isci_port *iport,
  585. struct isci_phy *iphy,
  586. u8 flags)
  587. {
  588. struct sci_sas_address port_sas_address;
  589. struct sci_sas_address phy_sas_address;
  590. sci_port_get_attached_sas_address(iport, &port_sas_address);
  591. sci_phy_get_attached_sas_address(iphy, &phy_sas_address);
  592. /* If the SAS address of the new phy matches the SAS address of
  593. * other phys in the port OR this is the first phy in the port,
  594. * then activate the phy and allow it to be used for operations
  595. * in this port.
  596. */
  597. if ((phy_sas_address.high == port_sas_address.high &&
  598. phy_sas_address.low == port_sas_address.low) ||
  599. iport->active_phy_mask == 0) {
  600. struct sci_base_state_machine *sm = &iport->sm;
  601. sci_port_activate_phy(iport, iphy, flags);
  602. if (sm->current_state_id == SCI_PORT_RESETTING)
  603. port_state_machine_change(iport, SCI_PORT_READY);
  604. } else
  605. sci_port_invalid_link_up(iport, iphy);
  606. }
  607. /**
  608. * This method returns false if the port only has a single phy object assigned.
  609. * If there are no phys or more than one phy then the method will return
  610. * true.
  611. * @sci_port: The port for which the wide port condition is to be checked.
  612. *
  613. * bool true Is returned if this is a wide ported port. false Is returned if
  614. * this is a narrow port.
  615. */
  616. static bool sci_port_is_wide(struct isci_port *iport)
  617. {
  618. u32 index;
  619. u32 phy_count = 0;
  620. for (index = 0; index < SCI_MAX_PHYS; index++) {
  621. if (iport->phy_table[index] != NULL) {
  622. phy_count++;
  623. }
  624. }
  625. return phy_count != 1;
  626. }
  627. /**
  628. * This method is called by the PHY object when the link is detected. if the
  629. * port wants the PHY to continue on to the link up state then the port
  630. * layer must return true. If the port object returns false the phy object
  631. * must halt its attempt to go link up.
  632. * @sci_port: The port associated with the phy object.
  633. * @sci_phy: The phy object that is trying to go link up.
  634. *
  635. * true if the phy object can continue to the link up condition. true Is
  636. * returned if this phy can continue to the ready state. false Is returned if
  637. * can not continue on to the ready state. This notification is in place for
  638. * wide ports and direct attached phys. Since there are no wide ported SATA
  639. * devices this could become an invalid port configuration.
  640. */
  641. bool sci_port_link_detected(struct isci_port *iport, struct isci_phy *iphy)
  642. {
  643. if ((iport->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  644. (iphy->protocol == SAS_PROTOCOL_SATA)) {
  645. if (sci_port_is_wide(iport)) {
  646. sci_port_invalid_link_up(iport, iphy);
  647. return false;
  648. } else {
  649. struct isci_host *ihost = iport->owning_controller;
  650. struct isci_port *dst_port = &(ihost->ports[iphy->phy_index]);
  651. writel(iphy->phy_index,
  652. &dst_port->port_pe_configuration_register[iphy->phy_index]);
  653. }
  654. }
  655. return true;
  656. }
  657. static void port_timeout(unsigned long data)
  658. {
  659. struct sci_timer *tmr = (struct sci_timer *)data;
  660. struct isci_port *iport = container_of(tmr, typeof(*iport), timer);
  661. struct isci_host *ihost = iport->owning_controller;
  662. unsigned long flags;
  663. u32 current_state;
  664. spin_lock_irqsave(&ihost->scic_lock, flags);
  665. if (tmr->cancel)
  666. goto done;
  667. current_state = iport->sm.current_state_id;
  668. if (current_state == SCI_PORT_RESETTING) {
  669. /* if the port is still in the resetting state then the timeout
  670. * fired before the reset completed.
  671. */
  672. port_state_machine_change(iport, SCI_PORT_FAILED);
  673. } else if (current_state == SCI_PORT_STOPPED) {
  674. /* if the port is stopped then the start request failed In this
  675. * case stay in the stopped state.
  676. */
  677. dev_err(sciport_to_dev(iport),
  678. "%s: SCIC Port 0x%p failed to stop before timeout.\n",
  679. __func__,
  680. iport);
  681. } else if (current_state == SCI_PORT_STOPPING) {
  682. dev_dbg(sciport_to_dev(iport),
  683. "%s: port%d: stop complete timeout\n",
  684. __func__, iport->physical_port_index);
  685. } else {
  686. /* The port is in the ready state and we have a timer
  687. * reporting a timeout this should not happen.
  688. */
  689. dev_err(sciport_to_dev(iport),
  690. "%s: SCIC Port 0x%p is processing a timeout operation "
  691. "in state %d.\n", __func__, iport, current_state);
  692. }
  693. done:
  694. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  695. }
  696. /* --------------------------------------------------------------------------- */
  697. /**
  698. * This function updates the hardwares VIIT entry for this port.
  699. *
  700. *
  701. */
  702. static void sci_port_update_viit_entry(struct isci_port *iport)
  703. {
  704. struct sci_sas_address sas_address;
  705. sci_port_get_sas_address(iport, &sas_address);
  706. writel(sas_address.high,
  707. &iport->viit_registers->initiator_sas_address_hi);
  708. writel(sas_address.low,
  709. &iport->viit_registers->initiator_sas_address_lo);
  710. /* This value get cleared just in case its not already cleared */
  711. writel(0, &iport->viit_registers->reserved);
  712. /* We are required to update the status register last */
  713. writel(SCU_VIIT_ENTRY_ID_VIIT |
  714. SCU_VIIT_IPPT_INITIATOR |
  715. ((1 << iport->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  716. SCU_VIIT_STATUS_ALL_VALID,
  717. &iport->viit_registers->status);
  718. }
  719. enum sas_linkrate sci_port_get_max_allowed_speed(struct isci_port *iport)
  720. {
  721. u16 index;
  722. struct isci_phy *iphy;
  723. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  724. /*
  725. * Loop through all of the phys in this port and find the phy with the
  726. * lowest maximum link rate. */
  727. for (index = 0; index < SCI_MAX_PHYS; index++) {
  728. iphy = iport->phy_table[index];
  729. if (iphy && sci_port_active_phy(iport, iphy) &&
  730. iphy->max_negotiated_speed < max_allowed_speed)
  731. max_allowed_speed = iphy->max_negotiated_speed;
  732. }
  733. return max_allowed_speed;
  734. }
  735. static void sci_port_suspend_port_task_scheduler(struct isci_port *iport)
  736. {
  737. u32 pts_control_value;
  738. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  739. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  740. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  741. }
  742. /**
  743. * sci_port_post_dummy_request() - post dummy/workaround request
  744. * @sci_port: port to post task
  745. *
  746. * Prevent the hardware scheduler from posting new requests to the front
  747. * of the scheduler queue causing a starvation problem for currently
  748. * ongoing requests.
  749. *
  750. */
  751. static void sci_port_post_dummy_request(struct isci_port *iport)
  752. {
  753. struct isci_host *ihost = iport->owning_controller;
  754. u16 tag = iport->reserved_tag;
  755. struct scu_task_context *tc;
  756. u32 command;
  757. tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  758. tc->abort = 0;
  759. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  760. iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  761. ISCI_TAG_TCI(tag);
  762. sci_controller_post_request(ihost, command);
  763. }
  764. /**
  765. * This routine will abort the dummy request. This will alow the hardware to
  766. * power down parts of the silicon to save power.
  767. *
  768. * @sci_port: The port on which the task must be aborted.
  769. *
  770. */
  771. static void sci_port_abort_dummy_request(struct isci_port *iport)
  772. {
  773. struct isci_host *ihost = iport->owning_controller;
  774. u16 tag = iport->reserved_tag;
  775. struct scu_task_context *tc;
  776. u32 command;
  777. tc = &ihost->task_context_table[ISCI_TAG_TCI(tag)];
  778. tc->abort = 1;
  779. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  780. iport->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  781. ISCI_TAG_TCI(tag);
  782. sci_controller_post_request(ihost, command);
  783. }
  784. /**
  785. *
  786. * @sci_port: This is the struct isci_port object to resume.
  787. *
  788. * This method will resume the port task scheduler for this port object. none
  789. */
  790. static void
  791. sci_port_resume_port_task_scheduler(struct isci_port *iport)
  792. {
  793. u32 pts_control_value;
  794. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  795. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  796. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  797. }
  798. static void sci_port_ready_substate_waiting_enter(struct sci_base_state_machine *sm)
  799. {
  800. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  801. sci_port_suspend_port_task_scheduler(iport);
  802. iport->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  803. if (iport->active_phy_mask != 0) {
  804. /* At least one of the phys on the port is ready */
  805. port_state_machine_change(iport,
  806. SCI_PORT_SUB_OPERATIONAL);
  807. }
  808. }
  809. static void scic_sds_port_ready_substate_waiting_exit(
  810. struct sci_base_state_machine *sm)
  811. {
  812. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  813. sci_port_resume_port_task_scheduler(iport);
  814. }
  815. static void sci_port_ready_substate_operational_enter(struct sci_base_state_machine *sm)
  816. {
  817. u32 index;
  818. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  819. struct isci_host *ihost = iport->owning_controller;
  820. dev_dbg(&ihost->pdev->dev, "%s: port%d ready\n",
  821. __func__, iport->physical_port_index);
  822. for (index = 0; index < SCI_MAX_PHYS; index++) {
  823. if (iport->phy_table[index]) {
  824. writel(iport->physical_port_index,
  825. &iport->port_pe_configuration_register[
  826. iport->phy_table[index]->phy_index]);
  827. if (((iport->active_phy_mask^iport->enabled_phy_mask) & (1 << index)) != 0)
  828. sci_port_resume_phy(iport, iport->phy_table[index]);
  829. }
  830. }
  831. sci_port_update_viit_entry(iport);
  832. /*
  833. * Post the dummy task for the port so the hardware can schedule
  834. * io correctly
  835. */
  836. sci_port_post_dummy_request(iport);
  837. }
  838. static void sci_port_invalidate_dummy_remote_node(struct isci_port *iport)
  839. {
  840. struct isci_host *ihost = iport->owning_controller;
  841. u8 phys_index = iport->physical_port_index;
  842. union scu_remote_node_context *rnc;
  843. u16 rni = iport->reserved_rni;
  844. u32 command;
  845. rnc = &ihost->remote_node_context_table[rni];
  846. rnc->ssp.is_valid = false;
  847. /* ensure the preceding tc abort request has reached the
  848. * controller and give it ample time to act before posting the rnc
  849. * invalidate
  850. */
  851. readl(&ihost->smu_registers->interrupt_status); /* flush */
  852. udelay(10);
  853. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  854. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  855. sci_controller_post_request(ihost, command);
  856. }
  857. /**
  858. *
  859. * @object: This is the object which is cast to a struct isci_port object.
  860. *
  861. * This method will perform the actions required by the struct isci_port on
  862. * exiting the SCI_PORT_SUB_OPERATIONAL. This function reports
  863. * the port not ready and suspends the port task scheduler. none
  864. */
  865. static void sci_port_ready_substate_operational_exit(struct sci_base_state_machine *sm)
  866. {
  867. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  868. struct isci_host *ihost = iport->owning_controller;
  869. /*
  870. * Kill the dummy task for this port if it has not yet posted
  871. * the hardware will treat this as a NOP and just return abort
  872. * complete.
  873. */
  874. sci_port_abort_dummy_request(iport);
  875. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  876. __func__, iport->physical_port_index);
  877. if (iport->ready_exit)
  878. sci_port_invalidate_dummy_remote_node(iport);
  879. }
  880. static void sci_port_ready_substate_configuring_enter(struct sci_base_state_machine *sm)
  881. {
  882. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  883. struct isci_host *ihost = iport->owning_controller;
  884. if (iport->active_phy_mask == 0) {
  885. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  886. __func__, iport->physical_port_index);
  887. port_state_machine_change(iport, SCI_PORT_SUB_WAITING);
  888. } else
  889. port_state_machine_change(iport, SCI_PORT_SUB_OPERATIONAL);
  890. }
  891. enum sci_status sci_port_start(struct isci_port *iport)
  892. {
  893. struct isci_host *ihost = iport->owning_controller;
  894. enum sci_status status = SCI_SUCCESS;
  895. enum sci_port_states state;
  896. u32 phy_mask;
  897. state = iport->sm.current_state_id;
  898. if (state != SCI_PORT_STOPPED) {
  899. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  900. __func__, port_state_name(state));
  901. return SCI_FAILURE_INVALID_STATE;
  902. }
  903. if (iport->assigned_device_count > 0) {
  904. /* TODO This is a start failure operation because
  905. * there are still devices assigned to this port.
  906. * There must be no devices assigned to a port on a
  907. * start operation.
  908. */
  909. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  910. }
  911. if (iport->reserved_rni == SCU_DUMMY_INDEX) {
  912. u16 rni = sci_remote_node_table_allocate_remote_node(
  913. &ihost->available_remote_nodes, 1);
  914. if (rni != SCU_DUMMY_INDEX)
  915. sci_port_construct_dummy_rnc(iport, rni);
  916. else
  917. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  918. iport->reserved_rni = rni;
  919. }
  920. if (iport->reserved_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
  921. u16 tag;
  922. tag = isci_alloc_tag(ihost);
  923. if (tag == SCI_CONTROLLER_INVALID_IO_TAG)
  924. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  925. else
  926. sci_port_construct_dummy_task(iport, tag);
  927. iport->reserved_tag = tag;
  928. }
  929. if (status == SCI_SUCCESS) {
  930. phy_mask = sci_port_get_phys(iport);
  931. /*
  932. * There are one or more phys assigned to this port. Make sure
  933. * the port's phy mask is in fact legal and supported by the
  934. * silicon.
  935. */
  936. if (sci_port_is_phy_mask_valid(iport, phy_mask) == true) {
  937. port_state_machine_change(iport,
  938. SCI_PORT_READY);
  939. return SCI_SUCCESS;
  940. }
  941. status = SCI_FAILURE;
  942. }
  943. if (status != SCI_SUCCESS)
  944. sci_port_destroy_dummy_resources(iport);
  945. return status;
  946. }
  947. enum sci_status sci_port_stop(struct isci_port *iport)
  948. {
  949. enum sci_port_states state;
  950. state = iport->sm.current_state_id;
  951. switch (state) {
  952. case SCI_PORT_STOPPED:
  953. return SCI_SUCCESS;
  954. case SCI_PORT_SUB_WAITING:
  955. case SCI_PORT_SUB_OPERATIONAL:
  956. case SCI_PORT_SUB_CONFIGURING:
  957. case SCI_PORT_RESETTING:
  958. port_state_machine_change(iport,
  959. SCI_PORT_STOPPING);
  960. return SCI_SUCCESS;
  961. default:
  962. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  963. __func__, port_state_name(state));
  964. return SCI_FAILURE_INVALID_STATE;
  965. }
  966. }
  967. static enum sci_status sci_port_hard_reset(struct isci_port *iport, u32 timeout)
  968. {
  969. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  970. struct isci_phy *iphy = NULL;
  971. enum sci_port_states state;
  972. u32 phy_index;
  973. state = iport->sm.current_state_id;
  974. if (state != SCI_PORT_SUB_OPERATIONAL) {
  975. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  976. __func__, port_state_name(state));
  977. return SCI_FAILURE_INVALID_STATE;
  978. }
  979. /* Select a phy on which we can send the hard reset request. */
  980. for (phy_index = 0; phy_index < SCI_MAX_PHYS && !iphy; phy_index++) {
  981. iphy = iport->phy_table[phy_index];
  982. if (iphy && !sci_port_active_phy(iport, iphy)) {
  983. /*
  984. * We found a phy but it is not ready select
  985. * different phy
  986. */
  987. iphy = NULL;
  988. }
  989. }
  990. /* If we have a phy then go ahead and start the reset procedure */
  991. if (!iphy)
  992. return status;
  993. status = sci_phy_reset(iphy);
  994. if (status != SCI_SUCCESS)
  995. return status;
  996. sci_mod_timer(&iport->timer, timeout);
  997. iport->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  998. port_state_machine_change(iport, SCI_PORT_RESETTING);
  999. return SCI_SUCCESS;
  1000. }
  1001. /**
  1002. * sci_port_add_phy() -
  1003. * @sci_port: This parameter specifies the port in which the phy will be added.
  1004. * @sci_phy: This parameter is the phy which is to be added to the port.
  1005. *
  1006. * This method will add a PHY to the selected port. This method returns an
  1007. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
  1008. * status is a failure to add the phy to the port.
  1009. */
  1010. enum sci_status sci_port_add_phy(struct isci_port *iport,
  1011. struct isci_phy *iphy)
  1012. {
  1013. enum sci_status status;
  1014. enum sci_port_states state;
  1015. sci_port_bcn_enable(iport);
  1016. state = iport->sm.current_state_id;
  1017. switch (state) {
  1018. case SCI_PORT_STOPPED: {
  1019. struct sci_sas_address port_sas_address;
  1020. /* Read the port assigned SAS Address if there is one */
  1021. sci_port_get_sas_address(iport, &port_sas_address);
  1022. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1023. struct sci_sas_address phy_sas_address;
  1024. /* Make sure that the PHY SAS Address matches the SAS Address
  1025. * for this port
  1026. */
  1027. sci_phy_get_sas_address(iphy, &phy_sas_address);
  1028. if (port_sas_address.high != phy_sas_address.high ||
  1029. port_sas_address.low != phy_sas_address.low)
  1030. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1031. }
  1032. return sci_port_set_phy(iport, iphy);
  1033. }
  1034. case SCI_PORT_SUB_WAITING:
  1035. case SCI_PORT_SUB_OPERATIONAL:
  1036. status = sci_port_set_phy(iport, iphy);
  1037. if (status != SCI_SUCCESS)
  1038. return status;
  1039. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
  1040. iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1041. port_state_machine_change(iport, SCI_PORT_SUB_CONFIGURING);
  1042. return status;
  1043. case SCI_PORT_SUB_CONFIGURING:
  1044. status = sci_port_set_phy(iport, iphy);
  1045. if (status != SCI_SUCCESS)
  1046. return status;
  1047. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY);
  1048. /* Re-enter the configuring state since this may be the last phy in
  1049. * the port.
  1050. */
  1051. port_state_machine_change(iport,
  1052. SCI_PORT_SUB_CONFIGURING);
  1053. return SCI_SUCCESS;
  1054. default:
  1055. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1056. __func__, port_state_name(state));
  1057. return SCI_FAILURE_INVALID_STATE;
  1058. }
  1059. }
  1060. /**
  1061. * sci_port_remove_phy() -
  1062. * @sci_port: This parameter specifies the port in which the phy will be added.
  1063. * @sci_phy: This parameter is the phy which is to be added to the port.
  1064. *
  1065. * This method will remove the PHY from the selected PORT. This method returns
  1066. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
  1067. * other status is a failure to add the phy to the port.
  1068. */
  1069. enum sci_status sci_port_remove_phy(struct isci_port *iport,
  1070. struct isci_phy *iphy)
  1071. {
  1072. enum sci_status status;
  1073. enum sci_port_states state;
  1074. state = iport->sm.current_state_id;
  1075. switch (state) {
  1076. case SCI_PORT_STOPPED:
  1077. return sci_port_clear_phy(iport, iphy);
  1078. case SCI_PORT_SUB_OPERATIONAL:
  1079. status = sci_port_clear_phy(iport, iphy);
  1080. if (status != SCI_SUCCESS)
  1081. return status;
  1082. sci_port_deactivate_phy(iport, iphy, true);
  1083. iport->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1084. port_state_machine_change(iport,
  1085. SCI_PORT_SUB_CONFIGURING);
  1086. return SCI_SUCCESS;
  1087. case SCI_PORT_SUB_CONFIGURING:
  1088. status = sci_port_clear_phy(iport, iphy);
  1089. if (status != SCI_SUCCESS)
  1090. return status;
  1091. sci_port_deactivate_phy(iport, iphy, true);
  1092. /* Re-enter the configuring state since this may be the last phy in
  1093. * the port
  1094. */
  1095. port_state_machine_change(iport,
  1096. SCI_PORT_SUB_CONFIGURING);
  1097. return SCI_SUCCESS;
  1098. default:
  1099. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1100. __func__, port_state_name(state));
  1101. return SCI_FAILURE_INVALID_STATE;
  1102. }
  1103. }
  1104. enum sci_status sci_port_link_up(struct isci_port *iport,
  1105. struct isci_phy *iphy)
  1106. {
  1107. enum sci_port_states state;
  1108. state = iport->sm.current_state_id;
  1109. switch (state) {
  1110. case SCI_PORT_SUB_WAITING:
  1111. /* Since this is the first phy going link up for the port we
  1112. * can just enable it and continue
  1113. */
  1114. sci_port_activate_phy(iport, iphy, PF_NOTIFY|PF_RESUME);
  1115. port_state_machine_change(iport,
  1116. SCI_PORT_SUB_OPERATIONAL);
  1117. return SCI_SUCCESS;
  1118. case SCI_PORT_SUB_OPERATIONAL:
  1119. sci_port_general_link_up_handler(iport, iphy, PF_NOTIFY|PF_RESUME);
  1120. return SCI_SUCCESS;
  1121. case SCI_PORT_RESETTING:
  1122. /* TODO We should make sure that the phy that has gone
  1123. * link up is the same one on which we sent the reset. It is
  1124. * possible that the phy on which we sent the reset is not the
  1125. * one that has gone link up and we want to make sure that
  1126. * phy being reset comes back. Consider the case where a
  1127. * reset is sent but before the hardware processes the reset it
  1128. * get a link up on the port because of a hot plug event.
  1129. * because of the reset request this phy will go link down
  1130. * almost immediately.
  1131. */
  1132. /* In the resetting state we don't notify the user regarding
  1133. * link up and link down notifications.
  1134. */
  1135. sci_port_general_link_up_handler(iport, iphy, PF_RESUME);
  1136. return SCI_SUCCESS;
  1137. default:
  1138. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1139. __func__, port_state_name(state));
  1140. return SCI_FAILURE_INVALID_STATE;
  1141. }
  1142. }
  1143. enum sci_status sci_port_link_down(struct isci_port *iport,
  1144. struct isci_phy *iphy)
  1145. {
  1146. enum sci_port_states state;
  1147. state = iport->sm.current_state_id;
  1148. switch (state) {
  1149. case SCI_PORT_SUB_OPERATIONAL:
  1150. sci_port_deactivate_phy(iport, iphy, true);
  1151. /* If there are no active phys left in the port, then
  1152. * transition the port to the WAITING state until such time
  1153. * as a phy goes link up
  1154. */
  1155. if (iport->active_phy_mask == 0)
  1156. port_state_machine_change(iport,
  1157. SCI_PORT_SUB_WAITING);
  1158. return SCI_SUCCESS;
  1159. case SCI_PORT_RESETTING:
  1160. /* In the resetting state we don't notify the user regarding
  1161. * link up and link down notifications. */
  1162. sci_port_deactivate_phy(iport, iphy, false);
  1163. return SCI_SUCCESS;
  1164. default:
  1165. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1166. __func__, port_state_name(state));
  1167. return SCI_FAILURE_INVALID_STATE;
  1168. }
  1169. }
  1170. enum sci_status sci_port_start_io(struct isci_port *iport,
  1171. struct isci_remote_device *idev,
  1172. struct isci_request *ireq)
  1173. {
  1174. enum sci_port_states state;
  1175. state = iport->sm.current_state_id;
  1176. switch (state) {
  1177. case SCI_PORT_SUB_WAITING:
  1178. return SCI_FAILURE_INVALID_STATE;
  1179. case SCI_PORT_SUB_OPERATIONAL:
  1180. iport->started_request_count++;
  1181. return SCI_SUCCESS;
  1182. default:
  1183. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1184. __func__, port_state_name(state));
  1185. return SCI_FAILURE_INVALID_STATE;
  1186. }
  1187. }
  1188. enum sci_status sci_port_complete_io(struct isci_port *iport,
  1189. struct isci_remote_device *idev,
  1190. struct isci_request *ireq)
  1191. {
  1192. enum sci_port_states state;
  1193. state = iport->sm.current_state_id;
  1194. switch (state) {
  1195. case SCI_PORT_STOPPED:
  1196. dev_warn(sciport_to_dev(iport), "%s: in wrong state: %s\n",
  1197. __func__, port_state_name(state));
  1198. return SCI_FAILURE_INVALID_STATE;
  1199. case SCI_PORT_STOPPING:
  1200. sci_port_decrement_request_count(iport);
  1201. if (iport->started_request_count == 0)
  1202. port_state_machine_change(iport,
  1203. SCI_PORT_STOPPED);
  1204. break;
  1205. case SCI_PORT_READY:
  1206. case SCI_PORT_RESETTING:
  1207. case SCI_PORT_FAILED:
  1208. case SCI_PORT_SUB_WAITING:
  1209. case SCI_PORT_SUB_OPERATIONAL:
  1210. sci_port_decrement_request_count(iport);
  1211. break;
  1212. case SCI_PORT_SUB_CONFIGURING:
  1213. sci_port_decrement_request_count(iport);
  1214. if (iport->started_request_count == 0) {
  1215. port_state_machine_change(iport,
  1216. SCI_PORT_SUB_OPERATIONAL);
  1217. }
  1218. break;
  1219. }
  1220. return SCI_SUCCESS;
  1221. }
  1222. static void sci_port_enable_port_task_scheduler(struct isci_port *iport)
  1223. {
  1224. u32 pts_control_value;
  1225. /* enable the port task scheduler in a suspended state */
  1226. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  1227. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1228. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  1229. }
  1230. static void sci_port_disable_port_task_scheduler(struct isci_port *iport)
  1231. {
  1232. u32 pts_control_value;
  1233. pts_control_value = readl(&iport->port_task_scheduler_registers->control);
  1234. pts_control_value &=
  1235. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1236. writel(pts_control_value, &iport->port_task_scheduler_registers->control);
  1237. }
  1238. static void sci_port_post_dummy_remote_node(struct isci_port *iport)
  1239. {
  1240. struct isci_host *ihost = iport->owning_controller;
  1241. u8 phys_index = iport->physical_port_index;
  1242. union scu_remote_node_context *rnc;
  1243. u16 rni = iport->reserved_rni;
  1244. u32 command;
  1245. rnc = &ihost->remote_node_context_table[rni];
  1246. rnc->ssp.is_valid = true;
  1247. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1248. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1249. sci_controller_post_request(ihost, command);
  1250. /* ensure hardware has seen the post rnc command and give it
  1251. * ample time to act before sending the suspend
  1252. */
  1253. readl(&ihost->smu_registers->interrupt_status); /* flush */
  1254. udelay(10);
  1255. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1256. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1257. sci_controller_post_request(ihost, command);
  1258. }
  1259. static void sci_port_stopped_state_enter(struct sci_base_state_machine *sm)
  1260. {
  1261. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1262. if (iport->sm.previous_state_id == SCI_PORT_STOPPING) {
  1263. /*
  1264. * If we enter this state becasuse of a request to stop
  1265. * the port then we want to disable the hardwares port
  1266. * task scheduler. */
  1267. sci_port_disable_port_task_scheduler(iport);
  1268. }
  1269. }
  1270. static void sci_port_stopped_state_exit(struct sci_base_state_machine *sm)
  1271. {
  1272. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1273. /* Enable and suspend the port task scheduler */
  1274. sci_port_enable_port_task_scheduler(iport);
  1275. }
  1276. static void sci_port_ready_state_enter(struct sci_base_state_machine *sm)
  1277. {
  1278. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1279. struct isci_host *ihost = iport->owning_controller;
  1280. u32 prev_state;
  1281. prev_state = iport->sm.previous_state_id;
  1282. if (prev_state == SCI_PORT_RESETTING)
  1283. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  1284. else
  1285. dev_dbg(&ihost->pdev->dev, "%s: port%d !ready\n",
  1286. __func__, iport->physical_port_index);
  1287. /* Post and suspend the dummy remote node context for this port. */
  1288. sci_port_post_dummy_remote_node(iport);
  1289. /* Start the ready substate machine */
  1290. port_state_machine_change(iport,
  1291. SCI_PORT_SUB_WAITING);
  1292. }
  1293. static void sci_port_resetting_state_exit(struct sci_base_state_machine *sm)
  1294. {
  1295. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1296. sci_del_timer(&iport->timer);
  1297. }
  1298. static void sci_port_stopping_state_exit(struct sci_base_state_machine *sm)
  1299. {
  1300. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1301. sci_del_timer(&iport->timer);
  1302. sci_port_destroy_dummy_resources(iport);
  1303. }
  1304. static void sci_port_failed_state_enter(struct sci_base_state_machine *sm)
  1305. {
  1306. struct isci_port *iport = container_of(sm, typeof(*iport), sm);
  1307. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  1308. }
  1309. void sci_port_set_hang_detection_timeout(struct isci_port *iport, u32 timeout)
  1310. {
  1311. int phy_index;
  1312. u32 phy_mask = iport->active_phy_mask;
  1313. if (timeout)
  1314. ++iport->hang_detect_users;
  1315. else if (iport->hang_detect_users > 1)
  1316. --iport->hang_detect_users;
  1317. else
  1318. iport->hang_detect_users = 0;
  1319. if (timeout || (iport->hang_detect_users == 0)) {
  1320. for (phy_index = 0; phy_index < SCI_MAX_PHYS; phy_index++) {
  1321. if ((phy_mask >> phy_index) & 1) {
  1322. writel(timeout,
  1323. &iport->phy_table[phy_index]
  1324. ->link_layer_registers
  1325. ->link_layer_hang_detection_timeout);
  1326. }
  1327. }
  1328. }
  1329. }
  1330. /* --------------------------------------------------------------------------- */
  1331. static const struct sci_base_state sci_port_state_table[] = {
  1332. [SCI_PORT_STOPPED] = {
  1333. .enter_state = sci_port_stopped_state_enter,
  1334. .exit_state = sci_port_stopped_state_exit
  1335. },
  1336. [SCI_PORT_STOPPING] = {
  1337. .exit_state = sci_port_stopping_state_exit
  1338. },
  1339. [SCI_PORT_READY] = {
  1340. .enter_state = sci_port_ready_state_enter,
  1341. },
  1342. [SCI_PORT_SUB_WAITING] = {
  1343. .enter_state = sci_port_ready_substate_waiting_enter,
  1344. .exit_state = scic_sds_port_ready_substate_waiting_exit,
  1345. },
  1346. [SCI_PORT_SUB_OPERATIONAL] = {
  1347. .enter_state = sci_port_ready_substate_operational_enter,
  1348. .exit_state = sci_port_ready_substate_operational_exit
  1349. },
  1350. [SCI_PORT_SUB_CONFIGURING] = {
  1351. .enter_state = sci_port_ready_substate_configuring_enter
  1352. },
  1353. [SCI_PORT_RESETTING] = {
  1354. .exit_state = sci_port_resetting_state_exit
  1355. },
  1356. [SCI_PORT_FAILED] = {
  1357. .enter_state = sci_port_failed_state_enter,
  1358. }
  1359. };
  1360. void sci_port_construct(struct isci_port *iport, u8 index,
  1361. struct isci_host *ihost)
  1362. {
  1363. sci_init_sm(&iport->sm, sci_port_state_table, SCI_PORT_STOPPED);
  1364. iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
  1365. iport->physical_port_index = index;
  1366. iport->active_phy_mask = 0;
  1367. iport->enabled_phy_mask = 0;
  1368. iport->last_active_phy = 0;
  1369. iport->ready_exit = false;
  1370. iport->owning_controller = ihost;
  1371. iport->started_request_count = 0;
  1372. iport->assigned_device_count = 0;
  1373. iport->hang_detect_users = 0;
  1374. iport->reserved_rni = SCU_DUMMY_INDEX;
  1375. iport->reserved_tag = SCI_CONTROLLER_INVALID_IO_TAG;
  1376. sci_init_timer(&iport->timer, port_timeout);
  1377. iport->port_task_scheduler_registers = NULL;
  1378. for (index = 0; index < SCI_MAX_PHYS; index++)
  1379. iport->phy_table[index] = NULL;
  1380. }
  1381. void sci_port_broadcast_change_received(struct isci_port *iport, struct isci_phy *iphy)
  1382. {
  1383. struct isci_host *ihost = iport->owning_controller;
  1384. /* notify the user. */
  1385. isci_port_bc_change_received(ihost, iport, iphy);
  1386. }
  1387. static void wait_port_reset(struct isci_host *ihost, struct isci_port *iport)
  1388. {
  1389. wait_event(ihost->eventq, !test_bit(IPORT_RESET_PENDING, &iport->state));
  1390. }
  1391. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  1392. struct isci_phy *iphy)
  1393. {
  1394. unsigned long flags;
  1395. enum sci_status status;
  1396. int ret = TMF_RESP_FUNC_COMPLETE;
  1397. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  1398. __func__, iport);
  1399. spin_lock_irqsave(&ihost->scic_lock, flags);
  1400. set_bit(IPORT_RESET_PENDING, &iport->state);
  1401. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  1402. status = sci_port_hard_reset(iport, ISCI_PORT_RESET_TIMEOUT);
  1403. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1404. if (status == SCI_SUCCESS) {
  1405. wait_port_reset(ihost, iport);
  1406. dev_dbg(&ihost->pdev->dev,
  1407. "%s: iport = %p; hard reset completion\n",
  1408. __func__, iport);
  1409. if (iport->hard_reset_status != SCI_SUCCESS) {
  1410. ret = TMF_RESP_FUNC_FAILED;
  1411. dev_err(&ihost->pdev->dev,
  1412. "%s: iport = %p; hard reset failed (0x%x)\n",
  1413. __func__, iport, iport->hard_reset_status);
  1414. }
  1415. } else {
  1416. clear_bit(IPORT_RESET_PENDING, &iport->state);
  1417. wake_up(&ihost->eventq);
  1418. ret = TMF_RESP_FUNC_FAILED;
  1419. dev_err(&ihost->pdev->dev,
  1420. "%s: iport = %p; sci_port_hard_reset call"
  1421. " failed 0x%x\n",
  1422. __func__, iport, status);
  1423. }
  1424. return ret;
  1425. }
  1426. int isci_ata_check_ready(struct domain_device *dev)
  1427. {
  1428. struct isci_port *iport = dev->port->lldd_port;
  1429. struct isci_host *ihost = dev_to_ihost(dev);
  1430. struct isci_remote_device *idev;
  1431. unsigned long flags;
  1432. int rc = 0;
  1433. spin_lock_irqsave(&ihost->scic_lock, flags);
  1434. idev = isci_lookup_device(dev);
  1435. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1436. if (!idev)
  1437. goto out;
  1438. if (test_bit(IPORT_RESET_PENDING, &iport->state))
  1439. goto out;
  1440. rc = !!iport->active_phy_mask;
  1441. out:
  1442. isci_put_device(idev);
  1443. return rc;
  1444. }
  1445. void isci_port_deformed(struct asd_sas_phy *phy)
  1446. {
  1447. struct isci_host *ihost = phy->ha->lldd_ha;
  1448. struct isci_port *iport = phy->port->lldd_port;
  1449. unsigned long flags;
  1450. int i;
  1451. /* we got a port notification on a port that was subsequently
  1452. * torn down and libsas is just now catching up
  1453. */
  1454. if (!iport)
  1455. return;
  1456. spin_lock_irqsave(&ihost->scic_lock, flags);
  1457. for (i = 0; i < SCI_MAX_PHYS; i++) {
  1458. if (iport->active_phy_mask & 1 << i)
  1459. break;
  1460. }
  1461. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1462. if (i >= SCI_MAX_PHYS)
  1463. dev_dbg(&ihost->pdev->dev, "%s: port: %ld\n",
  1464. __func__, (long) (iport - &ihost->ports[0]));
  1465. }
  1466. void isci_port_formed(struct asd_sas_phy *phy)
  1467. {
  1468. struct isci_host *ihost = phy->ha->lldd_ha;
  1469. struct isci_phy *iphy = to_iphy(phy);
  1470. struct asd_sas_port *port = phy->port;
  1471. struct isci_port *iport = NULL;
  1472. unsigned long flags;
  1473. int i;
  1474. /* initial ports are formed as the driver is still initializing,
  1475. * wait for that process to complete
  1476. */
  1477. wait_for_start(ihost);
  1478. spin_lock_irqsave(&ihost->scic_lock, flags);
  1479. for (i = 0; i < SCI_MAX_PORTS; i++) {
  1480. iport = &ihost->ports[i];
  1481. if (iport->active_phy_mask & 1 << iphy->phy_index)
  1482. break;
  1483. }
  1484. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  1485. if (i >= SCI_MAX_PORTS)
  1486. iport = NULL;
  1487. port->lldd_port = iport;
  1488. }