port.c 86 KB

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