port.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376
  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. #include "timers.h"
  59. #define SCIC_SDS_PORT_HARD_RESET_TIMEOUT (1000)
  60. #define SCU_DUMMY_INDEX (0xFFFF)
  61. static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[];
  62. static void isci_port_change_state(struct isci_port *iport, enum isci_status status)
  63. {
  64. unsigned long flags;
  65. dev_dbg(&iport->isci_host->pdev->dev,
  66. "%s: iport = %p, state = 0x%x\n",
  67. __func__, iport, status);
  68. /* XXX pointless lock */
  69. spin_lock_irqsave(&iport->state_lock, flags);
  70. iport->status = status;
  71. spin_unlock_irqrestore(&iport->state_lock, flags);
  72. }
  73. /*
  74. * This function will indicate which protocols are supported by this port.
  75. * @sci_port: a handle corresponding to the SAS port for which to return the
  76. * supported protocols.
  77. * @protocols: This parameter specifies a pointer to a data structure
  78. * which the core will copy the protocol values for the port from the
  79. * transmit_identification register.
  80. */
  81. static void
  82. scic_sds_port_get_protocols(struct scic_sds_port *sci_port,
  83. struct scic_phy_proto *protocols)
  84. {
  85. u8 index;
  86. protocols->all = 0;
  87. for (index = 0; index < SCI_MAX_PHYS; index++) {
  88. if (sci_port->phy_table[index] != NULL) {
  89. scic_sds_phy_get_protocols(sci_port->phy_table[index],
  90. protocols);
  91. }
  92. }
  93. }
  94. /**
  95. * This method requests a list (mask) of the phys contained in the supplied SAS
  96. * port.
  97. * @sci_port: a handle corresponding to the SAS port for which to return the
  98. * phy mask.
  99. *
  100. * Return a bit mask indicating which phys are a part of this port. Each bit
  101. * corresponds to a phy identifier (e.g. bit 0 = phy id 0).
  102. */
  103. static u32 scic_sds_port_get_phys(struct scic_sds_port *sci_port)
  104. {
  105. u32 index;
  106. u32 mask;
  107. mask = 0;
  108. for (index = 0; index < SCI_MAX_PHYS; index++) {
  109. if (sci_port->phy_table[index] != NULL) {
  110. mask |= (1 << index);
  111. }
  112. }
  113. return mask;
  114. }
  115. /**
  116. * scic_port_get_properties() - This method simply returns the properties
  117. * regarding the port, such as: physical index, protocols, sas address, etc.
  118. * @port: this parameter specifies the port for which to retrieve the physical
  119. * index.
  120. * @properties: This parameter specifies the properties structure into which to
  121. * copy the requested information.
  122. *
  123. * Indicate if the user specified a valid port. SCI_SUCCESS This value is
  124. * returned if the specified port was valid. SCI_FAILURE_INVALID_PORT This
  125. * value is returned if the specified port is not valid. When this value is
  126. * returned, no data is copied to the properties output parameter.
  127. */
  128. static enum sci_status scic_port_get_properties(struct scic_sds_port *port,
  129. struct scic_port_properties *prop)
  130. {
  131. if ((port == NULL) ||
  132. (port->logical_port_index == SCIC_SDS_DUMMY_PORT))
  133. return SCI_FAILURE_INVALID_PORT;
  134. prop->index = port->logical_port_index;
  135. prop->phy_mask = scic_sds_port_get_phys(port);
  136. scic_sds_port_get_sas_address(port, &prop->local.sas_address);
  137. scic_sds_port_get_protocols(port, &prop->local.protocols);
  138. scic_sds_port_get_attached_sas_address(port, &prop->remote.sas_address);
  139. return SCI_SUCCESS;
  140. }
  141. static void isci_port_link_up(struct isci_host *isci_host,
  142. struct scic_sds_port *port,
  143. struct scic_sds_phy *phy)
  144. {
  145. unsigned long flags;
  146. struct scic_port_properties properties;
  147. struct isci_phy *isci_phy = sci_phy_to_iphy(phy);
  148. struct isci_port *isci_port = sci_port_to_iport(port);
  149. unsigned long success = true;
  150. BUG_ON(isci_phy->isci_port != NULL);
  151. isci_phy->isci_port = isci_port;
  152. dev_dbg(&isci_host->pdev->dev,
  153. "%s: isci_port = %p\n",
  154. __func__, isci_port);
  155. spin_lock_irqsave(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  156. isci_port_change_state(isci_phy->isci_port, isci_starting);
  157. scic_port_get_properties(port, &properties);
  158. if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) {
  159. u64 attached_sas_address;
  160. isci_phy->sas_phy.oob_mode = SATA_OOB_MODE;
  161. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct dev_to_host_fis);
  162. /*
  163. * For direct-attached SATA devices, the SCI core will
  164. * automagically assign a SAS address to the end device
  165. * for the purpose of creating a port. This SAS address
  166. * will not be the same as assigned to the PHY and needs
  167. * to be obtained from struct scic_port_properties properties.
  168. */
  169. attached_sas_address = properties.remote.sas_address.high;
  170. attached_sas_address <<= 32;
  171. attached_sas_address |= properties.remote.sas_address.low;
  172. swab64s(&attached_sas_address);
  173. memcpy(&isci_phy->sas_phy.attached_sas_addr,
  174. &attached_sas_address, sizeof(attached_sas_address));
  175. } else if (phy->protocol == SCIC_SDS_PHY_PROTOCOL_SAS) {
  176. isci_phy->sas_phy.oob_mode = SAS_OOB_MODE;
  177. isci_phy->sas_phy.frame_rcvd_size = sizeof(struct sas_identify_frame);
  178. /* Copy the attached SAS address from the IAF */
  179. memcpy(isci_phy->sas_phy.attached_sas_addr,
  180. isci_phy->frame_rcvd.iaf.sas_addr, SAS_ADDR_SIZE);
  181. } else {
  182. dev_err(&isci_host->pdev->dev, "%s: unkown target\n", __func__);
  183. success = false;
  184. }
  185. isci_phy->sas_phy.phy->negotiated_linkrate = sci_phy_linkrate(phy);
  186. spin_unlock_irqrestore(&isci_phy->sas_phy.frame_rcvd_lock, flags);
  187. /* Notify libsas that we have an address frame, if indeed
  188. * we've found an SSP, SMP, or STP target */
  189. if (success)
  190. isci_host->sas_ha.notify_port_event(&isci_phy->sas_phy,
  191. PORTE_BYTES_DMAED);
  192. }
  193. /**
  194. * isci_port_link_down() - This function is called by the sci core when a link
  195. * becomes inactive.
  196. * @isci_host: This parameter specifies the isci host object.
  197. * @phy: This parameter specifies the isci phy with the active link.
  198. * @port: This parameter specifies the isci port with the active link.
  199. *
  200. */
  201. static void isci_port_link_down(struct isci_host *isci_host,
  202. struct isci_phy *isci_phy,
  203. struct isci_port *isci_port)
  204. {
  205. struct isci_remote_device *isci_device;
  206. dev_dbg(&isci_host->pdev->dev,
  207. "%s: isci_port = %p\n", __func__, isci_port);
  208. if (isci_port) {
  209. /* check to see if this is the last phy on this port. */
  210. if (isci_phy->sas_phy.port
  211. && isci_phy->sas_phy.port->num_phys == 1) {
  212. /* change the state for all devices on this port.
  213. * The next task sent to this device will be returned
  214. * as SAS_TASK_UNDELIVERED, and the scsi mid layer
  215. * will remove the target
  216. */
  217. list_for_each_entry(isci_device,
  218. &isci_port->remote_dev_list,
  219. node) {
  220. dev_dbg(&isci_host->pdev->dev,
  221. "%s: isci_device = %p\n",
  222. __func__, isci_device);
  223. isci_remote_device_change_state(isci_device,
  224. isci_stopping);
  225. }
  226. }
  227. isci_port_change_state(isci_port, isci_stopping);
  228. }
  229. /* Notify libsas of the borken link, this will trigger calls to our
  230. * isci_port_deformed and isci_dev_gone functions.
  231. */
  232. sas_phy_disconnected(&isci_phy->sas_phy);
  233. isci_host->sas_ha.notify_phy_event(&isci_phy->sas_phy,
  234. PHYE_LOSS_OF_SIGNAL);
  235. isci_phy->isci_port = NULL;
  236. dev_dbg(&isci_host->pdev->dev,
  237. "%s: isci_port = %p - Done\n", __func__, isci_port);
  238. }
  239. /**
  240. * isci_port_ready() - This function is called by the sci core when a link
  241. * becomes ready.
  242. * @isci_host: This parameter specifies the isci host object.
  243. * @port: This parameter specifies the sci port with the active link.
  244. *
  245. */
  246. static void isci_port_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  247. {
  248. dev_dbg(&isci_host->pdev->dev,
  249. "%s: isci_port = %p\n", __func__, isci_port);
  250. complete_all(&isci_port->start_complete);
  251. isci_port_change_state(isci_port, isci_ready);
  252. return;
  253. }
  254. /**
  255. * isci_port_not_ready() - This function is called by the sci core when a link
  256. * is not ready. All remote devices on this link will be removed if they are
  257. * in the stopping state.
  258. * @isci_host: This parameter specifies the isci host object.
  259. * @port: This parameter specifies the sci port with the active link.
  260. *
  261. */
  262. static void isci_port_not_ready(struct isci_host *isci_host, struct isci_port *isci_port)
  263. {
  264. dev_dbg(&isci_host->pdev->dev,
  265. "%s: isci_port = %p\n", __func__, isci_port);
  266. }
  267. static void isci_port_stop_complete(struct scic_sds_controller *scic,
  268. struct scic_sds_port *sci_port,
  269. enum sci_status completion_status)
  270. {
  271. dev_dbg(&scic_to_ihost(scic)->pdev->dev, "Port stop complete\n");
  272. }
  273. /**
  274. * isci_port_hard_reset_complete() - This function is called by the sci core
  275. * when the hard reset complete notification has been received.
  276. * @port: This parameter specifies the sci port with the active link.
  277. * @completion_status: This parameter specifies the core status for the reset
  278. * process.
  279. *
  280. */
  281. static void isci_port_hard_reset_complete(struct isci_port *isci_port,
  282. enum sci_status completion_status)
  283. {
  284. dev_dbg(&isci_port->isci_host->pdev->dev,
  285. "%s: isci_port = %p, completion_status=%x\n",
  286. __func__, isci_port, completion_status);
  287. /* Save the status of the hard reset from the port. */
  288. isci_port->hard_reset_status = completion_status;
  289. complete_all(&isci_port->hard_reset_complete);
  290. }
  291. /* This method will return a true value if the specified phy can be assigned to
  292. * this port The following is a list of phys for each port that are allowed: -
  293. * Port 0 - 3 2 1 0 - Port 1 - 1 - Port 2 - 3 2 - Port 3 - 3 This method
  294. * doesn't preclude all configurations. It merely ensures that a phy is part
  295. * of the allowable set of phy identifiers for that port. For example, one
  296. * could assign phy 3 to port 0 and no other phys. Please refer to
  297. * scic_sds_port_is_phy_mask_valid() for information regarding whether the
  298. * phy_mask for a port can be supported. bool true if this is a valid phy
  299. * assignment for the port false if this is not a valid phy assignment for the
  300. * port
  301. */
  302. bool scic_sds_port_is_valid_phy_assignment(struct scic_sds_port *sci_port,
  303. u32 phy_index)
  304. {
  305. /* Initialize to invalid value. */
  306. u32 existing_phy_index = SCI_MAX_PHYS;
  307. u32 index;
  308. if ((sci_port->physical_port_index == 1) && (phy_index != 1)) {
  309. return false;
  310. }
  311. if (sci_port->physical_port_index == 3 && phy_index != 3) {
  312. return false;
  313. }
  314. if (
  315. (sci_port->physical_port_index == 2)
  316. && ((phy_index == 0) || (phy_index == 1))
  317. ) {
  318. return false;
  319. }
  320. for (index = 0; index < SCI_MAX_PHYS; index++) {
  321. if ((sci_port->phy_table[index] != NULL)
  322. && (index != phy_index)) {
  323. existing_phy_index = index;
  324. }
  325. }
  326. /*
  327. * Ensure that all of the phys in the port are capable of
  328. * operating at the same maximum link rate. */
  329. if (
  330. (existing_phy_index < SCI_MAX_PHYS)
  331. && (sci_port->owning_controller->user_parameters.sds1.phys[
  332. phy_index].max_speed_generation !=
  333. sci_port->owning_controller->user_parameters.sds1.phys[
  334. existing_phy_index].max_speed_generation)
  335. )
  336. return false;
  337. return true;
  338. }
  339. /**
  340. *
  341. * @sci_port: This is the port object for which to determine if the phy mask
  342. * can be supported.
  343. *
  344. * This method will return a true value if the port's phy mask can be supported
  345. * by the SCU. The following is a list of valid PHY mask configurations for
  346. * each port: - Port 0 - [[3 2] 1] 0 - Port 1 - [1] - Port 2 - [[3] 2]
  347. * - Port 3 - [3] This method returns a boolean indication specifying if the
  348. * phy mask can be supported. true if this is a valid phy assignment for the
  349. * port false if this is not a valid phy assignment for the port
  350. */
  351. static bool scic_sds_port_is_phy_mask_valid(
  352. struct scic_sds_port *sci_port,
  353. u32 phy_mask)
  354. {
  355. if (sci_port->physical_port_index == 0) {
  356. if (((phy_mask & 0x0F) == 0x0F)
  357. || ((phy_mask & 0x03) == 0x03)
  358. || ((phy_mask & 0x01) == 0x01)
  359. || (phy_mask == 0))
  360. return true;
  361. } else if (sci_port->physical_port_index == 1) {
  362. if (((phy_mask & 0x02) == 0x02)
  363. || (phy_mask == 0))
  364. return true;
  365. } else if (sci_port->physical_port_index == 2) {
  366. if (((phy_mask & 0x0C) == 0x0C)
  367. || ((phy_mask & 0x04) == 0x04)
  368. || (phy_mask == 0))
  369. return true;
  370. } else if (sci_port->physical_port_index == 3) {
  371. if (((phy_mask & 0x08) == 0x08)
  372. || (phy_mask == 0))
  373. return true;
  374. }
  375. return false;
  376. }
  377. /**
  378. *
  379. * @sci_port: This parameter specifies the port from which to return a
  380. * connected phy.
  381. *
  382. * This method retrieves a currently active (i.e. connected) phy contained in
  383. * the port. Currently, the lowest order phy that is connected is returned.
  384. * This method returns a pointer to a SCIS_SDS_PHY object. NULL This value is
  385. * returned if there are no currently active (i.e. connected to a remote end
  386. * point) phys contained in the port. All other values specify a struct scic_sds_phy
  387. * object that is active in the port.
  388. */
  389. static struct scic_sds_phy *scic_sds_port_get_a_connected_phy(
  390. struct scic_sds_port *sci_port
  391. ) {
  392. u32 index;
  393. struct scic_sds_phy *phy;
  394. for (index = 0; index < SCI_MAX_PHYS; index++) {
  395. /*
  396. * Ensure that the phy is both part of the port and currently
  397. * connected to the remote end-point. */
  398. phy = sci_port->phy_table[index];
  399. if (
  400. (phy != NULL)
  401. && scic_sds_port_active_phy(sci_port, phy)
  402. ) {
  403. return phy;
  404. }
  405. }
  406. return NULL;
  407. }
  408. /**
  409. * scic_sds_port_set_phy() -
  410. * @out]: port The port object to which the phy assignement is being made.
  411. * @out]: phy The phy which is being assigned to the port.
  412. *
  413. * This method attempts to make the assignment of the phy to the port. If
  414. * successful the phy is assigned to the ports phy table. bool true if the phy
  415. * assignment can be made. false if the phy assignement can not be made. This
  416. * is a functional test that only fails if the phy is currently assigned to a
  417. * different port.
  418. */
  419. static enum sci_status scic_sds_port_set_phy(
  420. struct scic_sds_port *port,
  421. struct scic_sds_phy *phy)
  422. {
  423. /*
  424. * Check to see if we can add this phy to a port
  425. * that means that the phy is not part of a port and that the port does
  426. * not already have a phy assinged to the phy index. */
  427. if (
  428. (port->phy_table[phy->phy_index] == NULL)
  429. && (phy_get_non_dummy_port(phy) == NULL)
  430. && scic_sds_port_is_valid_phy_assignment(port, phy->phy_index)
  431. ) {
  432. /*
  433. * Phy is being added in the stopped state so we are in MPC mode
  434. * make logical port index = physical port index */
  435. port->logical_port_index = port->physical_port_index;
  436. port->phy_table[phy->phy_index] = phy;
  437. scic_sds_phy_set_port(phy, port);
  438. return SCI_SUCCESS;
  439. }
  440. return SCI_FAILURE;
  441. }
  442. /**
  443. * scic_sds_port_clear_phy() -
  444. * @out]: port The port from which the phy is being cleared.
  445. * @out]: phy The phy being cleared from the port.
  446. *
  447. * This method will clear the phy assigned to this port. This method fails if
  448. * this phy is not currently assinged to this port. bool true if the phy is
  449. * removed from the port. false if this phy is not assined to this port.
  450. */
  451. static enum sci_status scic_sds_port_clear_phy(
  452. struct scic_sds_port *port,
  453. struct scic_sds_phy *phy)
  454. {
  455. /* Make sure that this phy is part of this port */
  456. if (port->phy_table[phy->phy_index] == phy &&
  457. phy_get_non_dummy_port(phy) == port) {
  458. struct scic_sds_controller *scic = port->owning_controller;
  459. struct isci_host *ihost = scic_to_ihost(scic);
  460. /* Yep it is assigned to this port so remove it */
  461. scic_sds_phy_set_port(phy, &ihost->ports[SCI_MAX_PORTS].sci);
  462. port->phy_table[phy->phy_index] = NULL;
  463. return SCI_SUCCESS;
  464. }
  465. return SCI_FAILURE;
  466. }
  467. /**
  468. * This method requests the SAS address for the supplied SAS port from the SCI
  469. * implementation.
  470. * @sci_port: a handle corresponding to the SAS port for which to return the
  471. * SAS address.
  472. * @sas_address: This parameter specifies a pointer to a SAS address structure
  473. * into which the core will copy the SAS address for the port.
  474. *
  475. */
  476. void scic_sds_port_get_sas_address(
  477. struct scic_sds_port *sci_port,
  478. struct sci_sas_address *sas_address)
  479. {
  480. u32 index;
  481. sas_address->high = 0;
  482. sas_address->low = 0;
  483. for (index = 0; index < SCI_MAX_PHYS; index++) {
  484. if (sci_port->phy_table[index] != NULL) {
  485. scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
  486. }
  487. }
  488. }
  489. /*
  490. * This function requests the SAS address for the device directly attached to
  491. * this SAS port.
  492. * @sci_port: a handle corresponding to the SAS port for which to return the
  493. * SAS address.
  494. * @sas_address: This parameter specifies a pointer to a SAS address structure
  495. * into which the core will copy the SAS address for the device directly
  496. * attached to the port.
  497. *
  498. */
  499. void scic_sds_port_get_attached_sas_address(
  500. struct scic_sds_port *sci_port,
  501. struct sci_sas_address *sas_address)
  502. {
  503. struct scic_sds_phy *sci_phy;
  504. /*
  505. * Ensure that the phy is both part of the port and currently
  506. * connected to the remote end-point.
  507. */
  508. sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
  509. if (sci_phy) {
  510. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
  511. scic_sds_phy_get_attached_sas_address(sci_phy,
  512. sas_address);
  513. } else {
  514. scic_sds_phy_get_sas_address(sci_phy, sas_address);
  515. sas_address->low += sci_phy->phy_index;
  516. }
  517. } else {
  518. sas_address->high = 0;
  519. sas_address->low = 0;
  520. }
  521. }
  522. /**
  523. * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
  524. *
  525. * @sci_port: logical port on which we need to create the remote node context
  526. * @rni: remote node index for this remote node context.
  527. *
  528. * This routine will construct a dummy remote node context data structure
  529. * This structure will be posted to the hardware to work around a scheduler
  530. * error in the hardware.
  531. */
  532. static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
  533. {
  534. union scu_remote_node_context *rnc;
  535. rnc = &sci_port->owning_controller->remote_node_context_table[rni];
  536. memset(rnc, 0, sizeof(union scu_remote_node_context));
  537. rnc->ssp.remote_sas_address_hi = 0;
  538. rnc->ssp.remote_sas_address_lo = 0;
  539. rnc->ssp.remote_node_index = rni;
  540. rnc->ssp.remote_node_port_width = 1;
  541. rnc->ssp.logical_port_index = sci_port->physical_port_index;
  542. rnc->ssp.nexus_loss_timer_enable = false;
  543. rnc->ssp.check_bit = false;
  544. rnc->ssp.is_valid = true;
  545. rnc->ssp.is_remote_node_context = true;
  546. rnc->ssp.function_number = 0;
  547. rnc->ssp.arbitration_wait_time = 0;
  548. }
  549. /**
  550. * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
  551. * @sci_port The logical port on which we need to create the
  552. * remote node context.
  553. * context.
  554. * @tci The remote node index for this remote node context.
  555. *
  556. * This routine will construct a dummy task context data structure. This
  557. * structure will be posted to the hardwre to work around a scheduler error
  558. * in the hardware.
  559. *
  560. */
  561. static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
  562. {
  563. struct scu_task_context *task_context;
  564. task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
  565. memset(task_context, 0, sizeof(struct scu_task_context));
  566. task_context->abort = 0;
  567. task_context->priority = 0;
  568. task_context->initiator_request = 1;
  569. task_context->connection_rate = 1;
  570. task_context->protocol_engine_index = 0;
  571. task_context->logical_port_index = sci_port->physical_port_index;
  572. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  573. task_context->task_index = scic_sds_io_tag_get_index(tci);
  574. task_context->valid = SCU_TASK_CONTEXT_VALID;
  575. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  576. task_context->remote_node_index = sci_port->reserved_rni;
  577. task_context->command_code = 0;
  578. task_context->link_layer_control = 0;
  579. task_context->do_not_dma_ssp_good_response = 1;
  580. task_context->strict_ordering = 0;
  581. task_context->control_frame = 0;
  582. task_context->timeout_enable = 0;
  583. task_context->block_guard_enable = 0;
  584. task_context->address_modifier = 0;
  585. task_context->task_phase = 0x01;
  586. }
  587. static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
  588. {
  589. struct scic_sds_controller *scic = sci_port->owning_controller;
  590. if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
  591. scic_controller_free_io_tag(scic, sci_port->reserved_tci);
  592. if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
  593. scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
  594. 1, sci_port->reserved_rni);
  595. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  596. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  597. }
  598. /**
  599. * This method performs initialization of the supplied port. Initialization
  600. * includes: - state machine initialization - member variable initialization
  601. * - configuring the phy_mask
  602. * @sci_port:
  603. * @transport_layer_registers:
  604. * @port_task_scheduler_registers:
  605. * @port_configuration_regsiter:
  606. *
  607. * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
  608. * if the phy being added to the port
  609. */
  610. enum sci_status scic_sds_port_initialize(
  611. struct scic_sds_port *sci_port,
  612. void __iomem *port_task_scheduler_registers,
  613. void __iomem *port_configuration_regsiter,
  614. void __iomem *viit_registers)
  615. {
  616. sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
  617. sci_port->port_pe_configuration_register = port_configuration_regsiter;
  618. sci_port->viit_registers = viit_registers;
  619. return SCI_SUCCESS;
  620. }
  621. /**
  622. * This method assigns the direct attached device ID for this port.
  623. *
  624. * @param[in] sci_port The port for which the direct attached device id is to
  625. * be assigned.
  626. * @param[in] device_id The direct attached device ID to assign to the port.
  627. * This will be the RNi for the device
  628. */
  629. void scic_sds_port_setup_transports(
  630. struct scic_sds_port *sci_port,
  631. u32 device_id)
  632. {
  633. u8 index;
  634. for (index = 0; index < SCI_MAX_PHYS; index++) {
  635. if (sci_port->active_phy_mask & (1 << index))
  636. scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
  637. }
  638. }
  639. /**
  640. *
  641. * @sci_port: This is the port on which the phy should be enabled.
  642. * @sci_phy: This is the specific phy which to enable.
  643. * @do_notify_user: This parameter specifies whether to inform the user (via
  644. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  645. *
  646. * This function will activate the phy in the port.
  647. * Activation includes: - adding
  648. * the phy to the port - enabling the Protocol Engine in the silicon. -
  649. * notifying the user that the link is up. none
  650. */
  651. static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
  652. struct scic_sds_phy *sci_phy,
  653. bool do_notify_user)
  654. {
  655. struct scic_sds_controller *scic = sci_port->owning_controller;
  656. struct isci_host *ihost = scic_to_ihost(scic);
  657. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
  658. scic_sds_phy_resume(sci_phy);
  659. sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
  660. scic_sds_controller_clear_invalid_phy(scic, sci_phy);
  661. if (do_notify_user == true)
  662. isci_port_link_up(ihost, sci_port, sci_phy);
  663. }
  664. void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
  665. struct scic_sds_phy *sci_phy,
  666. bool do_notify_user)
  667. {
  668. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  669. struct isci_port *iport = sci_port_to_iport(sci_port);
  670. struct isci_host *ihost = scic_to_ihost(scic);
  671. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  672. sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
  673. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  674. /* Re-assign the phy back to the LP as if it were a narrow port */
  675. writel(sci_phy->phy_index,
  676. &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
  677. if (do_notify_user == true)
  678. isci_port_link_down(ihost, iphy, iport);
  679. }
  680. /**
  681. *
  682. * @sci_port: This is the port on which the phy should be disabled.
  683. * @sci_phy: This is the specific phy which to disabled.
  684. *
  685. * This function will disable the phy and report that the phy is not valid for
  686. * this port object. None
  687. */
  688. static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
  689. struct scic_sds_phy *sci_phy)
  690. {
  691. struct scic_sds_controller *scic = sci_port->owning_controller;
  692. /*
  693. * Check to see if we have alreay reported this link as bad and if
  694. * not go ahead and tell the SCI_USER that we have discovered an
  695. * invalid link.
  696. */
  697. if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
  698. scic_sds_controller_set_invalid_phy(scic, sci_phy);
  699. dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
  700. }
  701. }
  702. static bool is_port_ready_state(enum scic_sds_port_states state)
  703. {
  704. switch (state) {
  705. case SCI_BASE_PORT_STATE_READY:
  706. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  707. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  708. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  709. return true;
  710. default:
  711. return false;
  712. }
  713. }
  714. /* flag dummy rnc hanling when exiting a ready state */
  715. static void port_state_machine_change(struct scic_sds_port *sci_port,
  716. enum scic_sds_port_states state)
  717. {
  718. struct sci_base_state_machine *sm = &sci_port->state_machine;
  719. enum scic_sds_port_states old_state = sm->current_state_id;
  720. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  721. sci_port->ready_exit = true;
  722. sci_base_state_machine_change_state(sm, state);
  723. sci_port->ready_exit = false;
  724. }
  725. /**
  726. * scic_sds_port_general_link_up_handler - phy can be assigned to port?
  727. * @sci_port: scic_sds_port object for which has a phy that has gone link up.
  728. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  729. * @do_notify_user: This parameter specifies whether to inform the user (via
  730. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  731. *
  732. * Determine if this phy can be assigned to this
  733. * port . If the phy is not a valid PHY for
  734. * this port then the function will notify the user. A PHY can only be
  735. * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
  736. * the same port. none
  737. */
  738. static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
  739. struct scic_sds_phy *sci_phy,
  740. bool do_notify_user)
  741. {
  742. struct sci_sas_address port_sas_address;
  743. struct sci_sas_address phy_sas_address;
  744. scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
  745. scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
  746. /* If the SAS address of the new phy matches the SAS address of
  747. * other phys in the port OR this is the first phy in the port,
  748. * then activate the phy and allow it to be used for operations
  749. * in this port.
  750. */
  751. if ((phy_sas_address.high == port_sas_address.high &&
  752. phy_sas_address.low == port_sas_address.low) ||
  753. sci_port->active_phy_mask == 0) {
  754. struct sci_base_state_machine *sm = &sci_port->state_machine;
  755. scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
  756. if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
  757. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
  758. } else
  759. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  760. }
  761. /**
  762. * This method returns false if the port only has a single phy object assigned.
  763. * If there are no phys or more than one phy then the method will return
  764. * true.
  765. * @sci_port: The port for which the wide port condition is to be checked.
  766. *
  767. * bool true Is returned if this is a wide ported port. false Is returned if
  768. * this is a narrow port.
  769. */
  770. static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
  771. {
  772. u32 index;
  773. u32 phy_count = 0;
  774. for (index = 0; index < SCI_MAX_PHYS; index++) {
  775. if (sci_port->phy_table[index] != NULL) {
  776. phy_count++;
  777. }
  778. }
  779. return phy_count != 1;
  780. }
  781. /**
  782. * This method is called by the PHY object when the link is detected. if the
  783. * port wants the PHY to continue on to the link up state then the port
  784. * layer must return true. If the port object returns false the phy object
  785. * must halt its attempt to go link up.
  786. * @sci_port: The port associated with the phy object.
  787. * @sci_phy: The phy object that is trying to go link up.
  788. *
  789. * true if the phy object can continue to the link up condition. true Is
  790. * returned if this phy can continue to the ready state. false Is returned if
  791. * can not continue on to the ready state. This notification is in place for
  792. * wide ports and direct attached phys. Since there are no wide ported SATA
  793. * devices this could become an invalid port configuration.
  794. */
  795. bool scic_sds_port_link_detected(
  796. struct scic_sds_port *sci_port,
  797. struct scic_sds_phy *sci_phy)
  798. {
  799. if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  800. (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
  801. scic_sds_port_is_wide(sci_port)) {
  802. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  803. return false;
  804. }
  805. return true;
  806. }
  807. /**
  808. * This method is the entry point for the phy to inform the port that it is now
  809. * in a ready state
  810. * @sci_port:
  811. *
  812. *
  813. */
  814. void scic_sds_port_link_up(
  815. struct scic_sds_port *sci_port,
  816. struct scic_sds_phy *sci_phy)
  817. {
  818. sci_phy->is_in_link_training = false;
  819. sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
  820. }
  821. /**
  822. * This method is the entry point for the phy to inform the port that it is no
  823. * longer in a ready state
  824. * @sci_port:
  825. *
  826. *
  827. */
  828. void scic_sds_port_link_down(
  829. struct scic_sds_port *sci_port,
  830. struct scic_sds_phy *sci_phy)
  831. {
  832. sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
  833. }
  834. /**
  835. * This method is called to start an IO request on this port.
  836. * @sci_port:
  837. * @sci_dev:
  838. * @sci_req:
  839. *
  840. * enum sci_status
  841. */
  842. enum sci_status scic_sds_port_start_io(
  843. struct scic_sds_port *sci_port,
  844. struct scic_sds_remote_device *sci_dev,
  845. struct scic_sds_request *sci_req)
  846. {
  847. return sci_port->state_handlers->start_io_handler(
  848. sci_port, sci_dev, sci_req);
  849. }
  850. /**
  851. * This method is called to complete an IO request to the port.
  852. * @sci_port:
  853. * @sci_dev:
  854. * @sci_req:
  855. *
  856. * enum sci_status
  857. */
  858. enum sci_status scic_sds_port_complete_io(
  859. struct scic_sds_port *sci_port,
  860. struct scic_sds_remote_device *sci_dev,
  861. struct scic_sds_request *sci_req)
  862. {
  863. return sci_port->state_handlers->complete_io_handler(
  864. sci_port, sci_dev, sci_req);
  865. }
  866. /**
  867. * This method is provided to timeout requests for port operations. Mostly its
  868. * for the port reset operation.
  869. *
  870. *
  871. */
  872. static void scic_sds_port_timeout_handler(void *port)
  873. {
  874. struct scic_sds_port *sci_port = port;
  875. u32 current_state;
  876. current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
  877. if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
  878. /* if the port is still in the resetting state then the timeout
  879. * fired before the reset completed.
  880. */
  881. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
  882. } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
  883. /* if the port is stopped then the start request failed In this
  884. * case stay in the stopped state.
  885. */
  886. dev_err(sciport_to_dev(sci_port),
  887. "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
  888. __func__,
  889. sci_port);
  890. } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
  891. /* if the port is still stopping then the stop has not completed */
  892. isci_port_stop_complete(sci_port->owning_controller,
  893. sci_port,
  894. SCI_FAILURE_TIMEOUT);
  895. } else {
  896. /* The port is in the ready state and we have a timer
  897. * reporting a timeout this should not happen.
  898. */
  899. dev_err(sciport_to_dev(sci_port),
  900. "%s: SCIC Port 0x%p is processing a timeout operation "
  901. "in state %d.\n", __func__, sci_port, current_state);
  902. }
  903. }
  904. /* --------------------------------------------------------------------------- */
  905. /**
  906. * This function updates the hardwares VIIT entry for this port.
  907. *
  908. *
  909. */
  910. static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
  911. {
  912. struct sci_sas_address sas_address;
  913. scic_sds_port_get_sas_address(sci_port, &sas_address);
  914. writel(sas_address.high,
  915. &sci_port->viit_registers->initiator_sas_address_hi);
  916. writel(sas_address.low,
  917. &sci_port->viit_registers->initiator_sas_address_lo);
  918. /* This value get cleared just in case its not already cleared */
  919. writel(0, &sci_port->viit_registers->reserved);
  920. /* We are required to update the status register last */
  921. writel(SCU_VIIT_ENTRY_ID_VIIT |
  922. SCU_VIIT_IPPT_INITIATOR |
  923. ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  924. SCU_VIIT_STATUS_ALL_VALID,
  925. &sci_port->viit_registers->status);
  926. }
  927. /**
  928. * This method returns the maximum allowed speed for data transfers on this
  929. * port. This maximum allowed speed evaluates to the maximum speed of the
  930. * slowest phy in the port.
  931. * @sci_port: This parameter specifies the port for which to retrieve the
  932. * maximum allowed speed.
  933. *
  934. * This method returns the maximum negotiated speed of the slowest phy in the
  935. * port.
  936. */
  937. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  938. struct scic_sds_port *sci_port)
  939. {
  940. u16 index;
  941. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  942. struct scic_sds_phy *phy = NULL;
  943. /*
  944. * Loop through all of the phys in this port and find the phy with the
  945. * lowest maximum link rate. */
  946. for (index = 0; index < SCI_MAX_PHYS; index++) {
  947. phy = sci_port->phy_table[index];
  948. if (
  949. (phy != NULL)
  950. && (scic_sds_port_active_phy(sci_port, phy) == true)
  951. && (phy->max_negotiated_speed < max_allowed_speed)
  952. )
  953. max_allowed_speed = phy->max_negotiated_speed;
  954. }
  955. return max_allowed_speed;
  956. }
  957. static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
  958. {
  959. struct scic_sds_phy *phy;
  960. u32 register_value;
  961. u8 index;
  962. /* Loop through all of the phys to enable BCN. */
  963. for (index = 0; index < SCI_MAX_PHYS; index++) {
  964. phy = port->phy_table[index];
  965. if (phy != NULL) {
  966. register_value =
  967. readl(&phy->link_layer_registers->link_layer_control);
  968. /* clear the bit by writing 1. */
  969. writel(register_value,
  970. &phy->link_layer_registers->link_layer_control);
  971. }
  972. }
  973. }
  974. /*
  975. * ****************************************************************************
  976. * * READY SUBSTATE HANDLERS
  977. * **************************************************************************** */
  978. /*
  979. * This method is the general ready substate complete io handler for the
  980. * struct scic_sds_port object. This function decrments the outstanding request count
  981. * for this port object. enum sci_status SCI_SUCCESS
  982. */
  983. static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
  984. struct scic_sds_port *port,
  985. struct scic_sds_remote_device *device,
  986. struct scic_sds_request *io_request)
  987. {
  988. scic_sds_port_decrement_request_count(port);
  989. return SCI_SUCCESS;
  990. }
  991. /**
  992. *
  993. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  994. * gone link up.
  995. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  996. *
  997. * This method is the ready waiting substate link up handler for the
  998. * struct scic_sds_port object. This methos will report the link up condition for
  999. * this port and will transition to the ready operational substate. none
  1000. */
  1001. static void scic_sds_port_ready_waiting_substate_link_up_handler(
  1002. struct scic_sds_port *sci_port,
  1003. struct scic_sds_phy *sci_phy)
  1004. {
  1005. /*
  1006. * Since this is the first phy going link up for the port we can just enable
  1007. * it and continue. */
  1008. scic_sds_port_activate_phy(sci_port, sci_phy, true);
  1009. port_state_machine_change(sci_port,
  1010. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1011. }
  1012. /*
  1013. * This method is the ready waiting substate start io handler for the
  1014. * struct scic_sds_port object. The port object can not accept new requests so the
  1015. * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
  1016. */
  1017. static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
  1018. struct scic_sds_port *port,
  1019. struct scic_sds_remote_device *device,
  1020. struct scic_sds_request *io_request)
  1021. {
  1022. return SCI_FAILURE_INVALID_STATE;
  1023. }
  1024. /**
  1025. * scic_sds_port_ready_operational_substate_link_up_handler() -
  1026. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1027. * gone link up.
  1028. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  1029. *
  1030. * This method is the ready operational substate link up handler for the
  1031. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1032. * gone link up. none
  1033. */
  1034. static void scic_sds_port_ready_operational_substate_link_up_handler(
  1035. struct scic_sds_port *sci_port,
  1036. struct scic_sds_phy *sci_phy)
  1037. {
  1038. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1039. }
  1040. /**
  1041. * scic_sds_port_ready_operational_substate_link_down_handler() -
  1042. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1043. * gone link down.
  1044. * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
  1045. *
  1046. * This method is the ready operational substate link down handler for the
  1047. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1048. * gone link down and if this is the last phy in the port the port will change
  1049. * state to the ready waiting substate. none
  1050. */
  1051. static void scic_sds_port_ready_operational_substate_link_down_handler(
  1052. struct scic_sds_port *sci_port,
  1053. struct scic_sds_phy *sci_phy)
  1054. {
  1055. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1056. /*
  1057. * If there are no active phys left in the port, then transition
  1058. * the port to the WAITING state until such time as a phy goes
  1059. * link up. */
  1060. if (sci_port->active_phy_mask == 0)
  1061. port_state_machine_change(sci_port,
  1062. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1063. }
  1064. /*
  1065. * This method is the ready operational substate start io handler for the
  1066. * struct scic_sds_port object. This function incremetns the outstanding request
  1067. * count for this port object. enum sci_status SCI_SUCCESS
  1068. */
  1069. static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
  1070. struct scic_sds_port *port,
  1071. struct scic_sds_remote_device *device,
  1072. struct scic_sds_request *io_request)
  1073. {
  1074. port->started_request_count++;
  1075. return SCI_SUCCESS;
  1076. }
  1077. /**
  1078. * scic_sds_port_ready_configuring_substate_complete_io_handler() -
  1079. * @port: This is the port that is being requested to complete the io request.
  1080. * @device: This is the device on which the io is completing.
  1081. *
  1082. * This method will decrement the outstanding request count for this port. If
  1083. * the request count goes to 0 then the port can be reprogrammed with its new
  1084. * phy data.
  1085. */
  1086. static enum sci_status
  1087. scic_sds_port_ready_configuring_substate_complete_io_handler(
  1088. struct scic_sds_port *port,
  1089. struct scic_sds_remote_device *device,
  1090. struct scic_sds_request *io_request)
  1091. {
  1092. scic_sds_port_decrement_request_count(port);
  1093. if (port->started_request_count == 0) {
  1094. port_state_machine_change(port,
  1095. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1096. }
  1097. return SCI_SUCCESS;
  1098. }
  1099. static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
  1100. const char *func)
  1101. {
  1102. dev_warn(sciport_to_dev(sci_port),
  1103. "%s: in wrong state: %d\n", func,
  1104. sci_base_state_machine_get_state(&sci_port->state_machine));
  1105. return SCI_FAILURE_INVALID_STATE;
  1106. }
  1107. static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
  1108. struct scic_sds_phy *sci_phy)
  1109. {
  1110. default_port_handler(sci_port, __func__);
  1111. }
  1112. static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
  1113. struct scic_sds_phy *sci_phy)
  1114. {
  1115. default_port_handler(sci_port, __func__);
  1116. }
  1117. static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
  1118. struct scic_sds_remote_device *sci_dev,
  1119. struct scic_sds_request *sci_req)
  1120. {
  1121. return default_port_handler(sci_port, __func__);
  1122. }
  1123. static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
  1124. struct scic_sds_remote_device *sci_dev,
  1125. struct scic_sds_request *sci_req)
  1126. {
  1127. return default_port_handler(sci_port, __func__);
  1128. }
  1129. /*
  1130. * ******************************************************************************
  1131. * * PORT STATE PRIVATE METHODS
  1132. * ****************************************************************************** */
  1133. /**
  1134. *
  1135. * @sci_port: This is the struct scic_sds_port object to suspend.
  1136. *
  1137. * This method will susped the port task scheduler for this port object. none
  1138. */
  1139. static void
  1140. scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
  1141. {
  1142. u32 pts_control_value;
  1143. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1144. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  1145. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1146. }
  1147. /**
  1148. * scic_sds_port_post_dummy_request() - post dummy/workaround request
  1149. * @sci_port: port to post task
  1150. *
  1151. * Prevent the hardware scheduler from posting new requests to the front
  1152. * of the scheduler queue causing a starvation problem for currently
  1153. * ongoing requests.
  1154. *
  1155. */
  1156. static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
  1157. {
  1158. u32 command;
  1159. struct scu_task_context *task_context;
  1160. struct scic_sds_controller *scic = sci_port->owning_controller;
  1161. u16 tci = sci_port->reserved_tci;
  1162. task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
  1163. task_context->abort = 0;
  1164. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  1165. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1166. tci;
  1167. scic_sds_controller_post_request(scic, command);
  1168. }
  1169. /**
  1170. * This routine will abort the dummy request. This will alow the hardware to
  1171. * power down parts of the silicon to save power.
  1172. *
  1173. * @sci_port: The port on which the task must be aborted.
  1174. *
  1175. */
  1176. static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
  1177. {
  1178. struct scic_sds_controller *scic = sci_port->owning_controller;
  1179. u16 tci = sci_port->reserved_tci;
  1180. struct scu_task_context *tc;
  1181. u32 command;
  1182. tc = scic_sds_controller_get_task_context_buffer(scic, tci);
  1183. tc->abort = 1;
  1184. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  1185. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1186. tci;
  1187. scic_sds_controller_post_request(scic, command);
  1188. }
  1189. /**
  1190. *
  1191. * @sci_port: This is the struct scic_sds_port object to resume.
  1192. *
  1193. * This method will resume the port task scheduler for this port object. none
  1194. */
  1195. static void
  1196. scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
  1197. {
  1198. u32 pts_control_value;
  1199. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1200. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  1201. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1202. }
  1203. /*
  1204. * ******************************************************************************
  1205. * * PORT READY SUBSTATE METHODS
  1206. * ****************************************************************************** */
  1207. /**
  1208. *
  1209. * @object: This is the object which is cast to a struct scic_sds_port object.
  1210. *
  1211. * This method will perform the actions required by the struct scic_sds_port on
  1212. * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
  1213. * port for any ready phys. If there is at least one phy in a ready state then
  1214. * the port transitions to the ready operational substate. none
  1215. */
  1216. static void scic_sds_port_ready_substate_waiting_enter(void *object)
  1217. {
  1218. struct scic_sds_port *sci_port = object;
  1219. scic_sds_port_set_base_state_handlers(
  1220. sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
  1221. );
  1222. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1223. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  1224. if (sci_port->active_phy_mask != 0) {
  1225. /* At least one of the phys on the port is ready */
  1226. port_state_machine_change(sci_port,
  1227. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1228. }
  1229. }
  1230. /**
  1231. *
  1232. * @object: This is the object which is cast to a struct scic_sds_port object.
  1233. *
  1234. * This function will perform the actions required by the struct scic_sds_port
  1235. * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
  1236. * the state handlers for the port object, notifies the SCI User that the port
  1237. * is ready, and resumes port operations. none
  1238. */
  1239. static void scic_sds_port_ready_substate_operational_enter(void *object)
  1240. {
  1241. u32 index;
  1242. struct scic_sds_port *sci_port = object;
  1243. struct scic_sds_controller *scic = sci_port->owning_controller;
  1244. struct isci_host *ihost = scic_to_ihost(scic);
  1245. struct isci_port *iport = sci_port_to_iport(sci_port);
  1246. scic_sds_port_set_base_state_handlers(
  1247. sci_port,
  1248. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1249. isci_port_ready(ihost, iport);
  1250. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1251. if (sci_port->phy_table[index]) {
  1252. writel(sci_port->physical_port_index,
  1253. &sci_port->port_pe_configuration_register[
  1254. sci_port->phy_table[index]->phy_index]);
  1255. }
  1256. }
  1257. scic_sds_port_update_viit_entry(sci_port);
  1258. scic_sds_port_resume_port_task_scheduler(sci_port);
  1259. /*
  1260. * Post the dummy task for the port so the hardware can schedule
  1261. * io correctly
  1262. */
  1263. scic_sds_port_post_dummy_request(sci_port);
  1264. }
  1265. static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
  1266. {
  1267. struct scic_sds_controller *scic = sci_port->owning_controller;
  1268. u8 phys_index = sci_port->physical_port_index;
  1269. union scu_remote_node_context *rnc;
  1270. u16 rni = sci_port->reserved_rni;
  1271. u32 command;
  1272. rnc = &scic->remote_node_context_table[rni];
  1273. rnc->ssp.is_valid = false;
  1274. /* ensure the preceding tc abort request has reached the
  1275. * controller and give it ample time to act before posting the rnc
  1276. * invalidate
  1277. */
  1278. readl(&scic->smu_registers->interrupt_status); /* flush */
  1279. udelay(10);
  1280. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  1281. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1282. scic_sds_controller_post_request(scic, command);
  1283. }
  1284. /**
  1285. *
  1286. * @object: This is the object which is cast to a struct scic_sds_port object.
  1287. *
  1288. * This method will perform the actions required by the struct scic_sds_port on
  1289. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1290. * the port not ready and suspends the port task scheduler. none
  1291. */
  1292. static void scic_sds_port_ready_substate_operational_exit(void *object)
  1293. {
  1294. struct scic_sds_port *sci_port = object;
  1295. struct scic_sds_controller *scic = sci_port->owning_controller;
  1296. struct isci_host *ihost = scic_to_ihost(scic);
  1297. struct isci_port *iport = sci_port_to_iport(sci_port);
  1298. /*
  1299. * Kill the dummy task for this port if it has not yet posted
  1300. * the hardware will treat this as a NOP and just return abort
  1301. * complete.
  1302. */
  1303. scic_sds_port_abort_dummy_request(sci_port);
  1304. isci_port_not_ready(ihost, iport);
  1305. if (sci_port->ready_exit)
  1306. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1307. }
  1308. /*
  1309. * ******************************************************************************
  1310. * * PORT READY CONFIGURING METHODS
  1311. * ****************************************************************************** */
  1312. /**
  1313. * scic_sds_port_ready_substate_configuring_enter() -
  1314. * @object: This is the object which is cast to a struct scic_sds_port object.
  1315. *
  1316. * This method will perform the actions required by the struct scic_sds_port on
  1317. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1318. * the port not ready and suspends the port task scheduler. none
  1319. */
  1320. static void scic_sds_port_ready_substate_configuring_enter(void *object)
  1321. {
  1322. struct scic_sds_port *sci_port = object;
  1323. struct scic_sds_controller *scic = sci_port->owning_controller;
  1324. struct isci_host *ihost = scic_to_ihost(scic);
  1325. struct isci_port *iport = sci_port_to_iport(sci_port);
  1326. scic_sds_port_set_base_state_handlers(
  1327. sci_port,
  1328. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1329. if (sci_port->active_phy_mask == 0) {
  1330. isci_port_not_ready(ihost, iport);
  1331. port_state_machine_change(sci_port,
  1332. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1333. } else if (sci_port->started_request_count == 0)
  1334. port_state_machine_change(sci_port,
  1335. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1336. }
  1337. static void scic_sds_port_ready_substate_configuring_exit(void *object)
  1338. {
  1339. struct scic_sds_port *sci_port = object;
  1340. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1341. if (sci_port->ready_exit)
  1342. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1343. }
  1344. /* --------------------------------------------------------------------------- */
  1345. /**
  1346. *
  1347. * @port: This is the struct scic_sds_port object on which the io request count will
  1348. * be decremented.
  1349. * @device: This is the struct scic_sds_remote_device object to which the io request
  1350. * is being directed. This parameter is not required to complete this
  1351. * operation.
  1352. * @io_request: This is the request that is being completed on this port
  1353. * object. This parameter is not required to complete this operation.
  1354. *
  1355. * This is a general complete io request handler for the struct scic_sds_port object.
  1356. * enum sci_status SCI_SUCCESS
  1357. */
  1358. static enum sci_status scic_sds_port_general_complete_io_handler(
  1359. struct scic_sds_port *port,
  1360. struct scic_sds_remote_device *device,
  1361. struct scic_sds_request *io_request)
  1362. {
  1363. scic_sds_port_decrement_request_count(port);
  1364. return SCI_SUCCESS;
  1365. }
  1366. /*
  1367. * This method takes the struct scic_sds_port that is in a stopping state and handles
  1368. * the complete io request. Should the request count reach 0 then the port
  1369. * object will transition to the stopped state. enum sci_status SCI_SUCCESS
  1370. */
  1371. static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
  1372. struct scic_sds_port *sci_port,
  1373. struct scic_sds_remote_device *device,
  1374. struct scic_sds_request *io_request)
  1375. {
  1376. scic_sds_port_decrement_request_count(sci_port);
  1377. if (sci_port->started_request_count == 0)
  1378. port_state_machine_change(sci_port,
  1379. SCI_BASE_PORT_STATE_STOPPED);
  1380. return SCI_SUCCESS;
  1381. }
  1382. /*
  1383. * ****************************************************************************
  1384. * * RESETTING STATE HANDLERS
  1385. * **************************************************************************** */
  1386. /*
  1387. * This method will transition a failed port to its ready state. The port
  1388. * failed because a hard reset request timed out but at some time later one or
  1389. * more phys in the port became ready. enum sci_status SCI_SUCCESS
  1390. */
  1391. static void scic_sds_port_reset_state_link_up_handler(
  1392. struct scic_sds_port *port,
  1393. struct scic_sds_phy *phy)
  1394. {
  1395. /*
  1396. * / @todo We should make sure that the phy that has gone link up is the same
  1397. * / one on which we sent the reset. It is possible that the phy on
  1398. * / which we sent the reset is not the one that has gone link up and we
  1399. * / want to make sure that phy being reset comes back. Consider the
  1400. * / case where a reset is sent but before the hardware processes the
  1401. * / reset it get a link up on the port because of a hot plug event.
  1402. * / because of the reset request this phy will go link down almost
  1403. * / immediately. */
  1404. /*
  1405. * In the resetting state we don't notify the user regarding
  1406. * link up and link down notifications. */
  1407. scic_sds_port_general_link_up_handler(port, phy, false);
  1408. }
  1409. /*
  1410. * This method process link down notifications that occur during a port reset
  1411. * operation. Link downs can occur during the reset operation. enum sci_status
  1412. * SCI_SUCCESS
  1413. */
  1414. static void scic_sds_port_reset_state_link_down_handler(
  1415. struct scic_sds_port *port,
  1416. struct scic_sds_phy *phy)
  1417. {
  1418. /*
  1419. * In the resetting state we don't notify the user regarding
  1420. * link up and link down notifications. */
  1421. scic_sds_port_deactivate_phy(port, phy, false);
  1422. }
  1423. enum sci_status scic_sds_port_start(struct scic_sds_port *sci_port)
  1424. {
  1425. struct scic_sds_controller *scic = sci_port->owning_controller;
  1426. struct isci_host *ihost = scic_to_ihost(scic);
  1427. enum sci_status status = SCI_SUCCESS;
  1428. enum scic_sds_port_states state;
  1429. u32 phy_mask;
  1430. state = sci_port->state_machine.current_state_id;
  1431. if (state != SCI_BASE_PORT_STATE_STOPPED) {
  1432. dev_warn(sciport_to_dev(sci_port),
  1433. "%s: in wrong state: %d\n", __func__, state);
  1434. return SCI_FAILURE_INVALID_STATE;
  1435. }
  1436. if (sci_port->assigned_device_count > 0) {
  1437. /* TODO This is a start failure operation because
  1438. * there are still devices assigned to this port.
  1439. * There must be no devices assigned to a port on a
  1440. * start operation.
  1441. */
  1442. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1443. }
  1444. sci_port->timer_handle =
  1445. isci_timer_create(ihost,
  1446. sci_port,
  1447. scic_sds_port_timeout_handler);
  1448. if (!sci_port->timer_handle)
  1449. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1450. if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
  1451. u16 rni = scic_sds_remote_node_table_allocate_remote_node(
  1452. &scic->available_remote_nodes, 1);
  1453. if (rni != SCU_DUMMY_INDEX)
  1454. scic_sds_port_construct_dummy_rnc(sci_port, rni);
  1455. else
  1456. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1457. sci_port->reserved_rni = rni;
  1458. }
  1459. if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
  1460. /* Allocate a TCI and remove the sequence nibble */
  1461. u16 tci = scic_controller_allocate_io_tag(scic);
  1462. if (tci != SCU_DUMMY_INDEX)
  1463. scic_sds_port_construct_dummy_task(sci_port, tci);
  1464. else
  1465. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1466. sci_port->reserved_tci = tci;
  1467. }
  1468. if (status == SCI_SUCCESS) {
  1469. phy_mask = scic_sds_port_get_phys(sci_port);
  1470. /*
  1471. * There are one or more phys assigned to this port. Make sure
  1472. * the port's phy mask is in fact legal and supported by the
  1473. * silicon.
  1474. */
  1475. if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
  1476. port_state_machine_change(sci_port,
  1477. SCI_BASE_PORT_STATE_READY);
  1478. return SCI_SUCCESS;
  1479. }
  1480. status = SCI_FAILURE;
  1481. }
  1482. if (status != SCI_SUCCESS)
  1483. scic_sds_port_destroy_dummy_resources(sci_port);
  1484. return status;
  1485. }
  1486. enum sci_status scic_sds_port_stop(struct scic_sds_port *sci_port)
  1487. {
  1488. enum scic_sds_port_states state;
  1489. state = sci_port->state_machine.current_state_id;
  1490. switch (state) {
  1491. case SCI_BASE_PORT_STATE_STOPPED:
  1492. return SCI_SUCCESS;
  1493. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1494. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1495. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1496. case SCI_BASE_PORT_STATE_RESETTING:
  1497. port_state_machine_change(sci_port,
  1498. SCI_BASE_PORT_STATE_STOPPING);
  1499. return SCI_SUCCESS;
  1500. default:
  1501. dev_warn(sciport_to_dev(sci_port),
  1502. "%s: in wrong state: %d\n", __func__, state);
  1503. return SCI_FAILURE_INVALID_STATE;
  1504. }
  1505. }
  1506. static enum sci_status scic_port_hard_reset(struct scic_sds_port *sci_port, u32 timeout)
  1507. {
  1508. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  1509. struct scic_sds_phy *selected_phy = NULL;
  1510. enum scic_sds_port_states state;
  1511. u32 phy_index;
  1512. state = sci_port->state_machine.current_state_id;
  1513. if (state != SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL) {
  1514. dev_warn(sciport_to_dev(sci_port),
  1515. "%s: in wrong state: %d\n", __func__, state);
  1516. return SCI_FAILURE_INVALID_STATE;
  1517. }
  1518. /* Select a phy on which we can send the hard reset request. */
  1519. for (phy_index = 0; phy_index < SCI_MAX_PHYS && !selected_phy; phy_index++) {
  1520. selected_phy = sci_port->phy_table[phy_index];
  1521. if (selected_phy &&
  1522. !scic_sds_port_active_phy(sci_port, selected_phy)) {
  1523. /*
  1524. * We found a phy but it is not ready select
  1525. * different phy
  1526. */
  1527. selected_phy = NULL;
  1528. }
  1529. }
  1530. /* If we have a phy then go ahead and start the reset procedure */
  1531. if (!selected_phy)
  1532. return status;
  1533. status = scic_sds_phy_reset(selected_phy);
  1534. if (status != SCI_SUCCESS)
  1535. return status;
  1536. isci_timer_start(sci_port->timer_handle, timeout);
  1537. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  1538. port_state_machine_change(sci_port,
  1539. SCI_BASE_PORT_STATE_RESETTING);
  1540. return SCI_SUCCESS;
  1541. }
  1542. /**
  1543. * scic_sds_port_add_phy() -
  1544. * @sci_port: This parameter specifies the port in which the phy will be added.
  1545. * @sci_phy: This parameter is the phy which is to be added to the port.
  1546. *
  1547. * This method will add a PHY to the selected port. This method returns an
  1548. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other
  1549. * status is a failure to add the phy to the port.
  1550. */
  1551. enum sci_status scic_sds_port_add_phy(struct scic_sds_port *sci_port,
  1552. struct scic_sds_phy *sci_phy)
  1553. {
  1554. enum sci_status status;
  1555. enum scic_sds_port_states state;
  1556. state = sci_port->state_machine.current_state_id;
  1557. switch (state) {
  1558. case SCI_BASE_PORT_STATE_STOPPED: {
  1559. struct sci_sas_address port_sas_address;
  1560. /* Read the port assigned SAS Address if there is one */
  1561. scic_sds_port_get_sas_address(sci_port, &port_sas_address);
  1562. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1563. struct sci_sas_address phy_sas_address;
  1564. /* Make sure that the PHY SAS Address matches the SAS Address
  1565. * for this port
  1566. */
  1567. scic_sds_phy_get_sas_address(sci_phy, &phy_sas_address);
  1568. if (port_sas_address.high != phy_sas_address.high ||
  1569. port_sas_address.low != phy_sas_address.low)
  1570. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1571. }
  1572. return scic_sds_port_set_phy(sci_port, sci_phy);
  1573. }
  1574. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  1575. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1576. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1577. if (status != SCI_SUCCESS)
  1578. return status;
  1579. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1580. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1581. port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1582. return status;
  1583. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1584. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1585. if (status != SCI_SUCCESS)
  1586. return status;
  1587. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1588. /* Re-enter the configuring state since this may be the last phy in
  1589. * the port.
  1590. */
  1591. port_state_machine_change(sci_port,
  1592. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1593. return SCI_SUCCESS;
  1594. default:
  1595. dev_warn(sciport_to_dev(sci_port),
  1596. "%s: in wrong state: %d\n", __func__, state);
  1597. return SCI_FAILURE_INVALID_STATE;
  1598. }
  1599. }
  1600. /**
  1601. * scic_sds_port_remove_phy() -
  1602. * @sci_port: This parameter specifies the port in which the phy will be added.
  1603. * @sci_phy: This parameter is the phy which is to be added to the port.
  1604. *
  1605. * This method will remove the PHY from the selected PORT. This method returns
  1606. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any
  1607. * other status is a failure to add the phy to the port.
  1608. */
  1609. enum sci_status scic_sds_port_remove_phy(struct scic_sds_port *sci_port,
  1610. struct scic_sds_phy *sci_phy)
  1611. {
  1612. enum sci_status status;
  1613. enum scic_sds_port_states state;
  1614. state = sci_port->state_machine.current_state_id;
  1615. switch (state) {
  1616. case SCI_BASE_PORT_STATE_STOPPED:
  1617. return scic_sds_port_clear_phy(sci_port, sci_phy);
  1618. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  1619. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1620. if (status != SCI_SUCCESS)
  1621. return status;
  1622. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1623. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1624. port_state_machine_change(sci_port,
  1625. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1626. return SCI_SUCCESS;
  1627. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  1628. status = scic_sds_port_clear_phy(sci_port, sci_phy);
  1629. if (status != SCI_SUCCESS)
  1630. return status;
  1631. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1632. /* Re-enter the configuring state since this may be the last phy in
  1633. * the port
  1634. */
  1635. port_state_machine_change(sci_port,
  1636. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1637. return SCI_SUCCESS;
  1638. default:
  1639. dev_warn(sciport_to_dev(sci_port),
  1640. "%s: in wrong state: %d\n", __func__, state);
  1641. return SCI_FAILURE_INVALID_STATE;
  1642. }
  1643. }
  1644. static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
  1645. [SCI_BASE_PORT_STATE_STOPPED] = {
  1646. .link_up_handler = scic_sds_port_default_link_up_handler,
  1647. .link_down_handler = scic_sds_port_default_link_down_handler,
  1648. .start_io_handler = scic_sds_port_default_start_io_handler,
  1649. .complete_io_handler = scic_sds_port_default_complete_io_handler
  1650. },
  1651. [SCI_BASE_PORT_STATE_STOPPING] = {
  1652. .link_up_handler = scic_sds_port_default_link_up_handler,
  1653. .link_down_handler = scic_sds_port_default_link_down_handler,
  1654. .start_io_handler = scic_sds_port_default_start_io_handler,
  1655. .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
  1656. },
  1657. [SCI_BASE_PORT_STATE_READY] = {
  1658. .link_up_handler = scic_sds_port_default_link_up_handler,
  1659. .link_down_handler = scic_sds_port_default_link_down_handler,
  1660. .start_io_handler = scic_sds_port_default_start_io_handler,
  1661. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1662. },
  1663. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1664. .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
  1665. .link_down_handler = scic_sds_port_default_link_down_handler,
  1666. .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
  1667. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1668. },
  1669. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1670. .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
  1671. .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
  1672. .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
  1673. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1674. },
  1675. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1676. .link_up_handler = scic_sds_port_default_link_up_handler,
  1677. .link_down_handler = scic_sds_port_default_link_down_handler,
  1678. .start_io_handler = scic_sds_port_default_start_io_handler,
  1679. .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
  1680. },
  1681. [SCI_BASE_PORT_STATE_RESETTING] = {
  1682. .link_up_handler = scic_sds_port_reset_state_link_up_handler,
  1683. .link_down_handler = scic_sds_port_reset_state_link_down_handler,
  1684. .start_io_handler = scic_sds_port_default_start_io_handler,
  1685. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1686. },
  1687. [SCI_BASE_PORT_STATE_FAILED] = {
  1688. .link_up_handler = scic_sds_port_default_link_up_handler,
  1689. .link_down_handler = scic_sds_port_default_link_down_handler,
  1690. .start_io_handler = scic_sds_port_default_start_io_handler,
  1691. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1692. }
  1693. };
  1694. /*
  1695. * ******************************************************************************
  1696. * * PORT STATE PRIVATE METHODS
  1697. * ****************************************************************************** */
  1698. /**
  1699. *
  1700. * @sci_port: This is the port object which to suspend.
  1701. *
  1702. * This method will enable the SCU Port Task Scheduler for this port object but
  1703. * will leave the port task scheduler in a suspended state. none
  1704. */
  1705. static void
  1706. scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
  1707. {
  1708. u32 pts_control_value;
  1709. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1710. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1711. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1712. }
  1713. /**
  1714. *
  1715. * @sci_port: This is the port object which to resume.
  1716. *
  1717. * This method will disable the SCU port task scheduler for this port object.
  1718. * none
  1719. */
  1720. static void
  1721. scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
  1722. {
  1723. u32 pts_control_value;
  1724. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1725. pts_control_value &=
  1726. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1727. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1728. }
  1729. static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
  1730. {
  1731. struct scic_sds_controller *scic = sci_port->owning_controller;
  1732. u8 phys_index = sci_port->physical_port_index;
  1733. union scu_remote_node_context *rnc;
  1734. u16 rni = sci_port->reserved_rni;
  1735. u32 command;
  1736. rnc = &scic->remote_node_context_table[rni];
  1737. rnc->ssp.is_valid = true;
  1738. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1739. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1740. scic_sds_controller_post_request(scic, command);
  1741. /* ensure hardware has seen the post rnc command and give it
  1742. * ample time to act before sending the suspend
  1743. */
  1744. readl(&scic->smu_registers->interrupt_status); /* flush */
  1745. udelay(10);
  1746. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1747. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1748. scic_sds_controller_post_request(scic, command);
  1749. }
  1750. /*
  1751. * ******************************************************************************
  1752. * * PORT STATE METHODS
  1753. * ****************************************************************************** */
  1754. /**
  1755. *
  1756. * @object: This is the object which is cast to a struct scic_sds_port object.
  1757. *
  1758. * This method will perform the actions required by the struct scic_sds_port on
  1759. * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
  1760. * state handlers for the struct scic_sds_port object and disables the port task
  1761. * scheduler in the hardware. none
  1762. */
  1763. static void scic_sds_port_stopped_state_enter(void *object)
  1764. {
  1765. struct scic_sds_port *sci_port = object;
  1766. scic_sds_port_set_base_state_handlers(
  1767. sci_port, SCI_BASE_PORT_STATE_STOPPED
  1768. );
  1769. if (
  1770. SCI_BASE_PORT_STATE_STOPPING
  1771. == sci_port->state_machine.previous_state_id
  1772. ) {
  1773. /*
  1774. * If we enter this state becasuse of a request to stop
  1775. * the port then we want to disable the hardwares port
  1776. * task scheduler. */
  1777. scic_sds_port_disable_port_task_scheduler(sci_port);
  1778. }
  1779. }
  1780. /**
  1781. *
  1782. * @object: This is the object which is cast to a struct scic_sds_port object.
  1783. *
  1784. * This method will perform the actions required by the struct scic_sds_port on
  1785. * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
  1786. * port task scheduler. none
  1787. */
  1788. static void scic_sds_port_stopped_state_exit(void *object)
  1789. {
  1790. struct scic_sds_port *sci_port = object;
  1791. /* Enable and suspend the port task scheduler */
  1792. scic_sds_port_enable_port_task_scheduler(sci_port);
  1793. }
  1794. /**
  1795. * scic_sds_port_ready_state_enter -
  1796. * @object: This is the object which is cast to a struct scic_sds_port object.
  1797. *
  1798. * This method will perform the actions required by the struct scic_sds_port on
  1799. * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
  1800. * handlers for the struct scic_sds_port object, reports the port object as
  1801. * not ready and starts the ready substate machine. none
  1802. */
  1803. static void scic_sds_port_ready_state_enter(void *object)
  1804. {
  1805. struct scic_sds_port *sci_port = object;
  1806. struct scic_sds_controller *scic = sci_port->owning_controller;
  1807. struct isci_host *ihost = scic_to_ihost(scic);
  1808. struct isci_port *iport = sci_port_to_iport(sci_port);
  1809. u32 prev_state;
  1810. /* Put the ready state handlers in place though they will not be there long */
  1811. scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
  1812. prev_state = sci_port->state_machine.previous_state_id;
  1813. if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
  1814. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  1815. else
  1816. isci_port_not_ready(ihost, iport);
  1817. /* Post and suspend the dummy remote node context for this port. */
  1818. scic_sds_port_post_dummy_remote_node(sci_port);
  1819. /* Start the ready substate machine */
  1820. port_state_machine_change(sci_port,
  1821. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1822. }
  1823. /**
  1824. *
  1825. * @object: This is the object which is cast to a struct scic_sds_port object.
  1826. *
  1827. * This method will perform the actions required by the struct scic_sds_port on
  1828. * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
  1829. * state handlers for the struct scic_sds_port object. none
  1830. */
  1831. static void scic_sds_port_resetting_state_enter(void *object)
  1832. {
  1833. struct scic_sds_port *sci_port = object;
  1834. scic_sds_port_set_base_state_handlers(
  1835. sci_port, SCI_BASE_PORT_STATE_RESETTING
  1836. );
  1837. }
  1838. /**
  1839. *
  1840. * @object: This is the object which is cast to a struct scic_sds_port object.
  1841. *
  1842. * This function will perform the actions required by the
  1843. * struct scic_sds_port on
  1844. * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
  1845. */
  1846. static inline void scic_sds_port_resetting_state_exit(void *object)
  1847. {
  1848. struct scic_sds_port *sci_port = object;
  1849. isci_timer_stop(sci_port->timer_handle);
  1850. }
  1851. /**
  1852. *
  1853. * @object: This is the void object which is cast to a
  1854. * struct scic_sds_port object.
  1855. *
  1856. * This method will perform the actions required by the struct scic_sds_port on
  1857. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  1858. * state handlers for the struct scic_sds_port object. none
  1859. */
  1860. static void scic_sds_port_stopping_state_enter(void *object)
  1861. {
  1862. struct scic_sds_port *sci_port = object;
  1863. scic_sds_port_set_base_state_handlers(
  1864. sci_port, SCI_BASE_PORT_STATE_STOPPING
  1865. );
  1866. }
  1867. /**
  1868. *
  1869. * @object: This is the object which is cast to a struct scic_sds_port object.
  1870. *
  1871. * This function will perform the actions required by the
  1872. * struct scic_sds_port on
  1873. * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
  1874. */
  1875. static inline void
  1876. scic_sds_port_stopping_state_exit(void *object)
  1877. {
  1878. struct scic_sds_port *sci_port = object;
  1879. isci_timer_stop(sci_port->timer_handle);
  1880. scic_sds_port_destroy_dummy_resources(sci_port);
  1881. }
  1882. /**
  1883. *
  1884. * @object: This is the object which is cast to a struct scic_sds_port object.
  1885. *
  1886. * This function will perform the actions required by the
  1887. * struct scic_sds_port on
  1888. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  1889. * state handlers for the struct scic_sds_port object. none
  1890. */
  1891. static void scic_sds_port_failed_state_enter(void *object)
  1892. {
  1893. struct scic_sds_port *sci_port = object;
  1894. struct isci_port *iport = sci_port_to_iport(sci_port);
  1895. scic_sds_port_set_base_state_handlers(sci_port,
  1896. SCI_BASE_PORT_STATE_FAILED);
  1897. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  1898. }
  1899. /* --------------------------------------------------------------------------- */
  1900. static const struct sci_base_state scic_sds_port_state_table[] = {
  1901. [SCI_BASE_PORT_STATE_STOPPED] = {
  1902. .enter_state = scic_sds_port_stopped_state_enter,
  1903. .exit_state = scic_sds_port_stopped_state_exit
  1904. },
  1905. [SCI_BASE_PORT_STATE_STOPPING] = {
  1906. .enter_state = scic_sds_port_stopping_state_enter,
  1907. .exit_state = scic_sds_port_stopping_state_exit
  1908. },
  1909. [SCI_BASE_PORT_STATE_READY] = {
  1910. .enter_state = scic_sds_port_ready_state_enter,
  1911. },
  1912. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1913. .enter_state = scic_sds_port_ready_substate_waiting_enter,
  1914. },
  1915. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1916. .enter_state = scic_sds_port_ready_substate_operational_enter,
  1917. .exit_state = scic_sds_port_ready_substate_operational_exit
  1918. },
  1919. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1920. .enter_state = scic_sds_port_ready_substate_configuring_enter,
  1921. .exit_state = scic_sds_port_ready_substate_configuring_exit
  1922. },
  1923. [SCI_BASE_PORT_STATE_RESETTING] = {
  1924. .enter_state = scic_sds_port_resetting_state_enter,
  1925. .exit_state = scic_sds_port_resetting_state_exit
  1926. },
  1927. [SCI_BASE_PORT_STATE_FAILED] = {
  1928. .enter_state = scic_sds_port_failed_state_enter,
  1929. }
  1930. };
  1931. void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
  1932. struct scic_sds_controller *scic)
  1933. {
  1934. sci_base_state_machine_construct(&sci_port->state_machine,
  1935. sci_port,
  1936. scic_sds_port_state_table,
  1937. SCI_BASE_PORT_STATE_STOPPED);
  1938. sci_base_state_machine_start(&sci_port->state_machine);
  1939. sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
  1940. sci_port->physical_port_index = index;
  1941. sci_port->active_phy_mask = 0;
  1942. sci_port->ready_exit = false;
  1943. sci_port->owning_controller = scic;
  1944. sci_port->started_request_count = 0;
  1945. sci_port->assigned_device_count = 0;
  1946. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  1947. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  1948. sci_port->timer_handle = NULL;
  1949. sci_port->port_task_scheduler_registers = NULL;
  1950. for (index = 0; index < SCI_MAX_PHYS; index++)
  1951. sci_port->phy_table[index] = NULL;
  1952. }
  1953. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  1954. {
  1955. INIT_LIST_HEAD(&iport->remote_dev_list);
  1956. INIT_LIST_HEAD(&iport->domain_dev_list);
  1957. spin_lock_init(&iport->state_lock);
  1958. init_completion(&iport->start_complete);
  1959. iport->isci_host = ihost;
  1960. isci_port_change_state(iport, isci_freed);
  1961. }
  1962. /**
  1963. * isci_port_get_state() - This function gets the status of the port object.
  1964. * @isci_port: This parameter points to the isci_port object
  1965. *
  1966. * status of the object as a isci_status enum.
  1967. */
  1968. enum isci_status isci_port_get_state(
  1969. struct isci_port *isci_port)
  1970. {
  1971. return isci_port->status;
  1972. }
  1973. static void isci_port_bc_change_received(struct isci_host *ihost,
  1974. struct scic_sds_port *sci_port,
  1975. struct scic_sds_phy *sci_phy)
  1976. {
  1977. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  1978. dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
  1979. __func__, iphy, &iphy->sas_phy);
  1980. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  1981. scic_port_enable_broadcast_change_notification(sci_port);
  1982. }
  1983. void scic_sds_port_broadcast_change_received(
  1984. struct scic_sds_port *sci_port,
  1985. struct scic_sds_phy *sci_phy)
  1986. {
  1987. struct scic_sds_controller *scic = sci_port->owning_controller;
  1988. struct isci_host *ihost = scic_to_ihost(scic);
  1989. /* notify the user. */
  1990. isci_port_bc_change_received(ihost, sci_port, sci_phy);
  1991. }
  1992. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  1993. struct isci_phy *iphy)
  1994. {
  1995. unsigned long flags;
  1996. enum sci_status status;
  1997. int ret = TMF_RESP_FUNC_COMPLETE;
  1998. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  1999. __func__, iport);
  2000. init_completion(&iport->hard_reset_complete);
  2001. spin_lock_irqsave(&ihost->scic_lock, flags);
  2002. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  2003. status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
  2004. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  2005. if (status == SCI_SUCCESS) {
  2006. wait_for_completion(&iport->hard_reset_complete);
  2007. dev_dbg(&ihost->pdev->dev,
  2008. "%s: iport = %p; hard reset completion\n",
  2009. __func__, iport);
  2010. if (iport->hard_reset_status != SCI_SUCCESS)
  2011. ret = TMF_RESP_FUNC_FAILED;
  2012. } else {
  2013. ret = TMF_RESP_FUNC_FAILED;
  2014. dev_err(&ihost->pdev->dev,
  2015. "%s: iport = %p; scic_port_hard_reset call"
  2016. " failed 0x%x\n",
  2017. __func__, iport, status);
  2018. }
  2019. /* If the hard reset for the port has failed, consider this
  2020. * the same as link failures on all phys in the port.
  2021. */
  2022. if (ret != TMF_RESP_FUNC_COMPLETE) {
  2023. dev_err(&ihost->pdev->dev,
  2024. "%s: iport = %p; hard reset failed "
  2025. "(0x%x) - sending link down to libsas for phy %p\n",
  2026. __func__, iport, iport->hard_reset_status, iphy);
  2027. isci_port_link_down(ihost, iphy, iport);
  2028. }
  2029. return ret;
  2030. }
  2031. /**
  2032. * isci_port_deformed() - This function is called by libsas when a port becomes
  2033. * inactive.
  2034. * @phy: This parameter specifies the libsas phy with the inactive port.
  2035. *
  2036. */
  2037. void isci_port_deformed(struct asd_sas_phy *phy)
  2038. {
  2039. pr_debug("%s: sas_phy = %p\n", __func__, phy);
  2040. }
  2041. /**
  2042. * isci_port_formed() - This function is called by libsas when a port becomes
  2043. * active.
  2044. * @phy: This parameter specifies the libsas phy with the active port.
  2045. *
  2046. */
  2047. void isci_port_formed(struct asd_sas_phy *phy)
  2048. {
  2049. pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
  2050. }