zfcp_fsf.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corp. 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. struct kmem_cache *zfcp_fsf_qtcb_cache;
  19. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  20. {
  21. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  22. zfcp_qdio_siosl(adapter);
  23. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  24. "fsrth_1");
  25. }
  26. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  27. unsigned long timeout)
  28. {
  29. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  30. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  31. fsf_req->timer.expires = jiffies + timeout;
  32. add_timer(&fsf_req->timer);
  33. }
  34. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  35. {
  36. BUG_ON(!fsf_req->erp_action);
  37. fsf_req->timer.function = zfcp_erp_timeout_handler;
  38. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  39. fsf_req->timer.expires = jiffies + 30 * HZ;
  40. add_timer(&fsf_req->timer);
  41. }
  42. /* association between FSF command and FSF QTCB type */
  43. static u32 fsf_qtcb_type[] = {
  44. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  45. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  53. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  54. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  55. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  57. };
  58. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  59. {
  60. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  61. "operational because of an unsupported FC class\n");
  62. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
  63. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  64. }
  65. /**
  66. * zfcp_fsf_req_free - free memory used by fsf request
  67. * @fsf_req: pointer to struct zfcp_fsf_req
  68. */
  69. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  70. {
  71. if (likely(req->pool)) {
  72. if (likely(req->qtcb))
  73. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  74. mempool_free(req, req->pool);
  75. return;
  76. }
  77. if (likely(req->qtcb))
  78. kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
  79. kfree(req);
  80. }
  81. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  82. {
  83. unsigned long flags;
  84. struct fsf_status_read_buffer *sr_buf = req->data;
  85. struct zfcp_adapter *adapter = req->adapter;
  86. struct zfcp_port *port;
  87. int d_id = ntoh24(sr_buf->d_id);
  88. read_lock_irqsave(&adapter->port_list_lock, flags);
  89. list_for_each_entry(port, &adapter->port_list, list)
  90. if (port->d_id == d_id) {
  91. zfcp_erp_port_reopen(port, 0, "fssrpc1");
  92. break;
  93. }
  94. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  95. }
  96. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  97. struct fsf_link_down_info *link_down)
  98. {
  99. struct zfcp_adapter *adapter = req->adapter;
  100. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  101. return;
  102. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  103. zfcp_scsi_schedule_rports_block(adapter);
  104. if (!link_down)
  105. goto out;
  106. switch (link_down->error_code) {
  107. case FSF_PSQ_LINK_NO_LIGHT:
  108. dev_warn(&req->adapter->ccw_device->dev,
  109. "There is no light signal from the local "
  110. "fibre channel cable\n");
  111. break;
  112. case FSF_PSQ_LINK_WRAP_PLUG:
  113. dev_warn(&req->adapter->ccw_device->dev,
  114. "There is a wrap plug instead of a fibre "
  115. "channel cable\n");
  116. break;
  117. case FSF_PSQ_LINK_NO_FCP:
  118. dev_warn(&req->adapter->ccw_device->dev,
  119. "The adjacent fibre channel node does not "
  120. "support FCP\n");
  121. break;
  122. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  123. dev_warn(&req->adapter->ccw_device->dev,
  124. "The FCP device is suspended because of a "
  125. "firmware update\n");
  126. break;
  127. case FSF_PSQ_LINK_INVALID_WWPN:
  128. dev_warn(&req->adapter->ccw_device->dev,
  129. "The FCP device detected a WWPN that is "
  130. "duplicate or not valid\n");
  131. break;
  132. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  133. dev_warn(&req->adapter->ccw_device->dev,
  134. "The fibre channel fabric does not support NPIV\n");
  135. break;
  136. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  137. dev_warn(&req->adapter->ccw_device->dev,
  138. "The FCP adapter cannot support more NPIV ports\n");
  139. break;
  140. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "The adjacent switch cannot support "
  143. "more NPIV ports\n");
  144. break;
  145. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "The FCP adapter could not log in to the "
  148. "fibre channel fabric\n");
  149. break;
  150. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The WWPN assignment file on the FCP adapter "
  153. "has been damaged\n");
  154. break;
  155. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The mode table on the FCP adapter "
  158. "has been damaged\n");
  159. break;
  160. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "All NPIV ports on the FCP adapter have "
  163. "been assigned\n");
  164. break;
  165. default:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The link between the FCP adapter and "
  168. "the FC fabric is down\n");
  169. }
  170. out:
  171. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  172. }
  173. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  174. {
  175. struct fsf_status_read_buffer *sr_buf = req->data;
  176. struct fsf_link_down_info *ldi =
  177. (struct fsf_link_down_info *) &sr_buf->payload;
  178. switch (sr_buf->status_subtype) {
  179. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  180. zfcp_fsf_link_down_info_eval(req, ldi);
  181. break;
  182. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  183. zfcp_fsf_link_down_info_eval(req, ldi);
  184. break;
  185. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  186. zfcp_fsf_link_down_info_eval(req, NULL);
  187. };
  188. }
  189. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  190. {
  191. struct zfcp_adapter *adapter = req->adapter;
  192. struct fsf_status_read_buffer *sr_buf = req->data;
  193. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  194. zfcp_dbf_hba_fsf_uss("fssrh_1", req);
  195. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  196. zfcp_fsf_req_free(req);
  197. return;
  198. }
  199. zfcp_dbf_hba_fsf_uss("fssrh_4", req);
  200. switch (sr_buf->status_type) {
  201. case FSF_STATUS_READ_PORT_CLOSED:
  202. zfcp_fsf_status_read_port_closed(req);
  203. break;
  204. case FSF_STATUS_READ_INCOMING_ELS:
  205. zfcp_fc_incoming_els(req);
  206. break;
  207. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  208. break;
  209. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  210. dev_warn(&adapter->ccw_device->dev,
  211. "The error threshold for checksum statistics "
  212. "has been exceeded\n");
  213. zfcp_dbf_hba_bit_err("fssrh_3", req);
  214. break;
  215. case FSF_STATUS_READ_LINK_DOWN:
  216. zfcp_fsf_status_read_link_down(req);
  217. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  218. break;
  219. case FSF_STATUS_READ_LINK_UP:
  220. dev_info(&adapter->ccw_device->dev,
  221. "The local link has been restored\n");
  222. /* All ports should be marked as ready to run again */
  223. zfcp_erp_set_adapter_status(adapter,
  224. ZFCP_STATUS_COMMON_RUNNING);
  225. zfcp_erp_adapter_reopen(adapter,
  226. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  227. ZFCP_STATUS_COMMON_ERP_FAILED,
  228. "fssrh_2");
  229. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  230. break;
  231. case FSF_STATUS_READ_NOTIFICATION_LOST:
  232. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  233. zfcp_cfdc_adapter_access_changed(adapter);
  234. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  235. zfcp_fc_conditional_port_scan(adapter);
  236. break;
  237. case FSF_STATUS_READ_CFDC_UPDATED:
  238. zfcp_cfdc_adapter_access_changed(adapter);
  239. break;
  240. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  241. adapter->adapter_features = sr_buf->payload.word[0];
  242. break;
  243. }
  244. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  245. zfcp_fsf_req_free(req);
  246. atomic_inc(&adapter->stat_miss);
  247. queue_work(adapter->work_queue, &adapter->stat_work);
  248. }
  249. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  250. {
  251. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  252. case FSF_SQ_FCP_RSP_AVAILABLE:
  253. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  254. case FSF_SQ_NO_RETRY_POSSIBLE:
  255. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  256. return;
  257. case FSF_SQ_COMMAND_ABORTED:
  258. break;
  259. case FSF_SQ_NO_RECOM:
  260. dev_err(&req->adapter->ccw_device->dev,
  261. "The FCP adapter reported a problem "
  262. "that cannot be recovered\n");
  263. zfcp_qdio_siosl(req->adapter);
  264. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  265. break;
  266. }
  267. /* all non-return stats set FSFREQ_ERROR*/
  268. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  269. }
  270. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  271. {
  272. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  273. return;
  274. switch (req->qtcb->header.fsf_status) {
  275. case FSF_UNKNOWN_COMMAND:
  276. dev_err(&req->adapter->ccw_device->dev,
  277. "The FCP adapter does not recognize the command 0x%x\n",
  278. req->qtcb->header.fsf_command);
  279. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  280. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  281. break;
  282. case FSF_ADAPTER_STATUS_AVAILABLE:
  283. zfcp_fsf_fsfstatus_qual_eval(req);
  284. break;
  285. }
  286. }
  287. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  288. {
  289. struct zfcp_adapter *adapter = req->adapter;
  290. struct fsf_qtcb *qtcb = req->qtcb;
  291. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  292. zfcp_dbf_hba_fsf_response(req);
  293. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  294. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  295. return;
  296. }
  297. switch (qtcb->prefix.prot_status) {
  298. case FSF_PROT_GOOD:
  299. case FSF_PROT_FSF_STATUS_PRESENTED:
  300. return;
  301. case FSF_PROT_QTCB_VERSION_ERROR:
  302. dev_err(&adapter->ccw_device->dev,
  303. "QTCB version 0x%x not supported by FCP adapter "
  304. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  305. psq->word[0], psq->word[1]);
  306. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  307. break;
  308. case FSF_PROT_ERROR_STATE:
  309. case FSF_PROT_SEQ_NUMB_ERROR:
  310. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  311. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  312. break;
  313. case FSF_PROT_UNSUPP_QTCB_TYPE:
  314. dev_err(&adapter->ccw_device->dev,
  315. "The QTCB type is not supported by the FCP adapter\n");
  316. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  317. break;
  318. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  319. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  320. &adapter->status);
  321. break;
  322. case FSF_PROT_DUPLICATE_REQUEST_ID:
  323. dev_err(&adapter->ccw_device->dev,
  324. "0x%Lx is an ambiguous request identifier\n",
  325. (unsigned long long)qtcb->bottom.support.req_handle);
  326. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  327. break;
  328. case FSF_PROT_LINK_DOWN:
  329. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  330. /* go through reopen to flush pending requests */
  331. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  332. break;
  333. case FSF_PROT_REEST_QUEUE:
  334. /* All ports should be marked as ready to run again */
  335. zfcp_erp_set_adapter_status(adapter,
  336. ZFCP_STATUS_COMMON_RUNNING);
  337. zfcp_erp_adapter_reopen(adapter,
  338. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  339. ZFCP_STATUS_COMMON_ERP_FAILED,
  340. "fspse_8");
  341. break;
  342. default:
  343. dev_err(&adapter->ccw_device->dev,
  344. "0x%x is not a valid transfer protocol status\n",
  345. qtcb->prefix.prot_status);
  346. zfcp_qdio_siosl(adapter);
  347. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  348. }
  349. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  350. }
  351. /**
  352. * zfcp_fsf_req_complete - process completion of a FSF request
  353. * @fsf_req: The FSF request that has been completed.
  354. *
  355. * When a request has been completed either from the FCP adapter,
  356. * or it has been dismissed due to a queue shutdown, this function
  357. * is called to process the completion status and trigger further
  358. * events related to the FSF request.
  359. */
  360. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  361. {
  362. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  363. zfcp_fsf_status_read_handler(req);
  364. return;
  365. }
  366. del_timer(&req->timer);
  367. zfcp_fsf_protstatus_eval(req);
  368. zfcp_fsf_fsfstatus_eval(req);
  369. req->handler(req);
  370. if (req->erp_action)
  371. zfcp_erp_notify(req->erp_action, 0);
  372. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  373. zfcp_fsf_req_free(req);
  374. else
  375. complete(&req->completion);
  376. }
  377. /**
  378. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  379. * @adapter: pointer to struct zfcp_adapter
  380. *
  381. * Never ever call this without shutting down the adapter first.
  382. * Otherwise the adapter would continue using and corrupting s390 storage.
  383. * Included BUG_ON() call to ensure this is done.
  384. * ERP is supposed to be the only user of this function.
  385. */
  386. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  387. {
  388. struct zfcp_fsf_req *req, *tmp;
  389. LIST_HEAD(remove_queue);
  390. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  391. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  392. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  393. list_del(&req->list);
  394. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  395. zfcp_fsf_req_complete(req);
  396. }
  397. }
  398. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  399. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  400. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  401. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  402. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  403. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  404. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  405. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  406. {
  407. u32 fdmi_speed = 0;
  408. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  409. fdmi_speed |= FC_PORTSPEED_1GBIT;
  410. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  411. fdmi_speed |= FC_PORTSPEED_2GBIT;
  412. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  413. fdmi_speed |= FC_PORTSPEED_4GBIT;
  414. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  415. fdmi_speed |= FC_PORTSPEED_10GBIT;
  416. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  417. fdmi_speed |= FC_PORTSPEED_8GBIT;
  418. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  419. fdmi_speed |= FC_PORTSPEED_16GBIT;
  420. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  421. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  422. return fdmi_speed;
  423. }
  424. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  425. {
  426. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  427. struct zfcp_adapter *adapter = req->adapter;
  428. struct Scsi_Host *shost = adapter->scsi_host;
  429. struct fc_els_flogi *nsp, *plogi;
  430. /* adjust pointers for missing command code */
  431. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  432. - sizeof(u32));
  433. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  434. - sizeof(u32));
  435. if (req->data)
  436. memcpy(req->data, bottom, sizeof(*bottom));
  437. fc_host_port_name(shost) = nsp->fl_wwpn;
  438. fc_host_node_name(shost) = nsp->fl_wwnn;
  439. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  440. fc_host_speed(shost) =
  441. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  442. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  443. adapter->hydra_version = bottom->adapter_type;
  444. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  445. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  446. (u16)FSF_STATUS_READS_RECOM);
  447. if (fc_host_permanent_port_name(shost) == -1)
  448. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  449. switch (bottom->fc_topology) {
  450. case FSF_TOPO_P2P:
  451. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  452. adapter->peer_wwpn = plogi->fl_wwpn;
  453. adapter->peer_wwnn = plogi->fl_wwnn;
  454. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  455. break;
  456. case FSF_TOPO_FABRIC:
  457. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  458. break;
  459. case FSF_TOPO_AL:
  460. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  461. /* fall through */
  462. default:
  463. dev_err(&adapter->ccw_device->dev,
  464. "Unknown or unsupported arbitrated loop "
  465. "fibre channel topology detected\n");
  466. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  467. return -EIO;
  468. }
  469. zfcp_scsi_set_prot(adapter);
  470. return 0;
  471. }
  472. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  473. {
  474. struct zfcp_adapter *adapter = req->adapter;
  475. struct fsf_qtcb *qtcb = req->qtcb;
  476. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  477. struct Scsi_Host *shost = adapter->scsi_host;
  478. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  479. return;
  480. adapter->fsf_lic_version = bottom->lic_version;
  481. adapter->adapter_features = bottom->adapter_features;
  482. adapter->connection_features = bottom->connection_features;
  483. adapter->peer_wwpn = 0;
  484. adapter->peer_wwnn = 0;
  485. adapter->peer_d_id = 0;
  486. switch (qtcb->header.fsf_status) {
  487. case FSF_GOOD:
  488. if (zfcp_fsf_exchange_config_evaluate(req))
  489. return;
  490. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  491. dev_err(&adapter->ccw_device->dev,
  492. "FCP adapter maximum QTCB size (%d bytes) "
  493. "is too small\n",
  494. bottom->max_qtcb_size);
  495. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  496. return;
  497. }
  498. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  499. &adapter->status);
  500. break;
  501. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  502. fc_host_node_name(shost) = 0;
  503. fc_host_port_name(shost) = 0;
  504. fc_host_port_id(shost) = 0;
  505. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  506. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  507. adapter->hydra_version = 0;
  508. zfcp_fsf_link_down_info_eval(req,
  509. &qtcb->header.fsf_status_qual.link_down_info);
  510. break;
  511. default:
  512. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  513. return;
  514. }
  515. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  516. adapter->hardware_version = bottom->hardware_version;
  517. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  518. min(FC_SERIAL_NUMBER_SIZE, 17));
  519. EBCASC(fc_host_serial_number(shost),
  520. min(FC_SERIAL_NUMBER_SIZE, 17));
  521. }
  522. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  523. dev_err(&adapter->ccw_device->dev,
  524. "The FCP adapter only supports newer "
  525. "control block versions\n");
  526. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  527. return;
  528. }
  529. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  530. dev_err(&adapter->ccw_device->dev,
  531. "The FCP adapter only supports older "
  532. "control block versions\n");
  533. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  534. }
  535. }
  536. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  537. {
  538. struct zfcp_adapter *adapter = req->adapter;
  539. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  540. struct Scsi_Host *shost = adapter->scsi_host;
  541. if (req->data)
  542. memcpy(req->data, bottom, sizeof(*bottom));
  543. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  544. fc_host_permanent_port_name(shost) = bottom->wwpn;
  545. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  546. } else
  547. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  548. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  549. fc_host_supported_speeds(shost) =
  550. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  551. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  552. FC_FC4_LIST_SIZE);
  553. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  554. FC_FC4_LIST_SIZE);
  555. }
  556. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  557. {
  558. struct fsf_qtcb *qtcb = req->qtcb;
  559. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  560. return;
  561. switch (qtcb->header.fsf_status) {
  562. case FSF_GOOD:
  563. zfcp_fsf_exchange_port_evaluate(req);
  564. break;
  565. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  566. zfcp_fsf_exchange_port_evaluate(req);
  567. zfcp_fsf_link_down_info_eval(req,
  568. &qtcb->header.fsf_status_qual.link_down_info);
  569. break;
  570. }
  571. }
  572. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  573. {
  574. struct zfcp_fsf_req *req;
  575. if (likely(pool))
  576. req = mempool_alloc(pool, GFP_ATOMIC);
  577. else
  578. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  579. if (unlikely(!req))
  580. return NULL;
  581. memset(req, 0, sizeof(*req));
  582. req->pool = pool;
  583. return req;
  584. }
  585. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  586. {
  587. struct fsf_qtcb *qtcb;
  588. if (likely(pool))
  589. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  590. else
  591. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  592. if (unlikely(!qtcb))
  593. return NULL;
  594. memset(qtcb, 0, sizeof(*qtcb));
  595. return qtcb;
  596. }
  597. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  598. u32 fsf_cmd, u8 sbtype,
  599. mempool_t *pool)
  600. {
  601. struct zfcp_adapter *adapter = qdio->adapter;
  602. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  603. if (unlikely(!req))
  604. return ERR_PTR(-ENOMEM);
  605. if (adapter->req_no == 0)
  606. adapter->req_no++;
  607. INIT_LIST_HEAD(&req->list);
  608. init_timer(&req->timer);
  609. init_completion(&req->completion);
  610. req->adapter = adapter;
  611. req->fsf_command = fsf_cmd;
  612. req->req_id = adapter->req_no;
  613. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  614. if (likely(pool))
  615. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  616. else
  617. req->qtcb = zfcp_qtcb_alloc(NULL);
  618. if (unlikely(!req->qtcb)) {
  619. zfcp_fsf_req_free(req);
  620. return ERR_PTR(-ENOMEM);
  621. }
  622. req->seq_no = adapter->fsf_req_seq_no;
  623. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  624. req->qtcb->prefix.req_id = req->req_id;
  625. req->qtcb->prefix.ulp_info = 26;
  626. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  627. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  628. req->qtcb->header.req_handle = req->req_id;
  629. req->qtcb->header.fsf_command = req->fsf_command;
  630. }
  631. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  632. req->qtcb, sizeof(struct fsf_qtcb));
  633. return req;
  634. }
  635. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  636. {
  637. struct zfcp_adapter *adapter = req->adapter;
  638. struct zfcp_qdio *qdio = adapter->qdio;
  639. int with_qtcb = (req->qtcb != NULL);
  640. int req_id = req->req_id;
  641. zfcp_reqlist_add(adapter->req_list, req);
  642. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  643. req->issued = get_tod_clock();
  644. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  645. del_timer(&req->timer);
  646. /* lookup request again, list might have changed */
  647. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  648. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  649. return -EIO;
  650. }
  651. /* Don't increase for unsolicited status */
  652. if (with_qtcb)
  653. adapter->fsf_req_seq_no++;
  654. adapter->req_no++;
  655. return 0;
  656. }
  657. /**
  658. * zfcp_fsf_status_read - send status read request
  659. * @adapter: pointer to struct zfcp_adapter
  660. * @req_flags: request flags
  661. * Returns: 0 on success, ERROR otherwise
  662. */
  663. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  664. {
  665. struct zfcp_adapter *adapter = qdio->adapter;
  666. struct zfcp_fsf_req *req;
  667. struct fsf_status_read_buffer *sr_buf;
  668. struct page *page;
  669. int retval = -EIO;
  670. spin_lock_irq(&qdio->req_q_lock);
  671. if (zfcp_qdio_sbal_get(qdio))
  672. goto out;
  673. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  674. adapter->pool.status_read_req);
  675. if (IS_ERR(req)) {
  676. retval = PTR_ERR(req);
  677. goto out;
  678. }
  679. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  680. if (!page) {
  681. retval = -ENOMEM;
  682. goto failed_buf;
  683. }
  684. sr_buf = page_address(page);
  685. memset(sr_buf, 0, sizeof(*sr_buf));
  686. req->data = sr_buf;
  687. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  688. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  689. retval = zfcp_fsf_req_send(req);
  690. if (retval)
  691. goto failed_req_send;
  692. goto out;
  693. failed_req_send:
  694. req->data = NULL;
  695. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  696. failed_buf:
  697. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  698. zfcp_fsf_req_free(req);
  699. out:
  700. spin_unlock_irq(&qdio->req_q_lock);
  701. return retval;
  702. }
  703. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  704. {
  705. struct scsi_device *sdev = req->data;
  706. struct zfcp_scsi_dev *zfcp_sdev;
  707. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  708. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  709. return;
  710. zfcp_sdev = sdev_to_zfcp(sdev);
  711. switch (req->qtcb->header.fsf_status) {
  712. case FSF_PORT_HANDLE_NOT_VALID:
  713. if (fsq->word[0] == fsq->word[1]) {
  714. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  715. "fsafch1");
  716. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  717. }
  718. break;
  719. case FSF_LUN_HANDLE_NOT_VALID:
  720. if (fsq->word[0] == fsq->word[1]) {
  721. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  722. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  723. }
  724. break;
  725. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  726. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  727. break;
  728. case FSF_PORT_BOXED:
  729. zfcp_erp_set_port_status(zfcp_sdev->port,
  730. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  731. zfcp_erp_port_reopen(zfcp_sdev->port,
  732. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  733. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  734. break;
  735. case FSF_LUN_BOXED:
  736. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  737. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  738. "fsafch4");
  739. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  740. break;
  741. case FSF_ADAPTER_STATUS_AVAILABLE:
  742. switch (fsq->word[0]) {
  743. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  744. zfcp_fc_test_link(zfcp_sdev->port);
  745. /* fall through */
  746. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  747. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  748. break;
  749. }
  750. break;
  751. case FSF_GOOD:
  752. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  753. break;
  754. }
  755. }
  756. /**
  757. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  758. * @scmnd: The SCSI command to abort
  759. * Returns: pointer to struct zfcp_fsf_req
  760. */
  761. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  762. {
  763. struct zfcp_fsf_req *req = NULL;
  764. struct scsi_device *sdev = scmnd->device;
  765. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  766. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  767. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  768. spin_lock_irq(&qdio->req_q_lock);
  769. if (zfcp_qdio_sbal_get(qdio))
  770. goto out;
  771. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  772. SBAL_SFLAGS0_TYPE_READ,
  773. qdio->adapter->pool.scsi_abort);
  774. if (IS_ERR(req)) {
  775. req = NULL;
  776. goto out;
  777. }
  778. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  779. ZFCP_STATUS_COMMON_UNBLOCKED)))
  780. goto out_error_free;
  781. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  782. req->data = sdev;
  783. req->handler = zfcp_fsf_abort_fcp_command_handler;
  784. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  785. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  786. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  787. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  788. if (!zfcp_fsf_req_send(req))
  789. goto out;
  790. out_error_free:
  791. zfcp_fsf_req_free(req);
  792. req = NULL;
  793. out:
  794. spin_unlock_irq(&qdio->req_q_lock);
  795. return req;
  796. }
  797. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  798. {
  799. struct zfcp_adapter *adapter = req->adapter;
  800. struct zfcp_fsf_ct_els *ct = req->data;
  801. struct fsf_qtcb_header *header = &req->qtcb->header;
  802. ct->status = -EINVAL;
  803. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  804. goto skip_fsfstatus;
  805. switch (header->fsf_status) {
  806. case FSF_GOOD:
  807. zfcp_dbf_san_res("fsscth2", req);
  808. ct->status = 0;
  809. break;
  810. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  811. zfcp_fsf_class_not_supp(req);
  812. break;
  813. case FSF_ADAPTER_STATUS_AVAILABLE:
  814. switch (header->fsf_status_qual.word[0]){
  815. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  816. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  817. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  818. break;
  819. }
  820. break;
  821. case FSF_ACCESS_DENIED:
  822. break;
  823. case FSF_PORT_BOXED:
  824. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  825. break;
  826. case FSF_PORT_HANDLE_NOT_VALID:
  827. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  828. /* fall through */
  829. case FSF_GENERIC_COMMAND_REJECTED:
  830. case FSF_PAYLOAD_SIZE_MISMATCH:
  831. case FSF_REQUEST_SIZE_TOO_LARGE:
  832. case FSF_RESPONSE_SIZE_TOO_LARGE:
  833. case FSF_SBAL_MISMATCH:
  834. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  835. break;
  836. }
  837. skip_fsfstatus:
  838. if (ct->handler)
  839. ct->handler(ct->handler_data);
  840. }
  841. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  842. struct zfcp_qdio_req *q_req,
  843. struct scatterlist *sg_req,
  844. struct scatterlist *sg_resp)
  845. {
  846. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  847. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  848. zfcp_qdio_set_sbale_last(qdio, q_req);
  849. }
  850. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  851. struct scatterlist *sg_req,
  852. struct scatterlist *sg_resp)
  853. {
  854. struct zfcp_adapter *adapter = req->adapter;
  855. struct zfcp_qdio *qdio = adapter->qdio;
  856. struct fsf_qtcb *qtcb = req->qtcb;
  857. u32 feat = adapter->adapter_features;
  858. if (zfcp_adapter_multi_buffer_active(adapter)) {
  859. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  860. return -EIO;
  861. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  862. return -EIO;
  863. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  864. zfcp_qdio_sbale_count(sg_req));
  865. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  866. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  867. return 0;
  868. }
  869. /* use single, unchained SBAL if it can hold the request */
  870. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  871. zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
  872. sg_req, sg_resp);
  873. return 0;
  874. }
  875. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
  876. return -EOPNOTSUPP;
  877. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  878. return -EIO;
  879. qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
  880. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  881. zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
  882. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  883. return -EIO;
  884. qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
  885. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  886. return 0;
  887. }
  888. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  889. struct scatterlist *sg_req,
  890. struct scatterlist *sg_resp,
  891. unsigned int timeout)
  892. {
  893. int ret;
  894. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  895. if (ret)
  896. return ret;
  897. /* common settings for ct/gs and els requests */
  898. if (timeout > 255)
  899. timeout = 255; /* max value accepted by hardware */
  900. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  901. req->qtcb->bottom.support.timeout = timeout;
  902. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  903. return 0;
  904. }
  905. /**
  906. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  907. * @ct: pointer to struct zfcp_send_ct with data for request
  908. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  909. */
  910. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  911. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  912. unsigned int timeout)
  913. {
  914. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  915. struct zfcp_fsf_req *req;
  916. int ret = -EIO;
  917. spin_lock_irq(&qdio->req_q_lock);
  918. if (zfcp_qdio_sbal_get(qdio))
  919. goto out;
  920. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  921. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  922. if (IS_ERR(req)) {
  923. ret = PTR_ERR(req);
  924. goto out;
  925. }
  926. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  927. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  928. if (ret)
  929. goto failed_send;
  930. req->handler = zfcp_fsf_send_ct_handler;
  931. req->qtcb->header.port_handle = wka_port->handle;
  932. req->data = ct;
  933. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  934. ret = zfcp_fsf_req_send(req);
  935. if (ret)
  936. goto failed_send;
  937. goto out;
  938. failed_send:
  939. zfcp_fsf_req_free(req);
  940. out:
  941. spin_unlock_irq(&qdio->req_q_lock);
  942. return ret;
  943. }
  944. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  945. {
  946. struct zfcp_fsf_ct_els *send_els = req->data;
  947. struct zfcp_port *port = send_els->port;
  948. struct fsf_qtcb_header *header = &req->qtcb->header;
  949. send_els->status = -EINVAL;
  950. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  951. goto skip_fsfstatus;
  952. switch (header->fsf_status) {
  953. case FSF_GOOD:
  954. zfcp_dbf_san_res("fsselh1", req);
  955. send_els->status = 0;
  956. break;
  957. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  958. zfcp_fsf_class_not_supp(req);
  959. break;
  960. case FSF_ADAPTER_STATUS_AVAILABLE:
  961. switch (header->fsf_status_qual.word[0]){
  962. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  963. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  964. case FSF_SQ_RETRY_IF_POSSIBLE:
  965. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  966. break;
  967. }
  968. break;
  969. case FSF_ELS_COMMAND_REJECTED:
  970. case FSF_PAYLOAD_SIZE_MISMATCH:
  971. case FSF_REQUEST_SIZE_TOO_LARGE:
  972. case FSF_RESPONSE_SIZE_TOO_LARGE:
  973. break;
  974. case FSF_ACCESS_DENIED:
  975. if (port) {
  976. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  977. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  978. }
  979. break;
  980. case FSF_SBAL_MISMATCH:
  981. /* should never occur, avoided in zfcp_fsf_send_els */
  982. /* fall through */
  983. default:
  984. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  985. break;
  986. }
  987. skip_fsfstatus:
  988. if (send_els->handler)
  989. send_els->handler(send_els->handler_data);
  990. }
  991. /**
  992. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  993. * @els: pointer to struct zfcp_send_els with data for the command
  994. */
  995. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  996. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  997. {
  998. struct zfcp_fsf_req *req;
  999. struct zfcp_qdio *qdio = adapter->qdio;
  1000. int ret = -EIO;
  1001. spin_lock_irq(&qdio->req_q_lock);
  1002. if (zfcp_qdio_sbal_get(qdio))
  1003. goto out;
  1004. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1005. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1006. if (IS_ERR(req)) {
  1007. ret = PTR_ERR(req);
  1008. goto out;
  1009. }
  1010. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1011. if (!zfcp_adapter_multi_buffer_active(adapter))
  1012. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1013. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1014. if (ret)
  1015. goto failed_send;
  1016. hton24(req->qtcb->bottom.support.d_id, d_id);
  1017. req->handler = zfcp_fsf_send_els_handler;
  1018. req->data = els;
  1019. zfcp_dbf_san_req("fssels1", req, d_id);
  1020. ret = zfcp_fsf_req_send(req);
  1021. if (ret)
  1022. goto failed_send;
  1023. goto out;
  1024. failed_send:
  1025. zfcp_fsf_req_free(req);
  1026. out:
  1027. spin_unlock_irq(&qdio->req_q_lock);
  1028. return ret;
  1029. }
  1030. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1031. {
  1032. struct zfcp_fsf_req *req;
  1033. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1034. int retval = -EIO;
  1035. spin_lock_irq(&qdio->req_q_lock);
  1036. if (zfcp_qdio_sbal_get(qdio))
  1037. goto out;
  1038. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1039. SBAL_SFLAGS0_TYPE_READ,
  1040. qdio->adapter->pool.erp_req);
  1041. if (IS_ERR(req)) {
  1042. retval = PTR_ERR(req);
  1043. goto out;
  1044. }
  1045. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1046. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1047. req->qtcb->bottom.config.feature_selection =
  1048. FSF_FEATURE_CFDC |
  1049. FSF_FEATURE_LUN_SHARING |
  1050. FSF_FEATURE_NOTIFICATION_LOST |
  1051. FSF_FEATURE_UPDATE_ALERT;
  1052. req->erp_action = erp_action;
  1053. req->handler = zfcp_fsf_exchange_config_data_handler;
  1054. erp_action->fsf_req_id = req->req_id;
  1055. zfcp_fsf_start_erp_timer(req);
  1056. retval = zfcp_fsf_req_send(req);
  1057. if (retval) {
  1058. zfcp_fsf_req_free(req);
  1059. erp_action->fsf_req_id = 0;
  1060. }
  1061. out:
  1062. spin_unlock_irq(&qdio->req_q_lock);
  1063. return retval;
  1064. }
  1065. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1066. struct fsf_qtcb_bottom_config *data)
  1067. {
  1068. struct zfcp_fsf_req *req = NULL;
  1069. int retval = -EIO;
  1070. spin_lock_irq(&qdio->req_q_lock);
  1071. if (zfcp_qdio_sbal_get(qdio))
  1072. goto out_unlock;
  1073. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1074. SBAL_SFLAGS0_TYPE_READ, NULL);
  1075. if (IS_ERR(req)) {
  1076. retval = PTR_ERR(req);
  1077. goto out_unlock;
  1078. }
  1079. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1080. req->handler = zfcp_fsf_exchange_config_data_handler;
  1081. req->qtcb->bottom.config.feature_selection =
  1082. FSF_FEATURE_CFDC |
  1083. FSF_FEATURE_LUN_SHARING |
  1084. FSF_FEATURE_NOTIFICATION_LOST |
  1085. FSF_FEATURE_UPDATE_ALERT;
  1086. if (data)
  1087. req->data = data;
  1088. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1089. retval = zfcp_fsf_req_send(req);
  1090. spin_unlock_irq(&qdio->req_q_lock);
  1091. if (!retval)
  1092. wait_for_completion(&req->completion);
  1093. zfcp_fsf_req_free(req);
  1094. return retval;
  1095. out_unlock:
  1096. spin_unlock_irq(&qdio->req_q_lock);
  1097. return retval;
  1098. }
  1099. /**
  1100. * zfcp_fsf_exchange_port_data - request information about local port
  1101. * @erp_action: ERP action for the adapter for which port data is requested
  1102. * Returns: 0 on success, error otherwise
  1103. */
  1104. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1105. {
  1106. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1107. struct zfcp_fsf_req *req;
  1108. int retval = -EIO;
  1109. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1110. return -EOPNOTSUPP;
  1111. spin_lock_irq(&qdio->req_q_lock);
  1112. if (zfcp_qdio_sbal_get(qdio))
  1113. goto out;
  1114. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1115. SBAL_SFLAGS0_TYPE_READ,
  1116. qdio->adapter->pool.erp_req);
  1117. if (IS_ERR(req)) {
  1118. retval = PTR_ERR(req);
  1119. goto out;
  1120. }
  1121. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1122. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1123. req->handler = zfcp_fsf_exchange_port_data_handler;
  1124. req->erp_action = erp_action;
  1125. erp_action->fsf_req_id = req->req_id;
  1126. zfcp_fsf_start_erp_timer(req);
  1127. retval = zfcp_fsf_req_send(req);
  1128. if (retval) {
  1129. zfcp_fsf_req_free(req);
  1130. erp_action->fsf_req_id = 0;
  1131. }
  1132. out:
  1133. spin_unlock_irq(&qdio->req_q_lock);
  1134. return retval;
  1135. }
  1136. /**
  1137. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1138. * @qdio: pointer to struct zfcp_qdio
  1139. * @data: pointer to struct fsf_qtcb_bottom_port
  1140. * Returns: 0 on success, error otherwise
  1141. */
  1142. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1143. struct fsf_qtcb_bottom_port *data)
  1144. {
  1145. struct zfcp_fsf_req *req = NULL;
  1146. int retval = -EIO;
  1147. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1148. return -EOPNOTSUPP;
  1149. spin_lock_irq(&qdio->req_q_lock);
  1150. if (zfcp_qdio_sbal_get(qdio))
  1151. goto out_unlock;
  1152. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1153. SBAL_SFLAGS0_TYPE_READ, NULL);
  1154. if (IS_ERR(req)) {
  1155. retval = PTR_ERR(req);
  1156. goto out_unlock;
  1157. }
  1158. if (data)
  1159. req->data = data;
  1160. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1161. req->handler = zfcp_fsf_exchange_port_data_handler;
  1162. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1163. retval = zfcp_fsf_req_send(req);
  1164. spin_unlock_irq(&qdio->req_q_lock);
  1165. if (!retval)
  1166. wait_for_completion(&req->completion);
  1167. zfcp_fsf_req_free(req);
  1168. return retval;
  1169. out_unlock:
  1170. spin_unlock_irq(&qdio->req_q_lock);
  1171. return retval;
  1172. }
  1173. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1174. {
  1175. struct zfcp_port *port = req->data;
  1176. struct fsf_qtcb_header *header = &req->qtcb->header;
  1177. struct fc_els_flogi *plogi;
  1178. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1179. goto out;
  1180. switch (header->fsf_status) {
  1181. case FSF_PORT_ALREADY_OPEN:
  1182. break;
  1183. case FSF_ACCESS_DENIED:
  1184. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1185. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1186. break;
  1187. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1188. dev_warn(&req->adapter->ccw_device->dev,
  1189. "Not enough FCP adapter resources to open "
  1190. "remote port 0x%016Lx\n",
  1191. (unsigned long long)port->wwpn);
  1192. zfcp_erp_set_port_status(port,
  1193. ZFCP_STATUS_COMMON_ERP_FAILED);
  1194. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1195. break;
  1196. case FSF_ADAPTER_STATUS_AVAILABLE:
  1197. switch (header->fsf_status_qual.word[0]) {
  1198. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1199. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1200. case FSF_SQ_NO_RETRY_POSSIBLE:
  1201. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1202. break;
  1203. }
  1204. break;
  1205. case FSF_GOOD:
  1206. port->handle = header->port_handle;
  1207. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1208. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1209. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1210. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1211. &port->status);
  1212. /* check whether D_ID has changed during open */
  1213. /*
  1214. * FIXME: This check is not airtight, as the FCP channel does
  1215. * not monitor closures of target port connections caused on
  1216. * the remote side. Thus, they might miss out on invalidating
  1217. * locally cached WWPNs (and other N_Port parameters) of gone
  1218. * target ports. So, our heroic attempt to make things safe
  1219. * could be undermined by 'open port' response data tagged with
  1220. * obsolete WWPNs. Another reason to monitor potential
  1221. * connection closures ourself at least (by interpreting
  1222. * incoming ELS' and unsolicited status). It just crosses my
  1223. * mind that one should be able to cross-check by means of
  1224. * another GID_PN straight after a port has been opened.
  1225. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1226. */
  1227. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1228. if (req->qtcb->bottom.support.els1_length >=
  1229. FSF_PLOGI_MIN_LEN)
  1230. zfcp_fc_plogi_evaluate(port, plogi);
  1231. break;
  1232. case FSF_UNKNOWN_OP_SUBTYPE:
  1233. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1234. break;
  1235. }
  1236. out:
  1237. put_device(&port->dev);
  1238. }
  1239. /**
  1240. * zfcp_fsf_open_port - create and send open port request
  1241. * @erp_action: pointer to struct zfcp_erp_action
  1242. * Returns: 0 on success, error otherwise
  1243. */
  1244. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1245. {
  1246. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1247. struct zfcp_port *port = erp_action->port;
  1248. struct zfcp_fsf_req *req;
  1249. int retval = -EIO;
  1250. spin_lock_irq(&qdio->req_q_lock);
  1251. if (zfcp_qdio_sbal_get(qdio))
  1252. goto out;
  1253. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1254. SBAL_SFLAGS0_TYPE_READ,
  1255. qdio->adapter->pool.erp_req);
  1256. if (IS_ERR(req)) {
  1257. retval = PTR_ERR(req);
  1258. goto out;
  1259. }
  1260. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1261. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1262. req->handler = zfcp_fsf_open_port_handler;
  1263. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1264. req->data = port;
  1265. req->erp_action = erp_action;
  1266. erp_action->fsf_req_id = req->req_id;
  1267. get_device(&port->dev);
  1268. zfcp_fsf_start_erp_timer(req);
  1269. retval = zfcp_fsf_req_send(req);
  1270. if (retval) {
  1271. zfcp_fsf_req_free(req);
  1272. erp_action->fsf_req_id = 0;
  1273. put_device(&port->dev);
  1274. }
  1275. out:
  1276. spin_unlock_irq(&qdio->req_q_lock);
  1277. return retval;
  1278. }
  1279. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1280. {
  1281. struct zfcp_port *port = req->data;
  1282. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1283. return;
  1284. switch (req->qtcb->header.fsf_status) {
  1285. case FSF_PORT_HANDLE_NOT_VALID:
  1286. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1287. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1288. break;
  1289. case FSF_ADAPTER_STATUS_AVAILABLE:
  1290. break;
  1291. case FSF_GOOD:
  1292. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1293. break;
  1294. }
  1295. }
  1296. /**
  1297. * zfcp_fsf_close_port - create and send close port request
  1298. * @erp_action: pointer to struct zfcp_erp_action
  1299. * Returns: 0 on success, error otherwise
  1300. */
  1301. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1302. {
  1303. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1304. struct zfcp_fsf_req *req;
  1305. int retval = -EIO;
  1306. spin_lock_irq(&qdio->req_q_lock);
  1307. if (zfcp_qdio_sbal_get(qdio))
  1308. goto out;
  1309. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1310. SBAL_SFLAGS0_TYPE_READ,
  1311. qdio->adapter->pool.erp_req);
  1312. if (IS_ERR(req)) {
  1313. retval = PTR_ERR(req);
  1314. goto out;
  1315. }
  1316. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1317. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1318. req->handler = zfcp_fsf_close_port_handler;
  1319. req->data = erp_action->port;
  1320. req->erp_action = erp_action;
  1321. req->qtcb->header.port_handle = erp_action->port->handle;
  1322. erp_action->fsf_req_id = req->req_id;
  1323. zfcp_fsf_start_erp_timer(req);
  1324. retval = zfcp_fsf_req_send(req);
  1325. if (retval) {
  1326. zfcp_fsf_req_free(req);
  1327. erp_action->fsf_req_id = 0;
  1328. }
  1329. out:
  1330. spin_unlock_irq(&qdio->req_q_lock);
  1331. return retval;
  1332. }
  1333. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1334. {
  1335. struct zfcp_fc_wka_port *wka_port = req->data;
  1336. struct fsf_qtcb_header *header = &req->qtcb->header;
  1337. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1338. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1339. goto out;
  1340. }
  1341. switch (header->fsf_status) {
  1342. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1343. dev_warn(&req->adapter->ccw_device->dev,
  1344. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1345. /* fall through */
  1346. case FSF_ADAPTER_STATUS_AVAILABLE:
  1347. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1348. /* fall through */
  1349. case FSF_ACCESS_DENIED:
  1350. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1351. break;
  1352. case FSF_GOOD:
  1353. wka_port->handle = header->port_handle;
  1354. /* fall through */
  1355. case FSF_PORT_ALREADY_OPEN:
  1356. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1357. }
  1358. out:
  1359. wake_up(&wka_port->completion_wq);
  1360. }
  1361. /**
  1362. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1363. * @wka_port: pointer to struct zfcp_fc_wka_port
  1364. * Returns: 0 on success, error otherwise
  1365. */
  1366. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1367. {
  1368. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1369. struct zfcp_fsf_req *req;
  1370. int retval = -EIO;
  1371. spin_lock_irq(&qdio->req_q_lock);
  1372. if (zfcp_qdio_sbal_get(qdio))
  1373. goto out;
  1374. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1375. SBAL_SFLAGS0_TYPE_READ,
  1376. qdio->adapter->pool.erp_req);
  1377. if (IS_ERR(req)) {
  1378. retval = PTR_ERR(req);
  1379. goto out;
  1380. }
  1381. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1382. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1383. req->handler = zfcp_fsf_open_wka_port_handler;
  1384. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1385. req->data = wka_port;
  1386. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1387. retval = zfcp_fsf_req_send(req);
  1388. if (retval)
  1389. zfcp_fsf_req_free(req);
  1390. out:
  1391. spin_unlock_irq(&qdio->req_q_lock);
  1392. return retval;
  1393. }
  1394. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1395. {
  1396. struct zfcp_fc_wka_port *wka_port = req->data;
  1397. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1398. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1399. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1400. }
  1401. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1402. wake_up(&wka_port->completion_wq);
  1403. }
  1404. /**
  1405. * zfcp_fsf_close_wka_port - create and send close wka port request
  1406. * @wka_port: WKA port to open
  1407. * Returns: 0 on success, error otherwise
  1408. */
  1409. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1410. {
  1411. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1412. struct zfcp_fsf_req *req;
  1413. int retval = -EIO;
  1414. spin_lock_irq(&qdio->req_q_lock);
  1415. if (zfcp_qdio_sbal_get(qdio))
  1416. goto out;
  1417. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1418. SBAL_SFLAGS0_TYPE_READ,
  1419. qdio->adapter->pool.erp_req);
  1420. if (IS_ERR(req)) {
  1421. retval = PTR_ERR(req);
  1422. goto out;
  1423. }
  1424. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1425. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1426. req->handler = zfcp_fsf_close_wka_port_handler;
  1427. req->data = wka_port;
  1428. req->qtcb->header.port_handle = wka_port->handle;
  1429. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1430. retval = zfcp_fsf_req_send(req);
  1431. if (retval)
  1432. zfcp_fsf_req_free(req);
  1433. out:
  1434. spin_unlock_irq(&qdio->req_q_lock);
  1435. return retval;
  1436. }
  1437. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1438. {
  1439. struct zfcp_port *port = req->data;
  1440. struct fsf_qtcb_header *header = &req->qtcb->header;
  1441. struct scsi_device *sdev;
  1442. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1443. return;
  1444. switch (header->fsf_status) {
  1445. case FSF_PORT_HANDLE_NOT_VALID:
  1446. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1447. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1448. break;
  1449. case FSF_ACCESS_DENIED:
  1450. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1451. break;
  1452. case FSF_PORT_BOXED:
  1453. /* can't use generic zfcp_erp_modify_port_status because
  1454. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1455. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1456. shost_for_each_device(sdev, port->adapter->scsi_host)
  1457. if (sdev_to_zfcp(sdev)->port == port)
  1458. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1459. &sdev_to_zfcp(sdev)->status);
  1460. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1461. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1462. "fscpph2");
  1463. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1464. break;
  1465. case FSF_ADAPTER_STATUS_AVAILABLE:
  1466. switch (header->fsf_status_qual.word[0]) {
  1467. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1468. /* fall through */
  1469. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1470. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1471. break;
  1472. }
  1473. break;
  1474. case FSF_GOOD:
  1475. /* can't use generic zfcp_erp_modify_port_status because
  1476. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1477. */
  1478. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1479. shost_for_each_device(sdev, port->adapter->scsi_host)
  1480. if (sdev_to_zfcp(sdev)->port == port)
  1481. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1482. &sdev_to_zfcp(sdev)->status);
  1483. break;
  1484. }
  1485. }
  1486. /**
  1487. * zfcp_fsf_close_physical_port - close physical port
  1488. * @erp_action: pointer to struct zfcp_erp_action
  1489. * Returns: 0 on success
  1490. */
  1491. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1492. {
  1493. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1494. struct zfcp_fsf_req *req;
  1495. int retval = -EIO;
  1496. spin_lock_irq(&qdio->req_q_lock);
  1497. if (zfcp_qdio_sbal_get(qdio))
  1498. goto out;
  1499. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1500. SBAL_SFLAGS0_TYPE_READ,
  1501. qdio->adapter->pool.erp_req);
  1502. if (IS_ERR(req)) {
  1503. retval = PTR_ERR(req);
  1504. goto out;
  1505. }
  1506. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1507. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1508. req->data = erp_action->port;
  1509. req->qtcb->header.port_handle = erp_action->port->handle;
  1510. req->erp_action = erp_action;
  1511. req->handler = zfcp_fsf_close_physical_port_handler;
  1512. erp_action->fsf_req_id = req->req_id;
  1513. zfcp_fsf_start_erp_timer(req);
  1514. retval = zfcp_fsf_req_send(req);
  1515. if (retval) {
  1516. zfcp_fsf_req_free(req);
  1517. erp_action->fsf_req_id = 0;
  1518. }
  1519. out:
  1520. spin_unlock_irq(&qdio->req_q_lock);
  1521. return retval;
  1522. }
  1523. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1524. {
  1525. struct zfcp_adapter *adapter = req->adapter;
  1526. struct scsi_device *sdev = req->data;
  1527. struct zfcp_scsi_dev *zfcp_sdev;
  1528. struct fsf_qtcb_header *header = &req->qtcb->header;
  1529. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1530. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1531. return;
  1532. zfcp_sdev = sdev_to_zfcp(sdev);
  1533. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1534. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1535. ZFCP_STATUS_LUN_SHARED |
  1536. ZFCP_STATUS_LUN_READONLY,
  1537. &zfcp_sdev->status);
  1538. switch (header->fsf_status) {
  1539. case FSF_PORT_HANDLE_NOT_VALID:
  1540. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1541. /* fall through */
  1542. case FSF_LUN_ALREADY_OPEN:
  1543. break;
  1544. case FSF_ACCESS_DENIED:
  1545. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1546. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1547. break;
  1548. case FSF_PORT_BOXED:
  1549. zfcp_erp_set_port_status(zfcp_sdev->port,
  1550. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1551. zfcp_erp_port_reopen(zfcp_sdev->port,
  1552. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1553. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1554. break;
  1555. case FSF_LUN_SHARING_VIOLATION:
  1556. zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
  1557. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1558. break;
  1559. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1560. dev_warn(&adapter->ccw_device->dev,
  1561. "No handle is available for LUN "
  1562. "0x%016Lx on port 0x%016Lx\n",
  1563. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1564. (unsigned long long)zfcp_sdev->port->wwpn);
  1565. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1566. /* fall through */
  1567. case FSF_INVALID_COMMAND_OPTION:
  1568. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1569. break;
  1570. case FSF_ADAPTER_STATUS_AVAILABLE:
  1571. switch (header->fsf_status_qual.word[0]) {
  1572. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1573. zfcp_fc_test_link(zfcp_sdev->port);
  1574. /* fall through */
  1575. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1576. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1577. break;
  1578. }
  1579. break;
  1580. case FSF_GOOD:
  1581. zfcp_sdev->lun_handle = header->lun_handle;
  1582. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1583. zfcp_cfdc_open_lun_eval(sdev, bottom);
  1584. break;
  1585. }
  1586. }
  1587. /**
  1588. * zfcp_fsf_open_lun - open LUN
  1589. * @erp_action: pointer to struct zfcp_erp_action
  1590. * Returns: 0 on success, error otherwise
  1591. */
  1592. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1593. {
  1594. struct zfcp_adapter *adapter = erp_action->adapter;
  1595. struct zfcp_qdio *qdio = adapter->qdio;
  1596. struct zfcp_fsf_req *req;
  1597. int retval = -EIO;
  1598. spin_lock_irq(&qdio->req_q_lock);
  1599. if (zfcp_qdio_sbal_get(qdio))
  1600. goto out;
  1601. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1602. SBAL_SFLAGS0_TYPE_READ,
  1603. adapter->pool.erp_req);
  1604. if (IS_ERR(req)) {
  1605. retval = PTR_ERR(req);
  1606. goto out;
  1607. }
  1608. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1609. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1610. req->qtcb->header.port_handle = erp_action->port->handle;
  1611. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1612. req->handler = zfcp_fsf_open_lun_handler;
  1613. req->data = erp_action->sdev;
  1614. req->erp_action = erp_action;
  1615. erp_action->fsf_req_id = req->req_id;
  1616. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1617. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1618. zfcp_fsf_start_erp_timer(req);
  1619. retval = zfcp_fsf_req_send(req);
  1620. if (retval) {
  1621. zfcp_fsf_req_free(req);
  1622. erp_action->fsf_req_id = 0;
  1623. }
  1624. out:
  1625. spin_unlock_irq(&qdio->req_q_lock);
  1626. return retval;
  1627. }
  1628. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1629. {
  1630. struct scsi_device *sdev = req->data;
  1631. struct zfcp_scsi_dev *zfcp_sdev;
  1632. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1633. return;
  1634. zfcp_sdev = sdev_to_zfcp(sdev);
  1635. switch (req->qtcb->header.fsf_status) {
  1636. case FSF_PORT_HANDLE_NOT_VALID:
  1637. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1638. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1639. break;
  1640. case FSF_LUN_HANDLE_NOT_VALID:
  1641. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1642. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1643. break;
  1644. case FSF_PORT_BOXED:
  1645. zfcp_erp_set_port_status(zfcp_sdev->port,
  1646. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1647. zfcp_erp_port_reopen(zfcp_sdev->port,
  1648. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1649. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1650. break;
  1651. case FSF_ADAPTER_STATUS_AVAILABLE:
  1652. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1653. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1654. zfcp_fc_test_link(zfcp_sdev->port);
  1655. /* fall through */
  1656. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1657. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1658. break;
  1659. }
  1660. break;
  1661. case FSF_GOOD:
  1662. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1663. break;
  1664. }
  1665. }
  1666. /**
  1667. * zfcp_fsf_close_LUN - close LUN
  1668. * @erp_action: pointer to erp_action triggering the "close LUN"
  1669. * Returns: 0 on success, error otherwise
  1670. */
  1671. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1672. {
  1673. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1674. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1675. struct zfcp_fsf_req *req;
  1676. int retval = -EIO;
  1677. spin_lock_irq(&qdio->req_q_lock);
  1678. if (zfcp_qdio_sbal_get(qdio))
  1679. goto out;
  1680. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1681. SBAL_SFLAGS0_TYPE_READ,
  1682. qdio->adapter->pool.erp_req);
  1683. if (IS_ERR(req)) {
  1684. retval = PTR_ERR(req);
  1685. goto out;
  1686. }
  1687. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1688. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1689. req->qtcb->header.port_handle = erp_action->port->handle;
  1690. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1691. req->handler = zfcp_fsf_close_lun_handler;
  1692. req->data = erp_action->sdev;
  1693. req->erp_action = erp_action;
  1694. erp_action->fsf_req_id = req->req_id;
  1695. zfcp_fsf_start_erp_timer(req);
  1696. retval = zfcp_fsf_req_send(req);
  1697. if (retval) {
  1698. zfcp_fsf_req_free(req);
  1699. erp_action->fsf_req_id = 0;
  1700. }
  1701. out:
  1702. spin_unlock_irq(&qdio->req_q_lock);
  1703. return retval;
  1704. }
  1705. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1706. {
  1707. lat_rec->sum += lat;
  1708. lat_rec->min = min(lat_rec->min, lat);
  1709. lat_rec->max = max(lat_rec->max, lat);
  1710. }
  1711. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1712. {
  1713. struct fsf_qual_latency_info *lat_in;
  1714. struct latency_cont *lat = NULL;
  1715. struct zfcp_scsi_dev *zfcp_sdev;
  1716. struct zfcp_blk_drv_data blktrc;
  1717. int ticks = req->adapter->timer_ticks;
  1718. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1719. blktrc.flags = 0;
  1720. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1721. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1722. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1723. blktrc.inb_usage = 0;
  1724. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1725. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1726. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1727. zfcp_sdev = sdev_to_zfcp(scsi->device);
  1728. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1729. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1730. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1731. switch (req->qtcb->bottom.io.data_direction) {
  1732. case FSF_DATADIR_DIF_READ_STRIP:
  1733. case FSF_DATADIR_DIF_READ_CONVERT:
  1734. case FSF_DATADIR_READ:
  1735. lat = &zfcp_sdev->latencies.read;
  1736. break;
  1737. case FSF_DATADIR_DIF_WRITE_INSERT:
  1738. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1739. case FSF_DATADIR_WRITE:
  1740. lat = &zfcp_sdev->latencies.write;
  1741. break;
  1742. case FSF_DATADIR_CMND:
  1743. lat = &zfcp_sdev->latencies.cmd;
  1744. break;
  1745. }
  1746. if (lat) {
  1747. spin_lock(&zfcp_sdev->latencies.lock);
  1748. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1749. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1750. lat->counter++;
  1751. spin_unlock(&zfcp_sdev->latencies.lock);
  1752. }
  1753. }
  1754. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1755. sizeof(blktrc));
  1756. }
  1757. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1758. {
  1759. struct scsi_cmnd *scmnd = req->data;
  1760. struct scsi_device *sdev = scmnd->device;
  1761. struct zfcp_scsi_dev *zfcp_sdev;
  1762. struct fsf_qtcb_header *header = &req->qtcb->header;
  1763. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1764. return;
  1765. zfcp_sdev = sdev_to_zfcp(sdev);
  1766. switch (header->fsf_status) {
  1767. case FSF_HANDLE_MISMATCH:
  1768. case FSF_PORT_HANDLE_NOT_VALID:
  1769. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1771. break;
  1772. case FSF_FCPLUN_NOT_VALID:
  1773. case FSF_LUN_HANDLE_NOT_VALID:
  1774. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1775. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1776. break;
  1777. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1778. zfcp_fsf_class_not_supp(req);
  1779. break;
  1780. case FSF_ACCESS_DENIED:
  1781. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1782. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1783. break;
  1784. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1785. dev_err(&req->adapter->ccw_device->dev,
  1786. "Incorrect direction %d, LUN 0x%016Lx on port "
  1787. "0x%016Lx closed\n",
  1788. req->qtcb->bottom.io.data_direction,
  1789. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1790. (unsigned long long)zfcp_sdev->port->wwpn);
  1791. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1792. "fssfch3");
  1793. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1794. break;
  1795. case FSF_CMND_LENGTH_NOT_VALID:
  1796. dev_err(&req->adapter->ccw_device->dev,
  1797. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1798. "port 0x%016Lx closed\n",
  1799. req->qtcb->bottom.io.fcp_cmnd_length,
  1800. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1801. (unsigned long long)zfcp_sdev->port->wwpn);
  1802. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1803. "fssfch4");
  1804. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1805. break;
  1806. case FSF_PORT_BOXED:
  1807. zfcp_erp_set_port_status(zfcp_sdev->port,
  1808. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1809. zfcp_erp_port_reopen(zfcp_sdev->port,
  1810. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1811. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1812. break;
  1813. case FSF_LUN_BOXED:
  1814. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1815. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1816. "fssfch6");
  1817. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1818. break;
  1819. case FSF_ADAPTER_STATUS_AVAILABLE:
  1820. if (header->fsf_status_qual.word[0] ==
  1821. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1822. zfcp_fc_test_link(zfcp_sdev->port);
  1823. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1824. break;
  1825. }
  1826. }
  1827. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1828. {
  1829. struct scsi_cmnd *scpnt;
  1830. struct fcp_resp_with_ext *fcp_rsp;
  1831. unsigned long flags;
  1832. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1833. scpnt = req->data;
  1834. if (unlikely(!scpnt)) {
  1835. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1836. return;
  1837. }
  1838. zfcp_fsf_fcp_handler_common(req);
  1839. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1840. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1841. goto skip_fsfstatus;
  1842. }
  1843. switch (req->qtcb->header.fsf_status) {
  1844. case FSF_INCONSISTENT_PROT_DATA:
  1845. case FSF_INVALID_PROT_PARM:
  1846. set_host_byte(scpnt, DID_ERROR);
  1847. goto skip_fsfstatus;
  1848. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1849. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1850. goto skip_fsfstatus;
  1851. case FSF_APP_TAG_CHECK_FAILURE:
  1852. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1853. goto skip_fsfstatus;
  1854. case FSF_REF_TAG_CHECK_FAILURE:
  1855. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1856. goto skip_fsfstatus;
  1857. }
  1858. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1859. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1860. skip_fsfstatus:
  1861. zfcp_fsf_req_trace(req, scpnt);
  1862. zfcp_dbf_scsi_result(scpnt, req);
  1863. scpnt->host_scribble = NULL;
  1864. (scpnt->scsi_done) (scpnt);
  1865. /*
  1866. * We must hold this lock until scsi_done has been called.
  1867. * Otherwise we may call scsi_done after abort regarding this
  1868. * command has completed.
  1869. * Note: scsi_done must not block!
  1870. */
  1871. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1872. }
  1873. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1874. {
  1875. switch (scsi_get_prot_op(scsi_cmnd)) {
  1876. case SCSI_PROT_NORMAL:
  1877. switch (scsi_cmnd->sc_data_direction) {
  1878. case DMA_NONE:
  1879. *data_dir = FSF_DATADIR_CMND;
  1880. break;
  1881. case DMA_FROM_DEVICE:
  1882. *data_dir = FSF_DATADIR_READ;
  1883. break;
  1884. case DMA_TO_DEVICE:
  1885. *data_dir = FSF_DATADIR_WRITE;
  1886. break;
  1887. case DMA_BIDIRECTIONAL:
  1888. return -EINVAL;
  1889. }
  1890. break;
  1891. case SCSI_PROT_READ_STRIP:
  1892. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1893. break;
  1894. case SCSI_PROT_WRITE_INSERT:
  1895. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1896. break;
  1897. case SCSI_PROT_READ_PASS:
  1898. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1899. break;
  1900. case SCSI_PROT_WRITE_PASS:
  1901. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1902. break;
  1903. default:
  1904. return -EINVAL;
  1905. }
  1906. return 0;
  1907. }
  1908. /**
  1909. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1910. * @scsi_cmnd: scsi command to be sent
  1911. */
  1912. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1913. {
  1914. struct zfcp_fsf_req *req;
  1915. struct fcp_cmnd *fcp_cmnd;
  1916. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1917. int retval = -EIO;
  1918. struct scsi_device *sdev = scsi_cmnd->device;
  1919. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1920. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1921. struct zfcp_qdio *qdio = adapter->qdio;
  1922. struct fsf_qtcb_bottom_io *io;
  1923. unsigned long flags;
  1924. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1925. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1926. return -EBUSY;
  1927. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1928. if (atomic_read(&qdio->req_q_free) <= 0) {
  1929. atomic_inc(&qdio->req_q_full);
  1930. goto out;
  1931. }
  1932. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1933. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1934. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1935. sbtype, adapter->pool.scsi_req);
  1936. if (IS_ERR(req)) {
  1937. retval = PTR_ERR(req);
  1938. goto out;
  1939. }
  1940. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1941. io = &req->qtcb->bottom.io;
  1942. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1943. req->data = scsi_cmnd;
  1944. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1945. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1946. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1947. io->service_class = FSF_CLASS_3;
  1948. io->fcp_cmnd_length = FCP_CMND_LEN;
  1949. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1950. io->data_block_length = scsi_cmnd->device->sector_size;
  1951. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1952. }
  1953. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1954. goto failed_scsi_cmnd;
  1955. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1956. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1957. if (scsi_prot_sg_count(scsi_cmnd)) {
  1958. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1959. scsi_prot_sg_count(scsi_cmnd));
  1960. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1961. scsi_prot_sglist(scsi_cmnd));
  1962. if (retval)
  1963. goto failed_scsi_cmnd;
  1964. io->prot_data_length = zfcp_qdio_real_bytes(
  1965. scsi_prot_sglist(scsi_cmnd));
  1966. }
  1967. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1968. scsi_sglist(scsi_cmnd));
  1969. if (unlikely(retval))
  1970. goto failed_scsi_cmnd;
  1971. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1972. if (zfcp_adapter_multi_buffer_active(adapter))
  1973. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1974. retval = zfcp_fsf_req_send(req);
  1975. if (unlikely(retval))
  1976. goto failed_scsi_cmnd;
  1977. goto out;
  1978. failed_scsi_cmnd:
  1979. zfcp_fsf_req_free(req);
  1980. scsi_cmnd->host_scribble = NULL;
  1981. out:
  1982. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1983. return retval;
  1984. }
  1985. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1986. {
  1987. struct fcp_resp_with_ext *fcp_rsp;
  1988. struct fcp_resp_rsp_info *rsp_info;
  1989. zfcp_fsf_fcp_handler_common(req);
  1990. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1991. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1992. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1993. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1994. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1995. }
  1996. /**
  1997. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1998. * @scmnd: SCSI command to send the task management command for
  1999. * @tm_flags: unsigned byte for task management flags
  2000. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2001. */
  2002. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  2003. u8 tm_flags)
  2004. {
  2005. struct zfcp_fsf_req *req = NULL;
  2006. struct fcp_cmnd *fcp_cmnd;
  2007. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  2008. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  2009. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  2010. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2011. return NULL;
  2012. spin_lock_irq(&qdio->req_q_lock);
  2013. if (zfcp_qdio_sbal_get(qdio))
  2014. goto out;
  2015. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2016. SBAL_SFLAGS0_TYPE_WRITE,
  2017. qdio->adapter->pool.scsi_req);
  2018. if (IS_ERR(req)) {
  2019. req = NULL;
  2020. goto out;
  2021. }
  2022. req->data = scmnd;
  2023. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2024. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2025. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2026. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2027. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2028. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2029. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2030. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2031. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2032. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2033. if (!zfcp_fsf_req_send(req))
  2034. goto out;
  2035. zfcp_fsf_req_free(req);
  2036. req = NULL;
  2037. out:
  2038. spin_unlock_irq(&qdio->req_q_lock);
  2039. return req;
  2040. }
  2041. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2042. {
  2043. }
  2044. /**
  2045. * zfcp_fsf_control_file - control file upload/download
  2046. * @adapter: pointer to struct zfcp_adapter
  2047. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2048. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2049. */
  2050. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2051. struct zfcp_fsf_cfdc *fsf_cfdc)
  2052. {
  2053. struct zfcp_qdio *qdio = adapter->qdio;
  2054. struct zfcp_fsf_req *req = NULL;
  2055. struct fsf_qtcb_bottom_support *bottom;
  2056. int retval = -EIO;
  2057. u8 direction;
  2058. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2059. return ERR_PTR(-EOPNOTSUPP);
  2060. switch (fsf_cfdc->command) {
  2061. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2062. direction = SBAL_SFLAGS0_TYPE_WRITE;
  2063. break;
  2064. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2065. direction = SBAL_SFLAGS0_TYPE_READ;
  2066. break;
  2067. default:
  2068. return ERR_PTR(-EINVAL);
  2069. }
  2070. spin_lock_irq(&qdio->req_q_lock);
  2071. if (zfcp_qdio_sbal_get(qdio))
  2072. goto out;
  2073. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2074. if (IS_ERR(req)) {
  2075. retval = -EPERM;
  2076. goto out;
  2077. }
  2078. req->handler = zfcp_fsf_control_file_handler;
  2079. bottom = &req->qtcb->bottom.support;
  2080. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2081. bottom->option = fsf_cfdc->option;
  2082. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2083. if (retval ||
  2084. (zfcp_qdio_real_bytes(fsf_cfdc->sg) != ZFCP_CFDC_MAX_SIZE)) {
  2085. zfcp_fsf_req_free(req);
  2086. retval = -EIO;
  2087. goto out;
  2088. }
  2089. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2090. if (zfcp_adapter_multi_buffer_active(adapter))
  2091. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  2092. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2093. retval = zfcp_fsf_req_send(req);
  2094. out:
  2095. spin_unlock_irq(&qdio->req_q_lock);
  2096. if (!retval) {
  2097. wait_for_completion(&req->completion);
  2098. return req;
  2099. }
  2100. return ERR_PTR(retval);
  2101. }
  2102. /**
  2103. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2104. * @adapter: pointer to struct zfcp_adapter
  2105. * @sbal_idx: response queue index of SBAL to be processed
  2106. */
  2107. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2108. {
  2109. struct zfcp_adapter *adapter = qdio->adapter;
  2110. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2111. struct qdio_buffer_element *sbale;
  2112. struct zfcp_fsf_req *fsf_req;
  2113. unsigned long req_id;
  2114. int idx;
  2115. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2116. sbale = &sbal->element[idx];
  2117. req_id = (unsigned long) sbale->addr;
  2118. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2119. if (!fsf_req) {
  2120. /*
  2121. * Unknown request means that we have potentially memory
  2122. * corruption and must stop the machine immediately.
  2123. */
  2124. zfcp_qdio_siosl(adapter);
  2125. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2126. req_id, dev_name(&adapter->ccw_device->dev));
  2127. }
  2128. fsf_req->qdio_req.sbal_response = sbal_idx;
  2129. zfcp_fsf_req_complete(fsf_req);
  2130. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2131. break;
  2132. }
  2133. }
  2134. struct zfcp_fsf_req *zfcp_fsf_get_req(struct zfcp_qdio *qdio,
  2135. struct qdio_buffer *sbal)
  2136. {
  2137. struct qdio_buffer_element *sbale = &sbal->element[0];
  2138. u64 req_id = (unsigned long) sbale->addr;
  2139. return zfcp_reqlist_find(qdio->adapter->req_list, req_id);
  2140. }