zfcp_fsf.c 67 KB

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