port.c 61 KB

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