port.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652
  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. * scic_sds_port_add_phy() -
  469. * @sci_port: This parameter specifies the port in which the phy will be added.
  470. * @sci_phy: This parameter is the phy which is to be added to the port.
  471. *
  472. * This method will add a PHY to the selected port. This method returns an
  473. * enum sci_status. SCI_SUCCESS the phy has been added to the port. Any other status
  474. * is failre to add the phy to the port.
  475. */
  476. enum sci_status scic_sds_port_add_phy(
  477. struct scic_sds_port *sci_port,
  478. struct scic_sds_phy *sci_phy)
  479. {
  480. return sci_port->state_handlers->add_phy_handler(
  481. sci_port, sci_phy);
  482. }
  483. /**
  484. * scic_sds_port_remove_phy() -
  485. * @sci_port: This parameter specifies the port in which the phy will be added.
  486. * @sci_phy: This parameter is the phy which is to be added to the port.
  487. *
  488. * This method will remove the PHY from the selected PORT. This method returns
  489. * an enum sci_status. SCI_SUCCESS the phy has been removed from the port. Any other
  490. * status is failre to add the phy to the port.
  491. */
  492. enum sci_status scic_sds_port_remove_phy(
  493. struct scic_sds_port *sci_port,
  494. struct scic_sds_phy *sci_phy)
  495. {
  496. return sci_port->state_handlers->remove_phy_handler(
  497. sci_port, sci_phy);
  498. }
  499. /**
  500. * This method requests the SAS address for the supplied SAS port from the SCI
  501. * implementation.
  502. * @sci_port: a handle corresponding to the SAS port for which to return the
  503. * SAS address.
  504. * @sas_address: This parameter specifies a pointer to a SAS address structure
  505. * into which the core will copy the SAS address for the port.
  506. *
  507. */
  508. void scic_sds_port_get_sas_address(
  509. struct scic_sds_port *sci_port,
  510. struct sci_sas_address *sas_address)
  511. {
  512. u32 index;
  513. sas_address->high = 0;
  514. sas_address->low = 0;
  515. for (index = 0; index < SCI_MAX_PHYS; index++) {
  516. if (sci_port->phy_table[index] != NULL) {
  517. scic_sds_phy_get_sas_address(sci_port->phy_table[index], sas_address);
  518. }
  519. }
  520. }
  521. /*
  522. * This function requests the SAS address for the device directly attached to
  523. * this SAS port.
  524. * @sci_port: a handle corresponding to the SAS port for which to return the
  525. * SAS address.
  526. * @sas_address: This parameter specifies a pointer to a SAS address structure
  527. * into which the core will copy the SAS address for the device directly
  528. * attached to the port.
  529. *
  530. */
  531. void scic_sds_port_get_attached_sas_address(
  532. struct scic_sds_port *sci_port,
  533. struct sci_sas_address *sas_address)
  534. {
  535. struct scic_sds_phy *sci_phy;
  536. /*
  537. * Ensure that the phy is both part of the port and currently
  538. * connected to the remote end-point.
  539. */
  540. sci_phy = scic_sds_port_get_a_connected_phy(sci_port);
  541. if (sci_phy) {
  542. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA) {
  543. scic_sds_phy_get_attached_sas_address(sci_phy,
  544. sas_address);
  545. } else {
  546. scic_sds_phy_get_sas_address(sci_phy, sas_address);
  547. sas_address->low += sci_phy->phy_index;
  548. }
  549. } else {
  550. sas_address->high = 0;
  551. sas_address->low = 0;
  552. }
  553. }
  554. /**
  555. * scic_sds_port_construct_dummy_rnc() - create dummy rnc for si workaround
  556. *
  557. * @sci_port: logical port on which we need to create the remote node context
  558. * @rni: remote node index for this remote node context.
  559. *
  560. * This routine will construct a dummy remote node context data structure
  561. * This structure will be posted to the hardware to work around a scheduler
  562. * error in the hardware.
  563. */
  564. static void scic_sds_port_construct_dummy_rnc(struct scic_sds_port *sci_port, u16 rni)
  565. {
  566. union scu_remote_node_context *rnc;
  567. rnc = &sci_port->owning_controller->remote_node_context_table[rni];
  568. memset(rnc, 0, sizeof(union scu_remote_node_context));
  569. rnc->ssp.remote_sas_address_hi = 0;
  570. rnc->ssp.remote_sas_address_lo = 0;
  571. rnc->ssp.remote_node_index = rni;
  572. rnc->ssp.remote_node_port_width = 1;
  573. rnc->ssp.logical_port_index = sci_port->physical_port_index;
  574. rnc->ssp.nexus_loss_timer_enable = false;
  575. rnc->ssp.check_bit = false;
  576. rnc->ssp.is_valid = true;
  577. rnc->ssp.is_remote_node_context = true;
  578. rnc->ssp.function_number = 0;
  579. rnc->ssp.arbitration_wait_time = 0;
  580. }
  581. /**
  582. * scic_sds_port_construct_dummy_task() - create dummy task for si workaround
  583. * @sci_port The logical port on which we need to create the
  584. * remote node context.
  585. * context.
  586. * @tci The remote node index for this remote node context.
  587. *
  588. * This routine will construct a dummy task context data structure. This
  589. * structure will be posted to the hardwre to work around a scheduler error
  590. * in the hardware.
  591. *
  592. */
  593. static void scic_sds_port_construct_dummy_task(struct scic_sds_port *sci_port, u16 tci)
  594. {
  595. struct scu_task_context *task_context;
  596. task_context = scic_sds_controller_get_task_context_buffer(sci_port->owning_controller, tci);
  597. memset(task_context, 0, sizeof(struct scu_task_context));
  598. task_context->abort = 0;
  599. task_context->priority = 0;
  600. task_context->initiator_request = 1;
  601. task_context->connection_rate = 1;
  602. task_context->protocol_engine_index = 0;
  603. task_context->logical_port_index = sci_port->physical_port_index;
  604. task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
  605. task_context->task_index = scic_sds_io_tag_get_index(tci);
  606. task_context->valid = SCU_TASK_CONTEXT_VALID;
  607. task_context->context_type = SCU_TASK_CONTEXT_TYPE;
  608. task_context->remote_node_index = sci_port->reserved_rni;
  609. task_context->command_code = 0;
  610. task_context->link_layer_control = 0;
  611. task_context->do_not_dma_ssp_good_response = 1;
  612. task_context->strict_ordering = 0;
  613. task_context->control_frame = 0;
  614. task_context->timeout_enable = 0;
  615. task_context->block_guard_enable = 0;
  616. task_context->address_modifier = 0;
  617. task_context->task_phase = 0x01;
  618. }
  619. static void scic_sds_port_destroy_dummy_resources(struct scic_sds_port *sci_port)
  620. {
  621. struct scic_sds_controller *scic = sci_port->owning_controller;
  622. if (sci_port->reserved_tci != SCU_DUMMY_INDEX)
  623. scic_controller_free_io_tag(scic, sci_port->reserved_tci);
  624. if (sci_port->reserved_rni != SCU_DUMMY_INDEX)
  625. scic_sds_remote_node_table_release_remote_node_index(&scic->available_remote_nodes,
  626. 1, sci_port->reserved_rni);
  627. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  628. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  629. }
  630. /**
  631. * This method performs initialization of the supplied port. Initialization
  632. * includes: - state machine initialization - member variable initialization
  633. * - configuring the phy_mask
  634. * @sci_port:
  635. * @transport_layer_registers:
  636. * @port_task_scheduler_registers:
  637. * @port_configuration_regsiter:
  638. *
  639. * enum sci_status SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION This value is returned
  640. * if the phy being added to the port
  641. */
  642. enum sci_status scic_sds_port_initialize(
  643. struct scic_sds_port *sci_port,
  644. void __iomem *port_task_scheduler_registers,
  645. void __iomem *port_configuration_regsiter,
  646. void __iomem *viit_registers)
  647. {
  648. sci_port->port_task_scheduler_registers = port_task_scheduler_registers;
  649. sci_port->port_pe_configuration_register = port_configuration_regsiter;
  650. sci_port->viit_registers = viit_registers;
  651. return SCI_SUCCESS;
  652. }
  653. /**
  654. * scic_port_hard_reset() - perform port hard reset
  655. * @port: a handle corresponding to the SAS port to be hard reset.
  656. * @reset_timeout: This parameter specifies the number of milliseconds in which
  657. * the port reset operation should complete.
  658. *
  659. * The SCI User callback in scic_user_callbacks_t will only be called once for
  660. * each phy in the SAS Port at completion of the hard reset sequence. Return a
  661. * status indicating whether the hard reset started successfully. SCI_SUCCESS
  662. * This value is returned if the hard reset operation started successfully.
  663. */
  664. static enum sci_status scic_port_hard_reset(struct scic_sds_port *port,
  665. u32 reset_timeout)
  666. {
  667. return port->state_handlers->reset_handler(
  668. port, reset_timeout);
  669. }
  670. /**
  671. * This method assigns the direct attached device ID for this port.
  672. *
  673. * @param[in] sci_port The port for which the direct attached device id is to
  674. * be assigned.
  675. * @param[in] device_id The direct attached device ID to assign to the port.
  676. * This will be the RNi for the device
  677. */
  678. void scic_sds_port_setup_transports(
  679. struct scic_sds_port *sci_port,
  680. u32 device_id)
  681. {
  682. u8 index;
  683. for (index = 0; index < SCI_MAX_PHYS; index++) {
  684. if (sci_port->active_phy_mask & (1 << index))
  685. scic_sds_phy_setup_transport(sci_port->phy_table[index], device_id);
  686. }
  687. }
  688. /**
  689. *
  690. * @sci_port: This is the port on which the phy should be enabled.
  691. * @sci_phy: This is the specific phy which to enable.
  692. * @do_notify_user: This parameter specifies whether to inform the user (via
  693. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  694. *
  695. * This function will activate the phy in the port.
  696. * Activation includes: - adding
  697. * the phy to the port - enabling the Protocol Engine in the silicon. -
  698. * notifying the user that the link is up. none
  699. */
  700. static void scic_sds_port_activate_phy(struct scic_sds_port *sci_port,
  701. struct scic_sds_phy *sci_phy,
  702. bool do_notify_user)
  703. {
  704. struct scic_sds_controller *scic = sci_port->owning_controller;
  705. struct isci_host *ihost = scic_to_ihost(scic);
  706. if (sci_phy->protocol != SCIC_SDS_PHY_PROTOCOL_SATA)
  707. scic_sds_phy_resume(sci_phy);
  708. sci_port->active_phy_mask |= 1 << sci_phy->phy_index;
  709. scic_sds_controller_clear_invalid_phy(scic, sci_phy);
  710. if (do_notify_user == true)
  711. isci_port_link_up(ihost, sci_port, sci_phy);
  712. }
  713. void scic_sds_port_deactivate_phy(struct scic_sds_port *sci_port,
  714. struct scic_sds_phy *sci_phy,
  715. bool do_notify_user)
  716. {
  717. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  718. struct isci_port *iport = sci_port_to_iport(sci_port);
  719. struct isci_host *ihost = scic_to_ihost(scic);
  720. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  721. sci_port->active_phy_mask &= ~(1 << sci_phy->phy_index);
  722. sci_phy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
  723. /* Re-assign the phy back to the LP as if it were a narrow port */
  724. writel(sci_phy->phy_index,
  725. &sci_port->port_pe_configuration_register[sci_phy->phy_index]);
  726. if (do_notify_user == true)
  727. isci_port_link_down(ihost, iphy, iport);
  728. }
  729. /**
  730. *
  731. * @sci_port: This is the port on which the phy should be disabled.
  732. * @sci_phy: This is the specific phy which to disabled.
  733. *
  734. * This function will disable the phy and report that the phy is not valid for
  735. * this port object. None
  736. */
  737. static void scic_sds_port_invalid_link_up(struct scic_sds_port *sci_port,
  738. struct scic_sds_phy *sci_phy)
  739. {
  740. struct scic_sds_controller *scic = sci_port->owning_controller;
  741. /*
  742. * Check to see if we have alreay reported this link as bad and if
  743. * not go ahead and tell the SCI_USER that we have discovered an
  744. * invalid link.
  745. */
  746. if ((scic->invalid_phy_mask & (1 << sci_phy->phy_index)) == 0) {
  747. scic_sds_controller_set_invalid_phy(scic, sci_phy);
  748. dev_warn(&scic_to_ihost(scic)->pdev->dev, "Invalid link up!\n");
  749. }
  750. }
  751. static bool is_port_ready_state(enum scic_sds_port_states state)
  752. {
  753. switch (state) {
  754. case SCI_BASE_PORT_STATE_READY:
  755. case SCIC_SDS_PORT_READY_SUBSTATE_WAITING:
  756. case SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL:
  757. case SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING:
  758. return true;
  759. default:
  760. return false;
  761. }
  762. }
  763. /* flag dummy rnc hanling when exiting a ready state */
  764. static void port_state_machine_change(struct scic_sds_port *sci_port,
  765. enum scic_sds_port_states state)
  766. {
  767. struct sci_base_state_machine *sm = &sci_port->state_machine;
  768. enum scic_sds_port_states old_state = sm->current_state_id;
  769. if (is_port_ready_state(old_state) && !is_port_ready_state(state))
  770. sci_port->ready_exit = true;
  771. sci_base_state_machine_change_state(sm, state);
  772. sci_port->ready_exit = false;
  773. }
  774. static void port_state_machine_stop(struct scic_sds_port *sci_port)
  775. {
  776. sci_port->ready_exit = true;
  777. sci_base_state_machine_stop(&sci_port->state_machine);
  778. sci_port->ready_exit = false;
  779. }
  780. /**
  781. * scic_sds_port_general_link_up_handler - phy can be assigned to port?
  782. * @sci_port: scic_sds_port object for which has a phy that has gone link up.
  783. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  784. * @do_notify_user: This parameter specifies whether to inform the user (via
  785. * scic_cb_port_link_up()) as to the fact that a new phy as become ready.
  786. *
  787. * Determine if this phy can be assigned to this
  788. * port . If the phy is not a valid PHY for
  789. * this port then the function will notify the user. A PHY can only be
  790. * part of a port if it's attached SAS ADDRESS is the same as all other PHYs in
  791. * the same port. none
  792. */
  793. static void scic_sds_port_general_link_up_handler(struct scic_sds_port *sci_port,
  794. struct scic_sds_phy *sci_phy,
  795. bool do_notify_user)
  796. {
  797. struct sci_sas_address port_sas_address;
  798. struct sci_sas_address phy_sas_address;
  799. scic_sds_port_get_attached_sas_address(sci_port, &port_sas_address);
  800. scic_sds_phy_get_attached_sas_address(sci_phy, &phy_sas_address);
  801. /* If the SAS address of the new phy matches the SAS address of
  802. * other phys in the port OR this is the first phy in the port,
  803. * then activate the phy and allow it to be used for operations
  804. * in this port.
  805. */
  806. if ((phy_sas_address.high == port_sas_address.high &&
  807. phy_sas_address.low == port_sas_address.low) ||
  808. sci_port->active_phy_mask == 0) {
  809. struct sci_base_state_machine *sm = &sci_port->state_machine;
  810. scic_sds_port_activate_phy(sci_port, sci_phy, do_notify_user);
  811. if (sm->current_state_id == SCI_BASE_PORT_STATE_RESETTING)
  812. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_READY);
  813. } else
  814. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  815. }
  816. /**
  817. * This method returns false if the port only has a single phy object assigned.
  818. * If there are no phys or more than one phy then the method will return
  819. * true.
  820. * @sci_port: The port for which the wide port condition is to be checked.
  821. *
  822. * bool true Is returned if this is a wide ported port. false Is returned if
  823. * this is a narrow port.
  824. */
  825. static bool scic_sds_port_is_wide(struct scic_sds_port *sci_port)
  826. {
  827. u32 index;
  828. u32 phy_count = 0;
  829. for (index = 0; index < SCI_MAX_PHYS; index++) {
  830. if (sci_port->phy_table[index] != NULL) {
  831. phy_count++;
  832. }
  833. }
  834. return phy_count != 1;
  835. }
  836. /**
  837. * This method is called by the PHY object when the link is detected. if the
  838. * port wants the PHY to continue on to the link up state then the port
  839. * layer must return true. If the port object returns false the phy object
  840. * must halt its attempt to go link up.
  841. * @sci_port: The port associated with the phy object.
  842. * @sci_phy: The phy object that is trying to go link up.
  843. *
  844. * true if the phy object can continue to the link up condition. true Is
  845. * returned if this phy can continue to the ready state. false Is returned if
  846. * can not continue on to the ready state. This notification is in place for
  847. * wide ports and direct attached phys. Since there are no wide ported SATA
  848. * devices this could become an invalid port configuration.
  849. */
  850. bool scic_sds_port_link_detected(
  851. struct scic_sds_port *sci_port,
  852. struct scic_sds_phy *sci_phy)
  853. {
  854. if ((sci_port->logical_port_index != SCIC_SDS_DUMMY_PORT) &&
  855. (sci_phy->protocol == SCIC_SDS_PHY_PROTOCOL_SATA) &&
  856. scic_sds_port_is_wide(sci_port)) {
  857. scic_sds_port_invalid_link_up(sci_port, sci_phy);
  858. return false;
  859. }
  860. return true;
  861. }
  862. /**
  863. * This method is the entry point for the phy to inform the port that it is now
  864. * in a ready state
  865. * @sci_port:
  866. *
  867. *
  868. */
  869. void scic_sds_port_link_up(
  870. struct scic_sds_port *sci_port,
  871. struct scic_sds_phy *sci_phy)
  872. {
  873. sci_phy->is_in_link_training = false;
  874. sci_port->state_handlers->link_up_handler(sci_port, sci_phy);
  875. }
  876. /**
  877. * This method is the entry point for the phy to inform the port that it is no
  878. * longer in a ready state
  879. * @sci_port:
  880. *
  881. *
  882. */
  883. void scic_sds_port_link_down(
  884. struct scic_sds_port *sci_port,
  885. struct scic_sds_phy *sci_phy)
  886. {
  887. sci_port->state_handlers->link_down_handler(sci_port, sci_phy);
  888. }
  889. /**
  890. * This method is called to start an IO request on this port.
  891. * @sci_port:
  892. * @sci_dev:
  893. * @sci_req:
  894. *
  895. * enum sci_status
  896. */
  897. enum sci_status scic_sds_port_start_io(
  898. struct scic_sds_port *sci_port,
  899. struct scic_sds_remote_device *sci_dev,
  900. struct scic_sds_request *sci_req)
  901. {
  902. return sci_port->state_handlers->start_io_handler(
  903. sci_port, sci_dev, sci_req);
  904. }
  905. /**
  906. * This method is called to complete an IO request to the port.
  907. * @sci_port:
  908. * @sci_dev:
  909. * @sci_req:
  910. *
  911. * enum sci_status
  912. */
  913. enum sci_status scic_sds_port_complete_io(
  914. struct scic_sds_port *sci_port,
  915. struct scic_sds_remote_device *sci_dev,
  916. struct scic_sds_request *sci_req)
  917. {
  918. return sci_port->state_handlers->complete_io_handler(
  919. sci_port, sci_dev, sci_req);
  920. }
  921. /**
  922. * This method is provided to timeout requests for port operations. Mostly its
  923. * for the port reset operation.
  924. *
  925. *
  926. */
  927. static void scic_sds_port_timeout_handler(void *port)
  928. {
  929. struct scic_sds_port *sci_port = port;
  930. u32 current_state;
  931. current_state = sci_base_state_machine_get_state(&sci_port->state_machine);
  932. if (current_state == SCI_BASE_PORT_STATE_RESETTING) {
  933. /* if the port is still in the resetting state then the timeout
  934. * fired before the reset completed.
  935. */
  936. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_FAILED);
  937. } else if (current_state == SCI_BASE_PORT_STATE_STOPPED) {
  938. /* if the port is stopped then the start request failed In this
  939. * case stay in the stopped state.
  940. */
  941. dev_err(sciport_to_dev(sci_port),
  942. "%s: SCIC Port 0x%p failed to stop before tiemout.\n",
  943. __func__,
  944. sci_port);
  945. } else if (current_state == SCI_BASE_PORT_STATE_STOPPING) {
  946. /* if the port is still stopping then the stop has not completed */
  947. isci_port_stop_complete(sci_port->owning_controller,
  948. sci_port,
  949. SCI_FAILURE_TIMEOUT);
  950. } else {
  951. /* The port is in the ready state and we have a timer
  952. * reporting a timeout this should not happen.
  953. */
  954. dev_err(sciport_to_dev(sci_port),
  955. "%s: SCIC Port 0x%p is processing a timeout operation "
  956. "in state %d.\n", __func__, sci_port, current_state);
  957. }
  958. }
  959. /* --------------------------------------------------------------------------- */
  960. /**
  961. * This function updates the hardwares VIIT entry for this port.
  962. *
  963. *
  964. */
  965. static void scic_sds_port_update_viit_entry(struct scic_sds_port *sci_port)
  966. {
  967. struct sci_sas_address sas_address;
  968. scic_sds_port_get_sas_address(sci_port, &sas_address);
  969. writel(sas_address.high,
  970. &sci_port->viit_registers->initiator_sas_address_hi);
  971. writel(sas_address.low,
  972. &sci_port->viit_registers->initiator_sas_address_lo);
  973. /* This value get cleared just in case its not already cleared */
  974. writel(0, &sci_port->viit_registers->reserved);
  975. /* We are required to update the status register last */
  976. writel(SCU_VIIT_ENTRY_ID_VIIT |
  977. SCU_VIIT_IPPT_INITIATOR |
  978. ((1 << sci_port->physical_port_index) << SCU_VIIT_ENTRY_LPVIE_SHIFT) |
  979. SCU_VIIT_STATUS_ALL_VALID,
  980. &sci_port->viit_registers->status);
  981. }
  982. /**
  983. * This method returns the maximum allowed speed for data transfers on this
  984. * port. This maximum allowed speed evaluates to the maximum speed of the
  985. * slowest phy in the port.
  986. * @sci_port: This parameter specifies the port for which to retrieve the
  987. * maximum allowed speed.
  988. *
  989. * This method returns the maximum negotiated speed of the slowest phy in the
  990. * port.
  991. */
  992. enum sas_linkrate scic_sds_port_get_max_allowed_speed(
  993. struct scic_sds_port *sci_port)
  994. {
  995. u16 index;
  996. enum sas_linkrate max_allowed_speed = SAS_LINK_RATE_6_0_GBPS;
  997. struct scic_sds_phy *phy = NULL;
  998. /*
  999. * Loop through all of the phys in this port and find the phy with the
  1000. * lowest maximum link rate. */
  1001. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1002. phy = sci_port->phy_table[index];
  1003. if (
  1004. (phy != NULL)
  1005. && (scic_sds_port_active_phy(sci_port, phy) == true)
  1006. && (phy->max_negotiated_speed < max_allowed_speed)
  1007. )
  1008. max_allowed_speed = phy->max_negotiated_speed;
  1009. }
  1010. return max_allowed_speed;
  1011. }
  1012. static void scic_port_enable_broadcast_change_notification(struct scic_sds_port *port)
  1013. {
  1014. struct scic_sds_phy *phy;
  1015. u32 register_value;
  1016. u8 index;
  1017. /* Loop through all of the phys to enable BCN. */
  1018. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1019. phy = port->phy_table[index];
  1020. if (phy != NULL) {
  1021. register_value =
  1022. readl(&phy->link_layer_registers->link_layer_control);
  1023. /* clear the bit by writing 1. */
  1024. writel(register_value,
  1025. &phy->link_layer_registers->link_layer_control);
  1026. }
  1027. }
  1028. }
  1029. /*
  1030. * ****************************************************************************
  1031. * * READY SUBSTATE HANDLERS
  1032. * **************************************************************************** */
  1033. /*
  1034. * This method is the general ready state stop handler for the struct scic_sds_port
  1035. * object. This function will transition the ready substate machine to its
  1036. * final state. enum sci_status SCI_SUCCESS
  1037. */
  1038. static enum sci_status scic_sds_port_ready_substate_stop_handler(struct scic_sds_port *sci_port)
  1039. {
  1040. port_state_machine_change(sci_port, SCI_BASE_PORT_STATE_STOPPING);
  1041. return SCI_SUCCESS;
  1042. }
  1043. /*
  1044. * This method is the general ready substate complete io handler for the
  1045. * struct scic_sds_port object. This function decrments the outstanding request count
  1046. * for this port object. enum sci_status SCI_SUCCESS
  1047. */
  1048. static enum sci_status scic_sds_port_ready_substate_complete_io_handler(
  1049. struct scic_sds_port *port,
  1050. struct scic_sds_remote_device *device,
  1051. struct scic_sds_request *io_request)
  1052. {
  1053. scic_sds_port_decrement_request_count(port);
  1054. return SCI_SUCCESS;
  1055. }
  1056. static enum sci_status scic_sds_port_ready_substate_add_phy_handler(struct scic_sds_port *sci_port,
  1057. struct scic_sds_phy *sci_phy)
  1058. {
  1059. enum sci_status status;
  1060. status = scic_sds_port_set_phy(sci_port, sci_phy);
  1061. if (status != SCI_SUCCESS)
  1062. return status;
  1063. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1064. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1065. port_state_machine_change(sci_port, SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1066. return status;
  1067. }
  1068. static enum sci_status scic_sds_port_ready_substate_remove_phy_handler(struct scic_sds_port *port,
  1069. struct scic_sds_phy *phy)
  1070. {
  1071. enum sci_status status;
  1072. status = scic_sds_port_clear_phy(port, phy);
  1073. if (status != SCI_SUCCESS)
  1074. return status;
  1075. scic_sds_port_deactivate_phy(port, phy, true);
  1076. port->not_ready_reason = SCIC_PORT_NOT_READY_RECONFIGURING;
  1077. port_state_machine_change(port,
  1078. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1079. return status;
  1080. }
  1081. /*
  1082. * ****************************************************************************
  1083. * * READY SUBSTATE WAITING HANDLERS
  1084. * **************************************************************************** */
  1085. /**
  1086. *
  1087. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1088. * gone link up.
  1089. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  1090. *
  1091. * This method is the ready waiting substate link up handler for the
  1092. * struct scic_sds_port object. This methos will report the link up condition for
  1093. * this port and will transition to the ready operational substate. none
  1094. */
  1095. static void scic_sds_port_ready_waiting_substate_link_up_handler(
  1096. struct scic_sds_port *sci_port,
  1097. struct scic_sds_phy *sci_phy)
  1098. {
  1099. /*
  1100. * Since this is the first phy going link up for the port we can just enable
  1101. * it and continue. */
  1102. scic_sds_port_activate_phy(sci_port, sci_phy, true);
  1103. port_state_machine_change(sci_port,
  1104. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1105. }
  1106. /*
  1107. * This method is the ready waiting substate start io handler for the
  1108. * struct scic_sds_port object. The port object can not accept new requests so the
  1109. * request is failed. enum sci_status SCI_FAILURE_INVALID_STATE
  1110. */
  1111. static enum sci_status scic_sds_port_ready_waiting_substate_start_io_handler(
  1112. struct scic_sds_port *port,
  1113. struct scic_sds_remote_device *device,
  1114. struct scic_sds_request *io_request)
  1115. {
  1116. return SCI_FAILURE_INVALID_STATE;
  1117. }
  1118. /*
  1119. * ****************************************************************************
  1120. * * READY SUBSTATE OPERATIONAL HANDLERS
  1121. * **************************************************************************** */
  1122. /*
  1123. * This method will casue the port to reset. enum sci_status SCI_SUCCESS
  1124. */
  1125. static enum
  1126. sci_status scic_sds_port_ready_operational_substate_reset_handler(
  1127. struct scic_sds_port *port,
  1128. u32 timeout)
  1129. {
  1130. enum sci_status status = SCI_FAILURE_INVALID_PHY;
  1131. u32 phy_index;
  1132. struct scic_sds_phy *selected_phy = NULL;
  1133. /* Select a phy on which we can send the hard reset request. */
  1134. for (phy_index = 0;
  1135. (phy_index < SCI_MAX_PHYS) && (selected_phy == NULL);
  1136. phy_index++) {
  1137. selected_phy = port->phy_table[phy_index];
  1138. if ((selected_phy != NULL) &&
  1139. !scic_sds_port_active_phy(port, selected_phy)) {
  1140. /*
  1141. * We found a phy but it is not ready select
  1142. * different phy
  1143. */
  1144. selected_phy = NULL;
  1145. }
  1146. }
  1147. /* If we have a phy then go ahead and start the reset procedure */
  1148. if (selected_phy != NULL) {
  1149. status = scic_sds_phy_reset(selected_phy);
  1150. if (status == SCI_SUCCESS) {
  1151. isci_timer_start(port->timer_handle, timeout);
  1152. port->not_ready_reason =
  1153. SCIC_PORT_NOT_READY_HARD_RESET_REQUESTED;
  1154. port_state_machine_change(port,
  1155. SCI_BASE_PORT_STATE_RESETTING);
  1156. }
  1157. }
  1158. return status;
  1159. }
  1160. /**
  1161. * scic_sds_port_ready_operational_substate_link_up_handler() -
  1162. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1163. * gone link up.
  1164. * @sci_phy: This is the struct scic_sds_phy object that has gone link up.
  1165. *
  1166. * This method is the ready operational substate link up handler for the
  1167. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1168. * gone link up. none
  1169. */
  1170. static void scic_sds_port_ready_operational_substate_link_up_handler(
  1171. struct scic_sds_port *sci_port,
  1172. struct scic_sds_phy *sci_phy)
  1173. {
  1174. scic_sds_port_general_link_up_handler(sci_port, sci_phy, true);
  1175. }
  1176. /**
  1177. * scic_sds_port_ready_operational_substate_link_down_handler() -
  1178. * @sci_port: This is the struct scic_sds_port object that which has a phy that has
  1179. * gone link down.
  1180. * @sci_phy: This is the struct scic_sds_phy object that has gone link down.
  1181. *
  1182. * This method is the ready operational substate link down handler for the
  1183. * struct scic_sds_port object. This function notifies the SCI User that the phy has
  1184. * gone link down and if this is the last phy in the port the port will change
  1185. * state to the ready waiting substate. none
  1186. */
  1187. static void scic_sds_port_ready_operational_substate_link_down_handler(
  1188. struct scic_sds_port *sci_port,
  1189. struct scic_sds_phy *sci_phy)
  1190. {
  1191. scic_sds_port_deactivate_phy(sci_port, sci_phy, true);
  1192. /*
  1193. * If there are no active phys left in the port, then transition
  1194. * the port to the WAITING state until such time as a phy goes
  1195. * link up. */
  1196. if (sci_port->active_phy_mask == 0)
  1197. port_state_machine_change(sci_port,
  1198. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1199. }
  1200. /*
  1201. * This method is the ready operational substate start io handler for the
  1202. * struct scic_sds_port object. This function incremetns the outstanding request
  1203. * count for this port object. enum sci_status SCI_SUCCESS
  1204. */
  1205. static enum sci_status scic_sds_port_ready_operational_substate_start_io_handler(
  1206. struct scic_sds_port *port,
  1207. struct scic_sds_remote_device *device,
  1208. struct scic_sds_request *io_request)
  1209. {
  1210. port->started_request_count++;
  1211. return SCI_SUCCESS;
  1212. }
  1213. /*
  1214. * ****************************************************************************
  1215. * * READY SUBSTATE OPERATIONAL HANDLERS
  1216. * **************************************************************************** */
  1217. /*
  1218. * This is the default method for a port add phy request. It will report a
  1219. * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
  1220. */
  1221. static enum sci_status scic_sds_port_ready_configuring_substate_add_phy_handler(
  1222. struct scic_sds_port *port,
  1223. struct scic_sds_phy *phy)
  1224. {
  1225. enum sci_status status;
  1226. status = scic_sds_port_set_phy(port, phy);
  1227. if (status == SCI_SUCCESS) {
  1228. scic_sds_port_general_link_up_handler(port, phy, true);
  1229. /*
  1230. * Re-enter the configuring state since this may be the last phy in
  1231. * the port. */
  1232. port_state_machine_change(port,
  1233. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1234. }
  1235. return status;
  1236. }
  1237. /*
  1238. * This is the default method for a port remove phy request. It will report a
  1239. * warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE
  1240. */
  1241. static enum sci_status scic_sds_port_ready_configuring_substate_remove_phy_handler(
  1242. struct scic_sds_port *port,
  1243. struct scic_sds_phy *phy)
  1244. {
  1245. enum sci_status status;
  1246. status = scic_sds_port_clear_phy(port, phy);
  1247. if (status != SCI_SUCCESS)
  1248. return status;
  1249. scic_sds_port_deactivate_phy(port, phy, true);
  1250. /* Re-enter the configuring state since this may be the last phy in
  1251. * the port
  1252. */
  1253. port_state_machine_change(port,
  1254. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1255. return status;
  1256. }
  1257. /**
  1258. * scic_sds_port_ready_configuring_substate_complete_io_handler() -
  1259. * @port: This is the port that is being requested to complete the io request.
  1260. * @device: This is the device on which the io is completing.
  1261. *
  1262. * This method will decrement the outstanding request count for this port. If
  1263. * the request count goes to 0 then the port can be reprogrammed with its new
  1264. * phy data.
  1265. */
  1266. static enum sci_status
  1267. scic_sds_port_ready_configuring_substate_complete_io_handler(
  1268. struct scic_sds_port *port,
  1269. struct scic_sds_remote_device *device,
  1270. struct scic_sds_request *io_request)
  1271. {
  1272. scic_sds_port_decrement_request_count(port);
  1273. if (port->started_request_count == 0) {
  1274. port_state_machine_change(port,
  1275. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1276. }
  1277. return SCI_SUCCESS;
  1278. }
  1279. static enum sci_status default_port_handler(struct scic_sds_port *sci_port,
  1280. const char *func)
  1281. {
  1282. dev_warn(sciport_to_dev(sci_port),
  1283. "%s: in wrong state: %d\n", func,
  1284. sci_base_state_machine_get_state(&sci_port->state_machine));
  1285. return SCI_FAILURE_INVALID_STATE;
  1286. }
  1287. static enum sci_status
  1288. scic_sds_port_default_start_handler(struct scic_sds_port *sci_port)
  1289. {
  1290. return default_port_handler(sci_port, __func__);
  1291. }
  1292. static enum sci_status
  1293. scic_sds_port_default_stop_handler(struct scic_sds_port *sci_port)
  1294. {
  1295. return default_port_handler(sci_port, __func__);
  1296. }
  1297. static enum sci_status
  1298. scic_sds_port_default_destruct_handler(struct scic_sds_port *sci_port)
  1299. {
  1300. return default_port_handler(sci_port, __func__);
  1301. }
  1302. static enum sci_status
  1303. scic_sds_port_default_reset_handler(struct scic_sds_port *sci_port,
  1304. u32 timeout)
  1305. {
  1306. return default_port_handler(sci_port, __func__);
  1307. }
  1308. static enum sci_status
  1309. scic_sds_port_default_add_phy_handler(struct scic_sds_port *sci_port,
  1310. struct scic_sds_phy *base_phy)
  1311. {
  1312. return default_port_handler(sci_port, __func__);
  1313. }
  1314. static enum sci_status
  1315. scic_sds_port_default_remove_phy_handler(struct scic_sds_port *sci_port,
  1316. struct scic_sds_phy *base_phy)
  1317. {
  1318. return default_port_handler(sci_port, __func__);
  1319. }
  1320. /*
  1321. * This is the default method for a port unsolicited frame request. It will
  1322. * report a warning and exit. enum sci_status SCI_FAILURE_INVALID_STATE Is it even
  1323. * possible to receive an unsolicited frame directed to a port object? It
  1324. * seems possible if we implementing virtual functions but until then?
  1325. */
  1326. static enum sci_status
  1327. scic_sds_port_default_frame_handler(struct scic_sds_port *sci_port,
  1328. u32 frame_index)
  1329. {
  1330. struct scic_sds_controller *scic = scic_sds_port_get_controller(sci_port);
  1331. default_port_handler(sci_port, __func__);
  1332. scic_sds_controller_release_frame(scic, frame_index);
  1333. return SCI_FAILURE_INVALID_STATE;
  1334. }
  1335. static enum sci_status scic_sds_port_default_event_handler(struct scic_sds_port *sci_port,
  1336. u32 event_code)
  1337. {
  1338. return default_port_handler(sci_port, __func__);
  1339. }
  1340. static void scic_sds_port_default_link_up_handler(struct scic_sds_port *sci_port,
  1341. struct scic_sds_phy *sci_phy)
  1342. {
  1343. default_port_handler(sci_port, __func__);
  1344. }
  1345. static void scic_sds_port_default_link_down_handler(struct scic_sds_port *sci_port,
  1346. struct scic_sds_phy *sci_phy)
  1347. {
  1348. default_port_handler(sci_port, __func__);
  1349. }
  1350. static enum sci_status scic_sds_port_default_start_io_handler(struct scic_sds_port *sci_port,
  1351. struct scic_sds_remote_device *sci_dev,
  1352. struct scic_sds_request *sci_req)
  1353. {
  1354. return default_port_handler(sci_port, __func__);
  1355. }
  1356. static enum sci_status scic_sds_port_default_complete_io_handler(struct scic_sds_port *sci_port,
  1357. struct scic_sds_remote_device *sci_dev,
  1358. struct scic_sds_request *sci_req)
  1359. {
  1360. return default_port_handler(sci_port, __func__);
  1361. }
  1362. /*
  1363. * ******************************************************************************
  1364. * * PORT STATE PRIVATE METHODS
  1365. * ****************************************************************************** */
  1366. /**
  1367. *
  1368. * @sci_port: This is the struct scic_sds_port object to suspend.
  1369. *
  1370. * This method will susped the port task scheduler for this port object. none
  1371. */
  1372. static void
  1373. scic_sds_port_suspend_port_task_scheduler(struct scic_sds_port *port)
  1374. {
  1375. u32 pts_control_value;
  1376. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1377. pts_control_value |= SCU_PTSxCR_GEN_BIT(SUSPEND);
  1378. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1379. }
  1380. /**
  1381. * scic_sds_port_post_dummy_request() - post dummy/workaround request
  1382. * @sci_port: port to post task
  1383. *
  1384. * Prevent the hardware scheduler from posting new requests to the front
  1385. * of the scheduler queue causing a starvation problem for currently
  1386. * ongoing requests.
  1387. *
  1388. */
  1389. static void scic_sds_port_post_dummy_request(struct scic_sds_port *sci_port)
  1390. {
  1391. u32 command;
  1392. struct scu_task_context *task_context;
  1393. struct scic_sds_controller *scic = sci_port->owning_controller;
  1394. u16 tci = sci_port->reserved_tci;
  1395. task_context = scic_sds_controller_get_task_context_buffer(scic, tci);
  1396. task_context->abort = 0;
  1397. command = SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
  1398. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1399. tci;
  1400. scic_sds_controller_post_request(scic, command);
  1401. }
  1402. /**
  1403. * This routine will abort the dummy request. This will alow the hardware to
  1404. * power down parts of the silicon to save power.
  1405. *
  1406. * @sci_port: The port on which the task must be aborted.
  1407. *
  1408. */
  1409. static void scic_sds_port_abort_dummy_request(struct scic_sds_port *sci_port)
  1410. {
  1411. struct scic_sds_controller *scic = sci_port->owning_controller;
  1412. u16 tci = sci_port->reserved_tci;
  1413. struct scu_task_context *tc;
  1414. u32 command;
  1415. tc = scic_sds_controller_get_task_context_buffer(scic, tci);
  1416. tc->abort = 1;
  1417. command = SCU_CONTEXT_COMMAND_REQUEST_POST_TC_ABORT |
  1418. sci_port->physical_port_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT |
  1419. tci;
  1420. scic_sds_controller_post_request(scic, command);
  1421. }
  1422. /**
  1423. *
  1424. * @sci_port: This is the struct scic_sds_port object to resume.
  1425. *
  1426. * This method will resume the port task scheduler for this port object. none
  1427. */
  1428. static void
  1429. scic_sds_port_resume_port_task_scheduler(struct scic_sds_port *port)
  1430. {
  1431. u32 pts_control_value;
  1432. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1433. pts_control_value &= ~SCU_PTSxCR_GEN_BIT(SUSPEND);
  1434. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1435. }
  1436. /*
  1437. * ******************************************************************************
  1438. * * PORT READY SUBSTATE METHODS
  1439. * ****************************************************************************** */
  1440. /**
  1441. *
  1442. * @object: This is the object which is cast to a struct scic_sds_port object.
  1443. *
  1444. * This method will perform the actions required by the struct scic_sds_port on
  1445. * entering the SCIC_SDS_PORT_READY_SUBSTATE_WAITING. This function checks the
  1446. * port for any ready phys. If there is at least one phy in a ready state then
  1447. * the port transitions to the ready operational substate. none
  1448. */
  1449. static void scic_sds_port_ready_substate_waiting_enter(void *object)
  1450. {
  1451. struct scic_sds_port *sci_port = object;
  1452. scic_sds_port_set_base_state_handlers(
  1453. sci_port, SCIC_SDS_PORT_READY_SUBSTATE_WAITING
  1454. );
  1455. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1456. sci_port->not_ready_reason = SCIC_PORT_NOT_READY_NO_ACTIVE_PHYS;
  1457. if (sci_port->active_phy_mask != 0) {
  1458. /* At least one of the phys on the port is ready */
  1459. port_state_machine_change(sci_port,
  1460. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1461. }
  1462. }
  1463. /**
  1464. *
  1465. * @object: This is the object which is cast to a struct scic_sds_port object.
  1466. *
  1467. * This function will perform the actions required by the struct scic_sds_port
  1468. * on entering the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function sets
  1469. * the state handlers for the port object, notifies the SCI User that the port
  1470. * is ready, and resumes port operations. none
  1471. */
  1472. static void scic_sds_port_ready_substate_operational_enter(void *object)
  1473. {
  1474. u32 index;
  1475. struct scic_sds_port *sci_port = object;
  1476. struct scic_sds_controller *scic = sci_port->owning_controller;
  1477. struct isci_host *ihost = scic_to_ihost(scic);
  1478. struct isci_port *iport = sci_port_to_iport(sci_port);
  1479. scic_sds_port_set_base_state_handlers(
  1480. sci_port,
  1481. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1482. isci_port_ready(ihost, iport);
  1483. for (index = 0; index < SCI_MAX_PHYS; index++) {
  1484. if (sci_port->phy_table[index]) {
  1485. writel(sci_port->physical_port_index,
  1486. &sci_port->port_pe_configuration_register[
  1487. sci_port->phy_table[index]->phy_index]);
  1488. }
  1489. }
  1490. scic_sds_port_update_viit_entry(sci_port);
  1491. scic_sds_port_resume_port_task_scheduler(sci_port);
  1492. /*
  1493. * Post the dummy task for the port so the hardware can schedule
  1494. * io correctly
  1495. */
  1496. scic_sds_port_post_dummy_request(sci_port);
  1497. }
  1498. static void scic_sds_port_invalidate_dummy_remote_node(struct scic_sds_port *sci_port)
  1499. {
  1500. struct scic_sds_controller *scic = sci_port->owning_controller;
  1501. u8 phys_index = sci_port->physical_port_index;
  1502. union scu_remote_node_context *rnc;
  1503. u16 rni = sci_port->reserved_rni;
  1504. u32 command;
  1505. rnc = &scic->remote_node_context_table[rni];
  1506. rnc->ssp.is_valid = false;
  1507. /* ensure the preceding tc abort request has reached the
  1508. * controller and give it ample time to act before posting the rnc
  1509. * invalidate
  1510. */
  1511. readl(&scic->smu_registers->interrupt_status); /* flush */
  1512. udelay(10);
  1513. command = SCU_CONTEXT_COMMAND_POST_RNC_INVALIDATE |
  1514. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1515. scic_sds_controller_post_request(scic, command);
  1516. }
  1517. /**
  1518. *
  1519. * @object: This is the object which is cast to a struct scic_sds_port object.
  1520. *
  1521. * This method will perform the actions required by the struct scic_sds_port on
  1522. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1523. * the port not ready and suspends the port task scheduler. none
  1524. */
  1525. static void scic_sds_port_ready_substate_operational_exit(void *object)
  1526. {
  1527. struct scic_sds_port *sci_port = object;
  1528. struct scic_sds_controller *scic = sci_port->owning_controller;
  1529. struct isci_host *ihost = scic_to_ihost(scic);
  1530. struct isci_port *iport = sci_port_to_iport(sci_port);
  1531. /*
  1532. * Kill the dummy task for this port if it has not yet posted
  1533. * the hardware will treat this as a NOP and just return abort
  1534. * complete.
  1535. */
  1536. scic_sds_port_abort_dummy_request(sci_port);
  1537. isci_port_not_ready(ihost, iport);
  1538. if (sci_port->ready_exit)
  1539. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1540. }
  1541. /*
  1542. * ******************************************************************************
  1543. * * PORT READY CONFIGURING METHODS
  1544. * ****************************************************************************** */
  1545. /**
  1546. * scic_sds_port_ready_substate_configuring_enter() -
  1547. * @object: This is the object which is cast to a struct scic_sds_port object.
  1548. *
  1549. * This method will perform the actions required by the struct scic_sds_port on
  1550. * exiting the SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL. This function reports
  1551. * the port not ready and suspends the port task scheduler. none
  1552. */
  1553. static void scic_sds_port_ready_substate_configuring_enter(void *object)
  1554. {
  1555. struct scic_sds_port *sci_port = object;
  1556. struct scic_sds_controller *scic = sci_port->owning_controller;
  1557. struct isci_host *ihost = scic_to_ihost(scic);
  1558. struct isci_port *iport = sci_port_to_iport(sci_port);
  1559. scic_sds_port_set_base_state_handlers(
  1560. sci_port,
  1561. SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING);
  1562. if (sci_port->active_phy_mask == 0) {
  1563. isci_port_not_ready(ihost, iport);
  1564. port_state_machine_change(sci_port,
  1565. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  1566. } else if (sci_port->started_request_count == 0)
  1567. port_state_machine_change(sci_port,
  1568. SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL);
  1569. }
  1570. static void scic_sds_port_ready_substate_configuring_exit(void *object)
  1571. {
  1572. struct scic_sds_port *sci_port = object;
  1573. scic_sds_port_suspend_port_task_scheduler(sci_port);
  1574. if (sci_port->ready_exit)
  1575. scic_sds_port_invalidate_dummy_remote_node(sci_port);
  1576. }
  1577. /* --------------------------------------------------------------------------- */
  1578. /**
  1579. *
  1580. * @port: This is the struct scic_sds_port object on which the io request count will
  1581. * be decremented.
  1582. * @device: This is the struct scic_sds_remote_device object to which the io request
  1583. * is being directed. This parameter is not required to complete this
  1584. * operation.
  1585. * @io_request: This is the request that is being completed on this port
  1586. * object. This parameter is not required to complete this operation.
  1587. *
  1588. * This is a general complete io request handler for the struct scic_sds_port object.
  1589. * enum sci_status SCI_SUCCESS
  1590. */
  1591. static enum sci_status scic_sds_port_general_complete_io_handler(
  1592. struct scic_sds_port *port,
  1593. struct scic_sds_remote_device *device,
  1594. struct scic_sds_request *io_request)
  1595. {
  1596. scic_sds_port_decrement_request_count(port);
  1597. return SCI_SUCCESS;
  1598. }
  1599. /**
  1600. * scic_sds_port_stopped_state_start_handler() - stop a port from "started"
  1601. *
  1602. * @port: This is the struct scic_sds_port object which is cast into a
  1603. * struct scic_sds_port object.
  1604. *
  1605. * This function takes the struct scic_sds_port from a stopped state and
  1606. * attempts to start it. To start a port it must have no assiged devices and
  1607. * it must have at least one phy assigned to it. If those conditions are
  1608. * met then the port can transition to the ready state.
  1609. * enum sci_status
  1610. * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION
  1611. * This struct scic_sds_port object could not be started because the port
  1612. * configuration is not valid.
  1613. * SCI_SUCCESS
  1614. * the start request is successful and the struct scic_sds_port object
  1615. * has transitioned to the SCI_BASE_PORT_STATE_READY.
  1616. */
  1617. static enum sci_status
  1618. scic_sds_port_stopped_state_start_handler(struct scic_sds_port *sci_port)
  1619. {
  1620. struct scic_sds_controller *scic = sci_port->owning_controller;
  1621. struct isci_host *ihost = scic_to_ihost(scic);
  1622. enum sci_status status = SCI_SUCCESS;
  1623. u32 phy_mask;
  1624. if (sci_port->assigned_device_count > 0) {
  1625. /*
  1626. * @todo This is a start failure operation because
  1627. * there are still devices assigned to this port.
  1628. * There must be no devices assigned to a port on a
  1629. * start operation.
  1630. */
  1631. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1632. }
  1633. sci_port->timer_handle =
  1634. isci_timer_create(ihost,
  1635. sci_port,
  1636. scic_sds_port_timeout_handler);
  1637. if (!sci_port->timer_handle)
  1638. return SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1639. if (sci_port->reserved_rni == SCU_DUMMY_INDEX) {
  1640. u16 rni = scic_sds_remote_node_table_allocate_remote_node(
  1641. &scic->available_remote_nodes, 1);
  1642. if (rni != SCU_DUMMY_INDEX)
  1643. scic_sds_port_construct_dummy_rnc(sci_port, rni);
  1644. else
  1645. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1646. sci_port->reserved_rni = rni;
  1647. }
  1648. if (sci_port->reserved_tci == SCU_DUMMY_INDEX) {
  1649. /* Allocate a TCI and remove the sequence nibble */
  1650. u16 tci = scic_controller_allocate_io_tag(scic);
  1651. if (tci != SCU_DUMMY_INDEX)
  1652. scic_sds_port_construct_dummy_task(sci_port, tci);
  1653. else
  1654. status = SCI_FAILURE_INSUFFICIENT_RESOURCES;
  1655. sci_port->reserved_tci = tci;
  1656. }
  1657. if (status == SCI_SUCCESS) {
  1658. phy_mask = scic_sds_port_get_phys(sci_port);
  1659. /*
  1660. * There are one or more phys assigned to this port. Make sure
  1661. * the port's phy mask is in fact legal and supported by the
  1662. * silicon.
  1663. */
  1664. if (scic_sds_port_is_phy_mask_valid(sci_port, phy_mask) == true) {
  1665. port_state_machine_change(sci_port,
  1666. SCI_BASE_PORT_STATE_READY);
  1667. return SCI_SUCCESS;
  1668. } else
  1669. status = SCI_FAILURE;
  1670. }
  1671. if (status != SCI_SUCCESS)
  1672. scic_sds_port_destroy_dummy_resources(sci_port);
  1673. return status;
  1674. }
  1675. /*
  1676. * This method takes the struct scic_sds_port that is in a stopped state and handles a
  1677. * stop request. This function takes no action. enum sci_status SCI_SUCCESS the
  1678. * stop request is successful as the struct scic_sds_port object is already stopped.
  1679. */
  1680. static enum sci_status scic_sds_port_stopped_state_stop_handler(
  1681. struct scic_sds_port *port)
  1682. {
  1683. /* We are already stopped so there is nothing to do here */
  1684. return SCI_SUCCESS;
  1685. }
  1686. /*
  1687. * This method takes the struct scic_sds_port that is in a stopped state and handles
  1688. * the destruct request. The stopped state is the only state in which the
  1689. * struct scic_sds_port can be destroyed. This function causes the port object to
  1690. * transition to the SCI_BASE_PORT_STATE_FINAL. enum sci_status SCI_SUCCESS
  1691. */
  1692. static enum sci_status scic_sds_port_stopped_state_destruct_handler(struct scic_sds_port *port)
  1693. {
  1694. port_state_machine_stop(port);
  1695. return SCI_SUCCESS;
  1696. }
  1697. /*
  1698. * This method takes the struct scic_sds_port that is in a stopped state and handles
  1699. * the add phy request. In MPC mode the only time a phy can be added to a port
  1700. * is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
  1701. * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
  1702. * be added to the port. SCI_SUCCESS if the phy is added to the port.
  1703. */
  1704. static enum sci_status scic_sds_port_stopped_state_add_phy_handler(
  1705. struct scic_sds_port *port,
  1706. struct scic_sds_phy *phy)
  1707. {
  1708. struct sci_sas_address port_sas_address;
  1709. /* Read the port assigned SAS Address if there is one */
  1710. scic_sds_port_get_sas_address(port, &port_sas_address);
  1711. if (port_sas_address.high != 0 && port_sas_address.low != 0) {
  1712. struct sci_sas_address phy_sas_address;
  1713. /*
  1714. * Make sure that the PHY SAS Address matches the SAS Address
  1715. * for this port. */
  1716. scic_sds_phy_get_sas_address(phy, &phy_sas_address);
  1717. if (
  1718. (port_sas_address.high != phy_sas_address.high)
  1719. || (port_sas_address.low != phy_sas_address.low)
  1720. ) {
  1721. return SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION;
  1722. }
  1723. }
  1724. return scic_sds_port_set_phy(port, phy);
  1725. }
  1726. /*
  1727. * This method takes the struct scic_sds_port that is in a stopped state and handles
  1728. * the remove phy request. In MPC mode the only time a phy can be removed from
  1729. * a port is in the SCI_BASE_PORT_STATE_STOPPED. enum sci_status
  1730. * SCI_FAILURE_UNSUPPORTED_PORT_CONFIGURATION is returned when the phy can not
  1731. * be added to the port. SCI_SUCCESS if the phy is added to the port.
  1732. */
  1733. static enum sci_status scic_sds_port_stopped_state_remove_phy_handler(
  1734. struct scic_sds_port *port,
  1735. struct scic_sds_phy *phy)
  1736. {
  1737. return scic_sds_port_clear_phy(port, phy);
  1738. }
  1739. /*
  1740. * ****************************************************************************
  1741. * * READY STATE HANDLERS
  1742. * **************************************************************************** */
  1743. /*
  1744. * ****************************************************************************
  1745. * * RESETTING STATE HANDLERS
  1746. * **************************************************************************** */
  1747. /*
  1748. * ****************************************************************************
  1749. * * STOPPING STATE HANDLERS
  1750. * **************************************************************************** */
  1751. /*
  1752. * This method takes the struct scic_sds_port that is in a stopping state and handles
  1753. * the complete io request. Should the request count reach 0 then the port
  1754. * object will transition to the stopped state. enum sci_status SCI_SUCCESS
  1755. */
  1756. static enum sci_status scic_sds_port_stopping_state_complete_io_handler(
  1757. struct scic_sds_port *sci_port,
  1758. struct scic_sds_remote_device *device,
  1759. struct scic_sds_request *io_request)
  1760. {
  1761. scic_sds_port_decrement_request_count(sci_port);
  1762. if (sci_port->started_request_count == 0)
  1763. port_state_machine_change(sci_port,
  1764. SCI_BASE_PORT_STATE_STOPPED);
  1765. return SCI_SUCCESS;
  1766. }
  1767. /*
  1768. * ****************************************************************************
  1769. * * RESETTING STATE HANDLERS
  1770. * **************************************************************************** */
  1771. /**
  1772. *
  1773. * @port: This is the port object which is being requested to stop.
  1774. *
  1775. * This method will stop a failed port. This causes a transition to the
  1776. * stopping state. enum sci_status SCI_SUCCESS
  1777. */
  1778. static enum sci_status scic_sds_port_reset_state_stop_handler(
  1779. struct scic_sds_port *port)
  1780. {
  1781. port_state_machine_change(port,
  1782. SCI_BASE_PORT_STATE_STOPPING);
  1783. return SCI_SUCCESS;
  1784. }
  1785. /*
  1786. * This method will transition a failed port to its ready state. The port
  1787. * failed because a hard reset request timed out but at some time later one or
  1788. * more phys in the port became ready. enum sci_status SCI_SUCCESS
  1789. */
  1790. static void scic_sds_port_reset_state_link_up_handler(
  1791. struct scic_sds_port *port,
  1792. struct scic_sds_phy *phy)
  1793. {
  1794. /*
  1795. * / @todo We should make sure that the phy that has gone link up is the same
  1796. * / one on which we sent the reset. It is possible that the phy on
  1797. * / which we sent the reset is not the one that has gone link up and we
  1798. * / want to make sure that phy being reset comes back. Consider the
  1799. * / case where a reset is sent but before the hardware processes the
  1800. * / reset it get a link up on the port because of a hot plug event.
  1801. * / because of the reset request this phy will go link down almost
  1802. * / immediately. */
  1803. /*
  1804. * In the resetting state we don't notify the user regarding
  1805. * link up and link down notifications. */
  1806. scic_sds_port_general_link_up_handler(port, phy, false);
  1807. }
  1808. /*
  1809. * This method process link down notifications that occur during a port reset
  1810. * operation. Link downs can occur during the reset operation. enum sci_status
  1811. * SCI_SUCCESS
  1812. */
  1813. static void scic_sds_port_reset_state_link_down_handler(
  1814. struct scic_sds_port *port,
  1815. struct scic_sds_phy *phy)
  1816. {
  1817. /*
  1818. * In the resetting state we don't notify the user regarding
  1819. * link up and link down notifications. */
  1820. scic_sds_port_deactivate_phy(port, phy, false);
  1821. }
  1822. static struct scic_sds_port_state_handler scic_sds_port_state_handler_table[] = {
  1823. [SCI_BASE_PORT_STATE_STOPPED] = {
  1824. .start_handler = scic_sds_port_stopped_state_start_handler,
  1825. .stop_handler = scic_sds_port_stopped_state_stop_handler,
  1826. .destruct_handler = scic_sds_port_stopped_state_destruct_handler,
  1827. .reset_handler = scic_sds_port_default_reset_handler,
  1828. .add_phy_handler = scic_sds_port_stopped_state_add_phy_handler,
  1829. .remove_phy_handler = scic_sds_port_stopped_state_remove_phy_handler,
  1830. .frame_handler = scic_sds_port_default_frame_handler,
  1831. .event_handler = scic_sds_port_default_event_handler,
  1832. .link_up_handler = scic_sds_port_default_link_up_handler,
  1833. .link_down_handler = scic_sds_port_default_link_down_handler,
  1834. .start_io_handler = scic_sds_port_default_start_io_handler,
  1835. .complete_io_handler = scic_sds_port_default_complete_io_handler
  1836. },
  1837. [SCI_BASE_PORT_STATE_STOPPING] = {
  1838. .start_handler = scic_sds_port_default_start_handler,
  1839. .stop_handler = scic_sds_port_default_stop_handler,
  1840. .destruct_handler = scic_sds_port_default_destruct_handler,
  1841. .reset_handler = scic_sds_port_default_reset_handler,
  1842. .add_phy_handler = scic_sds_port_default_add_phy_handler,
  1843. .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
  1844. .frame_handler = scic_sds_port_default_frame_handler,
  1845. .event_handler = scic_sds_port_default_event_handler,
  1846. .link_up_handler = scic_sds_port_default_link_up_handler,
  1847. .link_down_handler = scic_sds_port_default_link_down_handler,
  1848. .start_io_handler = scic_sds_port_default_start_io_handler,
  1849. .complete_io_handler = scic_sds_port_stopping_state_complete_io_handler
  1850. },
  1851. [SCI_BASE_PORT_STATE_READY] = {
  1852. .start_handler = scic_sds_port_default_start_handler,
  1853. .stop_handler = scic_sds_port_default_stop_handler,
  1854. .destruct_handler = scic_sds_port_default_destruct_handler,
  1855. .reset_handler = scic_sds_port_default_reset_handler,
  1856. .add_phy_handler = scic_sds_port_default_add_phy_handler,
  1857. .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
  1858. .frame_handler = scic_sds_port_default_frame_handler,
  1859. .event_handler = scic_sds_port_default_event_handler,
  1860. .link_up_handler = scic_sds_port_default_link_up_handler,
  1861. .link_down_handler = scic_sds_port_default_link_down_handler,
  1862. .start_io_handler = scic_sds_port_default_start_io_handler,
  1863. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1864. },
  1865. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  1866. .start_handler = scic_sds_port_default_start_handler,
  1867. .stop_handler = scic_sds_port_ready_substate_stop_handler,
  1868. .destruct_handler = scic_sds_port_default_destruct_handler,
  1869. .reset_handler = scic_sds_port_default_reset_handler,
  1870. .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
  1871. .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
  1872. .frame_handler = scic_sds_port_default_frame_handler,
  1873. .event_handler = scic_sds_port_default_event_handler,
  1874. .link_up_handler = scic_sds_port_ready_waiting_substate_link_up_handler,
  1875. .link_down_handler = scic_sds_port_default_link_down_handler,
  1876. .start_io_handler = scic_sds_port_ready_waiting_substate_start_io_handler,
  1877. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1878. },
  1879. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  1880. .start_handler = scic_sds_port_default_start_handler,
  1881. .stop_handler = scic_sds_port_ready_substate_stop_handler,
  1882. .destruct_handler = scic_sds_port_default_destruct_handler,
  1883. .reset_handler = scic_sds_port_ready_operational_substate_reset_handler,
  1884. .add_phy_handler = scic_sds_port_ready_substate_add_phy_handler,
  1885. .remove_phy_handler = scic_sds_port_ready_substate_remove_phy_handler,
  1886. .frame_handler = scic_sds_port_default_frame_handler,
  1887. .event_handler = scic_sds_port_default_event_handler,
  1888. .link_up_handler = scic_sds_port_ready_operational_substate_link_up_handler,
  1889. .link_down_handler = scic_sds_port_ready_operational_substate_link_down_handler,
  1890. .start_io_handler = scic_sds_port_ready_operational_substate_start_io_handler,
  1891. .complete_io_handler = scic_sds_port_ready_substate_complete_io_handler,
  1892. },
  1893. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  1894. .start_handler = scic_sds_port_default_start_handler,
  1895. .stop_handler = scic_sds_port_ready_substate_stop_handler,
  1896. .destruct_handler = scic_sds_port_default_destruct_handler,
  1897. .reset_handler = scic_sds_port_default_reset_handler,
  1898. .add_phy_handler = scic_sds_port_ready_configuring_substate_add_phy_handler,
  1899. .remove_phy_handler = scic_sds_port_ready_configuring_substate_remove_phy_handler,
  1900. .frame_handler = scic_sds_port_default_frame_handler,
  1901. .event_handler = scic_sds_port_default_event_handler,
  1902. .link_up_handler = scic_sds_port_default_link_up_handler,
  1903. .link_down_handler = scic_sds_port_default_link_down_handler,
  1904. .start_io_handler = scic_sds_port_default_start_io_handler,
  1905. .complete_io_handler = scic_sds_port_ready_configuring_substate_complete_io_handler
  1906. },
  1907. [SCI_BASE_PORT_STATE_RESETTING] = {
  1908. .start_handler = scic_sds_port_default_start_handler,
  1909. .stop_handler = scic_sds_port_reset_state_stop_handler,
  1910. .destruct_handler = scic_sds_port_default_destruct_handler,
  1911. .reset_handler = scic_sds_port_default_reset_handler,
  1912. .add_phy_handler = scic_sds_port_default_add_phy_handler,
  1913. .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
  1914. .frame_handler = scic_sds_port_default_frame_handler,
  1915. .event_handler = scic_sds_port_default_event_handler,
  1916. .link_up_handler = scic_sds_port_reset_state_link_up_handler,
  1917. .link_down_handler = scic_sds_port_reset_state_link_down_handler,
  1918. .start_io_handler = scic_sds_port_default_start_io_handler,
  1919. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1920. },
  1921. [SCI_BASE_PORT_STATE_FAILED] = {
  1922. .start_handler = scic_sds_port_default_start_handler,
  1923. .stop_handler = scic_sds_port_default_stop_handler,
  1924. .destruct_handler = scic_sds_port_default_destruct_handler,
  1925. .reset_handler = scic_sds_port_default_reset_handler,
  1926. .add_phy_handler = scic_sds_port_default_add_phy_handler,
  1927. .remove_phy_handler = scic_sds_port_default_remove_phy_handler,
  1928. .frame_handler = scic_sds_port_default_frame_handler,
  1929. .event_handler = scic_sds_port_default_event_handler,
  1930. .link_up_handler = scic_sds_port_default_link_up_handler,
  1931. .link_down_handler = scic_sds_port_default_link_down_handler,
  1932. .start_io_handler = scic_sds_port_default_start_io_handler,
  1933. .complete_io_handler = scic_sds_port_general_complete_io_handler
  1934. }
  1935. };
  1936. /*
  1937. * ******************************************************************************
  1938. * * PORT STATE PRIVATE METHODS
  1939. * ****************************************************************************** */
  1940. /**
  1941. *
  1942. * @sci_port: This is the port object which to suspend.
  1943. *
  1944. * This method will enable the SCU Port Task Scheduler for this port object but
  1945. * will leave the port task scheduler in a suspended state. none
  1946. */
  1947. static void
  1948. scic_sds_port_enable_port_task_scheduler(struct scic_sds_port *port)
  1949. {
  1950. u32 pts_control_value;
  1951. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1952. pts_control_value |= SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND);
  1953. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1954. }
  1955. /**
  1956. *
  1957. * @sci_port: This is the port object which to resume.
  1958. *
  1959. * This method will disable the SCU port task scheduler for this port object.
  1960. * none
  1961. */
  1962. static void
  1963. scic_sds_port_disable_port_task_scheduler(struct scic_sds_port *port)
  1964. {
  1965. u32 pts_control_value;
  1966. pts_control_value = readl(&port->port_task_scheduler_registers->control);
  1967. pts_control_value &=
  1968. ~(SCU_PTSxCR_GEN_BIT(ENABLE) | SCU_PTSxCR_GEN_BIT(SUSPEND));
  1969. writel(pts_control_value, &port->port_task_scheduler_registers->control);
  1970. }
  1971. static void scic_sds_port_post_dummy_remote_node(struct scic_sds_port *sci_port)
  1972. {
  1973. struct scic_sds_controller *scic = sci_port->owning_controller;
  1974. u8 phys_index = sci_port->physical_port_index;
  1975. union scu_remote_node_context *rnc;
  1976. u16 rni = sci_port->reserved_rni;
  1977. u32 command;
  1978. rnc = &scic->remote_node_context_table[rni];
  1979. rnc->ssp.is_valid = true;
  1980. command = SCU_CONTEXT_COMMAND_POST_RNC_32 |
  1981. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1982. scic_sds_controller_post_request(scic, command);
  1983. /* ensure hardware has seen the post rnc command and give it
  1984. * ample time to act before sending the suspend
  1985. */
  1986. readl(&scic->smu_registers->interrupt_status); /* flush */
  1987. udelay(10);
  1988. command = SCU_CONTEXT_COMMAND_POST_RNC_SUSPEND_TX_RX |
  1989. phys_index << SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT | rni;
  1990. scic_sds_controller_post_request(scic, command);
  1991. }
  1992. /*
  1993. * ******************************************************************************
  1994. * * PORT STATE METHODS
  1995. * ****************************************************************************** */
  1996. /**
  1997. *
  1998. * @object: This is the object which is cast to a struct scic_sds_port object.
  1999. *
  2000. * This method will perform the actions required by the struct scic_sds_port on
  2001. * entering the SCI_BASE_PORT_STATE_STOPPED. This function sets the stopped
  2002. * state handlers for the struct scic_sds_port object and disables the port task
  2003. * scheduler in the hardware. none
  2004. */
  2005. static void scic_sds_port_stopped_state_enter(void *object)
  2006. {
  2007. struct scic_sds_port *sci_port = object;
  2008. scic_sds_port_set_base_state_handlers(
  2009. sci_port, SCI_BASE_PORT_STATE_STOPPED
  2010. );
  2011. if (
  2012. SCI_BASE_PORT_STATE_STOPPING
  2013. == sci_port->state_machine.previous_state_id
  2014. ) {
  2015. /*
  2016. * If we enter this state becasuse of a request to stop
  2017. * the port then we want to disable the hardwares port
  2018. * task scheduler. */
  2019. scic_sds_port_disable_port_task_scheduler(sci_port);
  2020. }
  2021. }
  2022. /**
  2023. *
  2024. * @object: This is the object which is cast to a struct scic_sds_port object.
  2025. *
  2026. * This method will perform the actions required by the struct scic_sds_port on
  2027. * exiting the SCI_BASE_STATE_STOPPED. This function enables the SCU hardware
  2028. * port task scheduler. none
  2029. */
  2030. static void scic_sds_port_stopped_state_exit(void *object)
  2031. {
  2032. struct scic_sds_port *sci_port = object;
  2033. /* Enable and suspend the port task scheduler */
  2034. scic_sds_port_enable_port_task_scheduler(sci_port);
  2035. }
  2036. /**
  2037. * scic_sds_port_ready_state_enter -
  2038. * @object: This is the object which is cast to a struct scic_sds_port object.
  2039. *
  2040. * This method will perform the actions required by the struct scic_sds_port on
  2041. * entering the SCI_BASE_PORT_STATE_READY. This function sets the ready state
  2042. * handlers for the struct scic_sds_port object, reports the port object as
  2043. * not ready and starts the ready substate machine. none
  2044. */
  2045. static void scic_sds_port_ready_state_enter(void *object)
  2046. {
  2047. struct scic_sds_port *sci_port = object;
  2048. struct scic_sds_controller *scic = sci_port->owning_controller;
  2049. struct isci_host *ihost = scic_to_ihost(scic);
  2050. struct isci_port *iport = sci_port_to_iport(sci_port);
  2051. u32 prev_state;
  2052. /* Put the ready state handlers in place though they will not be there long */
  2053. scic_sds_port_set_base_state_handlers(sci_port, SCI_BASE_PORT_STATE_READY);
  2054. prev_state = sci_port->state_machine.previous_state_id;
  2055. if (prev_state == SCI_BASE_PORT_STATE_RESETTING)
  2056. isci_port_hard_reset_complete(iport, SCI_SUCCESS);
  2057. else
  2058. isci_port_not_ready(ihost, iport);
  2059. /* Post and suspend the dummy remote node context for this port. */
  2060. scic_sds_port_post_dummy_remote_node(sci_port);
  2061. /* Start the ready substate machine */
  2062. port_state_machine_change(sci_port,
  2063. SCIC_SDS_PORT_READY_SUBSTATE_WAITING);
  2064. }
  2065. /**
  2066. *
  2067. * @object: This is the object which is cast to a struct scic_sds_port object.
  2068. *
  2069. * This method will perform the actions required by the struct scic_sds_port on
  2070. * entering the SCI_BASE_PORT_STATE_RESETTING. This function sets the resetting
  2071. * state handlers for the struct scic_sds_port object. none
  2072. */
  2073. static void scic_sds_port_resetting_state_enter(void *object)
  2074. {
  2075. struct scic_sds_port *sci_port = object;
  2076. scic_sds_port_set_base_state_handlers(
  2077. sci_port, SCI_BASE_PORT_STATE_RESETTING
  2078. );
  2079. }
  2080. /**
  2081. *
  2082. * @object: This is the object which is cast to a struct scic_sds_port object.
  2083. *
  2084. * This function will perform the actions required by the
  2085. * struct scic_sds_port on
  2086. * exiting the SCI_BASE_STATE_RESETTING. This function does nothing. none
  2087. */
  2088. static inline void scic_sds_port_resetting_state_exit(void *object)
  2089. {
  2090. struct scic_sds_port *sci_port = object;
  2091. isci_timer_stop(sci_port->timer_handle);
  2092. }
  2093. /**
  2094. *
  2095. * @object: This is the void object which is cast to a
  2096. * struct scic_sds_port object.
  2097. *
  2098. * This method will perform the actions required by the struct scic_sds_port on
  2099. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  2100. * state handlers for the struct scic_sds_port object. none
  2101. */
  2102. static void scic_sds_port_stopping_state_enter(void *object)
  2103. {
  2104. struct scic_sds_port *sci_port = object;
  2105. scic_sds_port_set_base_state_handlers(
  2106. sci_port, SCI_BASE_PORT_STATE_STOPPING
  2107. );
  2108. }
  2109. /**
  2110. *
  2111. * @object: This is the object which is cast to a struct scic_sds_port object.
  2112. *
  2113. * This function will perform the actions required by the
  2114. * struct scic_sds_port on
  2115. * exiting the SCI_BASE_STATE_STOPPING. This function does nothing. none
  2116. */
  2117. static inline void
  2118. scic_sds_port_stopping_state_exit(void *object)
  2119. {
  2120. struct scic_sds_port *sci_port = object;
  2121. isci_timer_stop(sci_port->timer_handle);
  2122. scic_sds_port_destroy_dummy_resources(sci_port);
  2123. }
  2124. /**
  2125. *
  2126. * @object: This is the object which is cast to a struct scic_sds_port object.
  2127. *
  2128. * This function will perform the actions required by the
  2129. * struct scic_sds_port on
  2130. * entering the SCI_BASE_PORT_STATE_STOPPING. This function sets the stopping
  2131. * state handlers for the struct scic_sds_port object. none
  2132. */
  2133. static void scic_sds_port_failed_state_enter(void *object)
  2134. {
  2135. struct scic_sds_port *sci_port = object;
  2136. struct isci_port *iport = sci_port_to_iport(sci_port);
  2137. scic_sds_port_set_base_state_handlers(sci_port,
  2138. SCI_BASE_PORT_STATE_FAILED);
  2139. isci_port_hard_reset_complete(iport, SCI_FAILURE_TIMEOUT);
  2140. }
  2141. /* --------------------------------------------------------------------------- */
  2142. static const struct sci_base_state scic_sds_port_state_table[] = {
  2143. [SCI_BASE_PORT_STATE_STOPPED] = {
  2144. .enter_state = scic_sds_port_stopped_state_enter,
  2145. .exit_state = scic_sds_port_stopped_state_exit
  2146. },
  2147. [SCI_BASE_PORT_STATE_STOPPING] = {
  2148. .enter_state = scic_sds_port_stopping_state_enter,
  2149. .exit_state = scic_sds_port_stopping_state_exit
  2150. },
  2151. [SCI_BASE_PORT_STATE_READY] = {
  2152. .enter_state = scic_sds_port_ready_state_enter,
  2153. },
  2154. [SCIC_SDS_PORT_READY_SUBSTATE_WAITING] = {
  2155. .enter_state = scic_sds_port_ready_substate_waiting_enter,
  2156. },
  2157. [SCIC_SDS_PORT_READY_SUBSTATE_OPERATIONAL] = {
  2158. .enter_state = scic_sds_port_ready_substate_operational_enter,
  2159. .exit_state = scic_sds_port_ready_substate_operational_exit
  2160. },
  2161. [SCIC_SDS_PORT_READY_SUBSTATE_CONFIGURING] = {
  2162. .enter_state = scic_sds_port_ready_substate_configuring_enter,
  2163. .exit_state = scic_sds_port_ready_substate_configuring_exit
  2164. },
  2165. [SCI_BASE_PORT_STATE_RESETTING] = {
  2166. .enter_state = scic_sds_port_resetting_state_enter,
  2167. .exit_state = scic_sds_port_resetting_state_exit
  2168. },
  2169. [SCI_BASE_PORT_STATE_FAILED] = {
  2170. .enter_state = scic_sds_port_failed_state_enter,
  2171. }
  2172. };
  2173. void scic_sds_port_construct(struct scic_sds_port *sci_port, u8 index,
  2174. struct scic_sds_controller *scic)
  2175. {
  2176. sci_base_state_machine_construct(&sci_port->state_machine,
  2177. sci_port,
  2178. scic_sds_port_state_table,
  2179. SCI_BASE_PORT_STATE_STOPPED);
  2180. sci_base_state_machine_start(&sci_port->state_machine);
  2181. sci_port->logical_port_index = SCIC_SDS_DUMMY_PORT;
  2182. sci_port->physical_port_index = index;
  2183. sci_port->active_phy_mask = 0;
  2184. sci_port->ready_exit = false;
  2185. sci_port->owning_controller = scic;
  2186. sci_port->started_request_count = 0;
  2187. sci_port->assigned_device_count = 0;
  2188. sci_port->reserved_rni = SCU_DUMMY_INDEX;
  2189. sci_port->reserved_tci = SCU_DUMMY_INDEX;
  2190. sci_port->timer_handle = NULL;
  2191. sci_port->port_task_scheduler_registers = NULL;
  2192. for (index = 0; index < SCI_MAX_PHYS; index++)
  2193. sci_port->phy_table[index] = NULL;
  2194. }
  2195. void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
  2196. {
  2197. INIT_LIST_HEAD(&iport->remote_dev_list);
  2198. INIT_LIST_HEAD(&iport->domain_dev_list);
  2199. spin_lock_init(&iport->state_lock);
  2200. init_completion(&iport->start_complete);
  2201. iport->isci_host = ihost;
  2202. isci_port_change_state(iport, isci_freed);
  2203. }
  2204. /**
  2205. * isci_port_get_state() - This function gets the status of the port object.
  2206. * @isci_port: This parameter points to the isci_port object
  2207. *
  2208. * status of the object as a isci_status enum.
  2209. */
  2210. enum isci_status isci_port_get_state(
  2211. struct isci_port *isci_port)
  2212. {
  2213. return isci_port->status;
  2214. }
  2215. static void isci_port_bc_change_received(struct isci_host *ihost,
  2216. struct scic_sds_port *sci_port,
  2217. struct scic_sds_phy *sci_phy)
  2218. {
  2219. struct isci_phy *iphy = sci_phy_to_iphy(sci_phy);
  2220. dev_dbg(&ihost->pdev->dev, "%s: iphy = %p, sas_phy = %p\n",
  2221. __func__, iphy, &iphy->sas_phy);
  2222. ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
  2223. scic_port_enable_broadcast_change_notification(sci_port);
  2224. }
  2225. void scic_sds_port_broadcast_change_received(
  2226. struct scic_sds_port *sci_port,
  2227. struct scic_sds_phy *sci_phy)
  2228. {
  2229. struct scic_sds_controller *scic = sci_port->owning_controller;
  2230. struct isci_host *ihost = scic_to_ihost(scic);
  2231. /* notify the user. */
  2232. isci_port_bc_change_received(ihost, sci_port, sci_phy);
  2233. }
  2234. int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *iport,
  2235. struct isci_phy *iphy)
  2236. {
  2237. unsigned long flags;
  2238. enum sci_status status;
  2239. int ret = TMF_RESP_FUNC_COMPLETE;
  2240. dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
  2241. __func__, iport);
  2242. init_completion(&iport->hard_reset_complete);
  2243. spin_lock_irqsave(&ihost->scic_lock, flags);
  2244. #define ISCI_PORT_RESET_TIMEOUT SCIC_SDS_SIGNATURE_FIS_TIMEOUT
  2245. status = scic_port_hard_reset(&iport->sci, ISCI_PORT_RESET_TIMEOUT);
  2246. spin_unlock_irqrestore(&ihost->scic_lock, flags);
  2247. if (status == SCI_SUCCESS) {
  2248. wait_for_completion(&iport->hard_reset_complete);
  2249. dev_dbg(&ihost->pdev->dev,
  2250. "%s: iport = %p; hard reset completion\n",
  2251. __func__, iport);
  2252. if (iport->hard_reset_status != SCI_SUCCESS)
  2253. ret = TMF_RESP_FUNC_FAILED;
  2254. } else {
  2255. ret = TMF_RESP_FUNC_FAILED;
  2256. dev_err(&ihost->pdev->dev,
  2257. "%s: iport = %p; scic_port_hard_reset call"
  2258. " failed 0x%x\n",
  2259. __func__, iport, status);
  2260. }
  2261. /* If the hard reset for the port has failed, consider this
  2262. * the same as link failures on all phys in the port.
  2263. */
  2264. if (ret != TMF_RESP_FUNC_COMPLETE) {
  2265. dev_err(&ihost->pdev->dev,
  2266. "%s: iport = %p; hard reset failed "
  2267. "(0x%x) - sending link down to libsas for phy %p\n",
  2268. __func__, iport, iport->hard_reset_status, iphy);
  2269. isci_port_link_down(ihost, iphy, iport);
  2270. }
  2271. return ret;
  2272. }
  2273. /**
  2274. * isci_port_deformed() - This function is called by libsas when a port becomes
  2275. * inactive.
  2276. * @phy: This parameter specifies the libsas phy with the inactive port.
  2277. *
  2278. */
  2279. void isci_port_deformed(struct asd_sas_phy *phy)
  2280. {
  2281. pr_debug("%s: sas_phy = %p\n", __func__, phy);
  2282. }
  2283. /**
  2284. * isci_port_formed() - This function is called by libsas when a port becomes
  2285. * active.
  2286. * @phy: This parameter specifies the libsas phy with the active port.
  2287. *
  2288. */
  2289. void isci_port_formed(struct asd_sas_phy *phy)
  2290. {
  2291. pr_debug("%s: sas_phy = %p, sas_port = %p\n", __func__, phy, phy->port);
  2292. }