zfcp_fsf.c 69 KB

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